Class: Rebi::Config
Instance Attribute Summary collapse
- #aws_key ⇒ Object
- #aws_profile ⇒ Object
- #aws_secret ⇒ Object
-
#data ⇒ Object
Returns the value of attribute data.
- #region ⇒ Object
Instance Method Summary collapse
- #app_description ⇒ Object
- #app_name ⇒ Object
- #app_name=(name) ⇒ Object
- #aws_session_token ⇒ Object
- #config_file ⇒ Object
- #config_file=(path) ⇒ Object
- #env_by_name(name) ⇒ Object
- #environment(stg_name, env_name) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #push_to_file ⇒ Object
- #reload! ⇒ Object
- #stage(stage) ⇒ Object
- #stages ⇒ Object
- #timeout ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
6 7 8 |
# File 'lib/rebi/config.rb', line 6 def initialize reload! end |
Instance Attribute Details
#aws_key ⇒ Object
23 24 25 |
# File 'lib/rebi/config.rb', line 23 def aws_key data[:aws_key] || ENV["AWS_ACCESS_KEY_ID"] end |
#aws_profile ⇒ Object
19 20 21 |
# File 'lib/rebi/config.rb', line 19 def aws_profile @aws_profile || data[:profile] || ENV["AWS_PROFILE"] end |
#aws_secret ⇒ Object
27 28 29 |
# File 'lib/rebi/config.rb', line 27 def aws_secret data[:aws_secret] || ENV["AWS_SECRET_ACCESS_KEY"] end |
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/rebi/config.rb', line 5 def data @data end |
#region ⇒ Object
35 36 37 |
# File 'lib/rebi/config.rb', line 35 def region data[:region] end |
Instance Method Details
#app_description ⇒ Object
53 54 55 |
# File 'lib/rebi/config.rb', line 53 def app_description data[:app_description] || "Created via rebi" end |
#app_name ⇒ Object
45 46 47 |
# File 'lib/rebi/config.rb', line 45 def app_name data[:app_name] end |
#app_name=(name) ⇒ Object
49 50 51 |
# File 'lib/rebi/config.rb', line 49 def app_name=name data[:app_name] = name end |
#aws_session_token ⇒ Object
31 32 33 |
# File 'lib/rebi/config.rb', line 31 def aws_session_token ENV["AWS_SESSION_TOKEN"] end |
#config_file ⇒ Object
10 11 12 |
# File 'lib/rebi/config.rb', line 10 def config_file @config_file ||= "#{Rebi.root}/.rebi.yml" end |
#config_file=(path) ⇒ Object
14 15 16 |
# File 'lib/rebi/config.rb', line 14 def config_file=path @config_file = Pathname.new(path).realpath.to_s end |
#env_by_name(name) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rebi/config.rb', line 71 def env_by_name name data[:stages].each do |stg_name, stg_conf| stg = stage stg_name stg_conf.keys.each do |env_name| env_conf = Rebi::ConfigEnvironment.new(stg_name, env_name, stg[env_name] || {}) return env_conf if env_conf.name == name end end return nil end |
#environment(stg_name, env_name) ⇒ Object
65 66 67 68 69 |
# File 'lib/rebi/config.rb', line 65 def environment stg_name, env_name stg = stage stg_name raise(Rebi::Error::ConfigNotFound.new("Environment config: #{env_name}")) unless stg.key?(env_name) return Rebi::ConfigEnvironment.new(stg_name, env_name, stg[env_name] || {}) end |
#push_to_file ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/rebi/config.rb', line 96 def push_to_file File.open(config_file, "wb") do |f| f.write JSON.parse(data.to_json).to_yaml end Rebi.log "Saved config to #{config_file}" Rebi.log "For more configs, please refer sample or github" end |
#reload! ⇒ Object
39 40 41 42 43 |
# File 'lib/rebi/config.rb', line 39 def reload! @data = nil set_aws_config return data end |
#stage(stage) ⇒ Object
57 58 59 |
# File 'lib/rebi/config.rb', line 57 def stage stage data[:stages] && data[:stages][stage] || raise(Rebi::Error::ConfigNotFound.new("Stage: #{stage}")) end |
#stages ⇒ Object
82 83 84 |
# File 'lib/rebi/config.rb', line 82 def stages data[:stages].keys end |
#timeout ⇒ Object
61 62 63 |
# File 'lib/rebi/config.rb', line 61 def timeout (data[:timeout] || 60*10).second end |