Class: EY::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/engineyard/config.rb

Defined Under Namespace

Classes: ConfigurationError, EnvironmentConfig

Constant Summary collapse

CONFIG_FILES =
["config/ey.yml", "ey.yml"].map {|path| Pathname.new(path)}.freeze
EY_YML_HINTS =
"# ey.yml supports many deploy configuration options when committed in an\n# application's repository.\n#\n# Valid locations: REPO_ROOT/ey.yml or REPO_ROOT/config/ey.yml.\n#\n# Examples options:\n#\n# environments:\n#   YOUR_ENVIRONMENT_NAME: # All options pertain only to the named environment\n#     migrate: true                           # Default --migrate choice for ey deploy\n#     migration_command: 'rake migrate'       # Default migrate command to run when migrations are enabled\n#     branch: default_deploy_branch           # Branch/ref to be deployed by default during ey deploy\n#     bundle_without: development test        # The string to pass to bundle install --without ''\n#     maintenance_on_migrate: true            # Enable maintenance page during migrate action (use with caution) (default: true)\n#     maintenance_on_restart: false           # Enable maintanence page during every deploy (default: false for unicorn & passenger)\n#     ignore_database_adapter_warning: false  # Hide the warning shown when the Gemfile does not contain a recognized database adapter (mongodb for example)\n#     your_own_custom_key: 'any attribute you put in ey.yml is available in deploy hooks'\n#\n# Further information available here:\n# https://support.cloud.engineyard.com/entries/20996661-customize-your-deployment-on-engine-yard-cloud\n#\n# NOTE: Please commit this file into your git repository.\n#\n"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
# File 'lib/engineyard/config.rb', line 12

def initialize(file = nil)
  @path = file || CONFIG_FILES.find{|pathname| pathname.exist? }
  @config = (@path ? YAML.load_file(@path.to_s) : {}) || {} # load_file returns `false' when the file is empty
  @config["environments"] ||= {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/engineyard/config.rb', line 18

def method_missing(meth, *args, &blk)
  key = meth.to_s.downcase
  if @config.key?(key)
    @config[key]
  else
    super
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/engineyard/config.rb', line 10

def path
  @path
end

Instance Method Details

#default_endpointObject



40
41
42
# File 'lib/engineyard/config.rb', line 40

def default_endpoint
  "https://cloud.engineyard.com/"
end

#default_endpoint?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/engineyard/config.rb', line 44

def default_endpoint?
  default_endpoint == endpoint
end

#default_environmentObject



48
49
50
51
52
53
# File 'lib/engineyard/config.rb', line 48

def default_environment
  d = environments.find do |name, env|
    env["default"]
  end
  d && d.first
end

#endpointObject



32
33
34
# File 'lib/engineyard/config.rb', line 32

def endpoint
  env_var_endpoint || default_endpoint
end

#ensure_pathObject



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/engineyard/config.rb', line 105

def ensure_path
  return if @path && @path.exist?
  unless EY::Repo.exist?
    raise "Not in application directory. Unable to save configuration."
  end
  if Pathname.new('config').exist?
    @path = Pathname.new('config/ey.yml')
  else
    @path = Pathname.new('ey.yml')
  end
  @path
end

#env_var_endpointObject



36
37
38
# File 'lib/engineyard/config.rb', line 36

def env_var_endpoint
  ENV["CLOUD_URL"]
end

#environment_config(environment_name) ⇒ Object



55
56
57
58
# File 'lib/engineyard/config.rb', line 55

def environment_config(environment_name)
  environments[environment_name] ||= {}
  EnvironmentConfig.new(environments[environment_name], environment_name, self)
end

#ey_yml_commentsObject



97
98
99
100
101
102
103
# File 'lib/engineyard/config.rb', line 97

def ey_yml_comments
  if @path.exist?
    existing = @path.readlines.grep(/^#/).map {|line| line.strip }.join("\n")
  else
    EY_YML_HINTS
  end
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/engineyard/config.rb', line 27

def respond_to?(meth)
  key = meth.to_s.downcase
  @config.key?(key) || super
end

#set_environment_option(environment_name, key, value) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/engineyard/config.rb', line 60

def set_environment_option(environment_name, key, value)
  environments[environment_name] ||= {}
  environments[environment_name][key] = value
  ensure_path
  comments = ey_yml_comments
  @path.open('w') do |f|
    f.puts comments
    f.puts YAML.dump(@config)
  end
end