Class: EY::Config

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

Defined Under Namespace

Classes: ConfigurationError

Constant Summary collapse

CONFIG_FILES =
["config/ey.yml", "ey.yml"]

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ Config

Returns a new instance of Config.



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

def initialize(file = nil)
  require 'yaml'
  @file = file || CONFIG_FILES.find{|f| File.exists?(f) }
  @config = @file ? YAML.load_file(@file) : {}
  @config.merge!("environments" => {}) unless @config["environments"]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



14
15
16
17
18
19
20
21
# File 'lib/engineyard/config.rb', line 14

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

Instance Method Details

#config_file_endpointObject



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

def config_file_endpoint
  if endpoint = @config["endpoint"]
    assert_valid_endpoint endpoint, @file
  end
end

#default_branch(environment = default_environment) ⇒ Object



61
62
63
64
# File 'lib/engineyard/config.rb', line 61

def default_branch(environment = default_environment)
  env = environments[environment]
  env && env["branch"]
end

#default_endpointObject



46
47
48
# File 'lib/engineyard/config.rb', line 46

def default_endpoint
  URI.parse("https://cloud.engineyard.com/")
end

#default_endpoint?Boolean

Returns:

  • (Boolean)


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

def default_endpoint?
  default_endpoint == endpoint
end

#default_environmentObject



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

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

#endpointObject



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

def endpoint
  @endpoint ||= env_var_endpoint ||
    config_file_endpoint ||
    default_endpoint
end

#env_var_endpointObject



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

def env_var_endpoint
  if endpoint = ENV["CLOUD_URL"]
    assert_valid_endpoint endpoint, "CLOUD_URL"
  end
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/engineyard/config.rb', line 23

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