Module: Elastic::Beanstalk::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/elastic/beanstalk/config.rb

Overview

If this behavior of merging arrays or the defaults are somehow un-sensible, file an issue and we’ll revisit it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



101
102
103
104
105
# File 'lib/elastic/beanstalk/config.rb', line 101

def method_missing(name, *args, &block)
  @configuration[name.to_sym] ||
      #fail(NoMethodError, "Unknown settings root \'#{name}\'", caller)
      nil
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



38
39
40
# File 'lib/elastic/beanstalk/config.rb', line 38

def configuration
  @configuration
end

Instance Method Details

#clearObject



107
108
109
# File 'lib/elastic/beanstalk/config.rb', line 107

def clear
  init
end

#deep_merge!(target, data) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/elastic/beanstalk/config.rb', line 78

def deep_merge!(target, data)
  merger = proc { |key, v1, v2|
    if (Hash === v1 && Hash === v2)
      v1.merge(v2, &merger)
    elsif (Array === v1 && Array === v2)
      v1.concat(v2)
    else
      v2
    end
  }
  target.merge! data, &merger
end

#find_option_setting(name) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/elastic/beanstalk/config.rb', line 141

def find_option_setting(name)
  name = name.to_sym
  options.each_key do |namespace|
    options[namespace].each do |option_name, value|
      if option_name.eql? name
        return to_option_setting(namespace, option_name, value)
      end
    end
  end
  return nil
end

#find_option_setting_value(name) ⇒ Object



153
154
155
156
# File 'lib/elastic/beanstalk/config.rb', line 153

def find_option_setting_value(name)
  o = find_option_setting(name)
  o[:value] unless o.nil?
end

#initObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/elastic/beanstalk/config.rb', line 19

def init

  # seed the sensible defaults here
  @configuration = {
      environment: nil,
      disallow_environments: %w(cucumber test),
      strategy: :blue_green,
      package: {
          dir: 'pkg',
          verbose: false,
          includes: %w(**/* .ebextensions/**/*),
          exclude_files: [],
          exclude_dirs: %w(pkg tmp log test-reports)
      },
      options: {}
  }
end

#load!(environment = nil, filename = resolve_path('config/eb.yml')) ⇒ Object

This is the main point of entry - we call Settings.load! and provide a name of the file to read as it’s argument. We can also pass in some options, but at the moment it’s being used to allow per-environment overrides in Rails



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/elastic/beanstalk/config.rb', line 44

def load!(environment = nil, filename = resolve_path('config/eb.yml'))

  # merge all top level settings with the defaults set in the #init
  #@configuration.deep_merge!( YAML::load_file(filename).deep_symbolize )
  deep_merge!(@configuration, YAML::load_file(filename).deep_symbolize)

  # add the environment to the top level settings
  @configuration[:environment] = (environment.nil? ? nil : environment.to_s)

  # overlay the specific environment if provided
  if environment && @configuration[environment.to_sym]

    # this is environment specific, so prune any environment
    # based settings from the initial set so that they can be overlaid.
    [:development, :test, :staging, :production].each do |env|
      @configuration.delete(env)
    end

    # re-read the file
    environment_settings = YAML::load_file(filename).deep_symbolize

    # snag the requested environment
    environment_settings = environment_settings[environment.to_sym]

    # finally overlay what was provided
    #@configuration.deep_merge!(environment_settings)
    deep_merge!(@configuration, environment_settings)
  end


  #ap @configuration
  #generate_accessors
end

#option_settingsObject

custom methods for the specifics of eb.yml settings



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/elastic/beanstalk/config.rb', line 117

def option_settings
  result = []
  options.each_key do |namespace|
    options[namespace].each do |option_name, value|
      result << to_option_setting(namespace, option_name, value)
    end
  end

  #{"option_settings" => result}
  result
end

#optionsObject



111
112
113
114
# File 'lib/elastic/beanstalk/config.rb', line 111

def options
  @configuration[:options] = {} if @configuration[:options].nil?
  @configuration[:options]
end

#reload!(options = {}, filename) ⇒ Object



91
92
93
94
95
# File 'lib/elastic/beanstalk/config.rb', line 91

def reload!(options = {}, filename)
  clear
  #filename.nil? ?
  load!(options) # : load!(options, filename)
end

#resolve_path(relative_path) ⇒ Object



166
167
168
169
170
171
172
173
174
175
# File 'lib/elastic/beanstalk/config.rb', line 166

def resolve_path(relative_path)

  if defined?(Rails)
    Rails.root.join(relative_path)
  elsif defined?(Rake.original_dir)
    File.expand_path(relative_path, Rake.original_dir)
  else
    File.expand_path(relative_path, Dir.pwd)
  end
end

#set_option(namespace, option_name, value) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/elastic/beanstalk/config.rb', line 129

def set_option(namespace, option_name, value)
  namespace = namespace.to_sym

  if options[namespace].nil?
    options[namespace] = {option_name.to_sym => value}
  else
    options[namespace][option_name.to_sym] = value
  end

  #puts '888888hello'
end

#to_option_setting(namespace, option_name, value) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/elastic/beanstalk/config.rb', line 158

def to_option_setting(namespace, option_name, value)
  {
      :"namespace" => "#{namespace}",
      :"option_name" => "#{option_name}",
      :"value" => "#{value}"
  }
end

#to_yamlObject



97
98
99
# File 'lib/elastic/beanstalk/config.rb', line 97

def to_yaml

end