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.



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

def initialize(file = nil)
  require 'yaml'
  @file = file || CONFIG_FILES.find{|f| File.exists?(f) }
  @config = (@file ? YAML.load_file(@file) : {}) || {} # load_file returns `false' when the file is empty
  @config["environments"] = {} unless @config["environments"]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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

Instance Method Details

#default_branch(environment = default_environment) ⇒ Object



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

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

#default_endpointObject



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

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

#default_endpoint?Boolean

Returns:

  • (Boolean)


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

def default_endpoint?
  default_endpoint == endpoint
end

#default_environmentObject



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

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

#endpointObject



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

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

#env_var_endpointObject



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

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

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


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

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