Class: EY::Config
- Inherits:
-
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 =
<<-HINTS
# ey.yml supports many deploy configuration options when committed in an
# application's repository.
#
# Valid locations: REPO_ROOT/ey.yml or REPO_ROOT/config/ey.yml.
#
# Examples options:
#
# environments:
# YOUR_ENVIRONMENT_NAME: # All options pertain only to the named environment
# migrate: true # Default --migrate choice for ey deploy
# migration_command: 'rake migrate' # Default migrate command to run when migrations are enabled
# branch: default_deploy_branch # Branch/ref to be deployed by default during ey deploy
# bundle_without: development test # The string to pass to bundle install --without ''
# maintenance_on_migrate: true # Enable maintenance page during migrate action (use with caution) (default: true)
# maintenance_on_restart: false # Enable maintanence page during every deploy (default: false for unicorn & passenger)
# ignore_database_adapter_warning: false # Hide the warning shown when the Gemfile does not contain a recognized database adapter (mongodb for example)
# your_own_custom_key: 'any attribute you put in ey.yml is available in deploy hooks'
#
# Further information available here:
# https://support.cloud.engineyard.com/entries/20996661-customize-your-deployment-on-engine-yard-cloud
#
# NOTE: Please commit this file into your git repository.
#
HINTS
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) : {}) || {} @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
#path ⇒ Object
Returns the value of attribute path.
10
11
12
|
# File 'lib/engineyard/config.rb', line 10
def path
@path
end
|
Instance Method Details
#default_endpoint ⇒ Object
40
41
42
|
# File 'lib/engineyard/config.rb', line 40
def default_endpoint
"https://cloud.engineyard.com/"
end
|
#default_endpoint? ⇒ Boolean
44
45
46
|
# File 'lib/engineyard/config.rb', line 44
def default_endpoint?
default_endpoint == endpoint
end
|
#default_environment ⇒ Object
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
|
#endpoint ⇒ Object
32
33
34
|
# File 'lib/engineyard/config.rb', line 32
def endpoint
env_var_endpoint || default_endpoint
end
|
#ensure_path ⇒ Object
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_endpoint ⇒ Object
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
|
97
98
99
100
101
102
103
|
# File 'lib/engineyard/config.rb', line 97
def
if @path.exist?
existing = @path.readlines.grep(/^#/).map {|line| line.strip }.join("\n")
else
EY_YML_HINTS
end
end
|
#respond_to?(meth) ⇒ 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
=
@path.open('w') do |f|
f.puts
f.puts YAML.dump(@config)
end
end
|