Class: Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
10
11
12
13
14
# File 'lib/config.rb', line 5

def initialize(hash)
  @contexts = hash[:contexts] || hash['contexts'] || {}
  @contexts = @contexts.map {|ctx| Context.new(ctx) }

  @environments = hash[:environments] || hash['environments'] || {}
  @environments = @environments.map { |env| Environment.new(env) }

  @requests = hash[:requests] || hash['requests'] || {}
  @requests = @requests.map { |req| Request.new(req) }
end

Instance Attribute Details

#contextsObject

Returns the value of attribute contexts.



3
4
5
# File 'lib/config.rb', line 3

def contexts
  @contexts
end

#environmentsObject

Returns the value of attribute environments.



3
4
5
# File 'lib/config.rb', line 3

def environments
  @environments
end

#requestsObject

Returns the value of attribute requests.



3
4
5
# File 'lib/config.rb', line 3

def requests
  @requests
end

Class Method Details

.create_from_yaml(yaml_string) ⇒ Object



16
17
18
# File 'lib/config.rb', line 16

def self.create_from_yaml(yaml_string)
  return Config.new YAML.load(yaml_string)
end

Instance Method Details

#get_context(ctx_name) ⇒ Object



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

def get_context(ctx_name)
  @contexts.find {|ctx| ctx.name == ctx_name }
end

#get_environment(env_name) ⇒ Object



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

def get_environment(env_name)
  @environments.find {|env| env.name == env_name }
end

#get_request(env_name) ⇒ Object



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

def get_request(env_name)
  @requests.find {|env| env.name == env_name }
end

#has_context?(ctx_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/config.rb', line 20

def has_context?(ctx_name)
  @contexts.any? {|ctx| ctx.name == ctx_name }
end

#has_environment?(env_name) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_environment?(env_name)
  @environments.any? {|env| env.name == env_name }
end

#has_request?(env_name) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_request?(env_name)
  @requests.any? {|env| env.name == env_name }
end