Class: S3Config::Application
- Inherits:
-
Object
- Object
- S3Config::Application
- Includes:
- Enumerable
- Defined in:
- lib/s3_config/application.rb
Direct Known Subclasses
Instance Method Summary collapse
- #configuration ⇒ Object
- #delete(key) ⇒ Object
- #each(&block) ⇒ Object
- #environment ⇒ Object
- #environment=(environment) ⇒ Object
- #environments ⇒ Object
-
#initialize(options = {}) ⇒ Application
constructor
A new instance of Application.
- #latest_version ⇒ Object
- #load ⇒ Object
- #read(key) ⇒ Object
- #valid? ⇒ Boolean
- #version ⇒ Object
- #version=(version) ⇒ Object
- #versions_count ⇒ Object
- #write(key, value) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Application
Returns a new instance of Application.
10 11 12 |
# File 'lib/s3_config/application.rb', line 10 def initialize( = {}) = .inject({}) { |m, (k, v)| m[k.to_sym] = v; m } end |
Instance Method Details
#configuration ⇒ Object
36 37 38 |
# File 'lib/s3_config/application.rb', line 36 def configuration @configuration ||= read_configuration end |
#delete(key) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/s3_config/application.rb', line 83 def delete(key) config = read_configuration unless config[key].nil? config.delete key write_configuration config end end |
#each(&block) ⇒ Object
46 47 48 |
# File 'lib/s3_config/application.rb', line 46 def each(&block) configuration.each(&block) end |
#environment ⇒ Object
18 19 20 21 |
# File 'lib/s3_config/application.rb', line 18 def environment environment = .fetch(:environment) { default_environment } environment.nil? ? nil : environment.to_s end |
#environment=(environment) ⇒ Object
23 24 25 |
# File 'lib/s3_config/application.rb', line 23 def environment=(environment) [:environment] = environment end |
#environments ⇒ Object
14 15 16 |
# File 'lib/s3_config/application.rb', line 14 def environments bucket.objects.map(&:key).map{|key| key.split('/').first }.uniq end |
#latest_version ⇒ Object
62 63 64 |
# File 'lib/s3_config/application.rb', line 62 def latest_version [versions_count - 1, 0].max end |
#load ⇒ Object
40 41 42 43 44 |
# File 'lib/s3_config/application.rb', line 40 def load each do |key, value| skip?(key) ? key_skipped!(key) : graduate_to_env(key, value) end end |
#read(key) ⇒ Object
66 67 68 69 |
# File 'lib/s3_config/application.rb', line 66 def read(key) config = read_configuration config[key] end |
#valid? ⇒ Boolean
50 51 52 |
# File 'lib/s3_config/application.rb', line 50 def valid? !client.nil? and !bucket.nil? end |
#version ⇒ Object
27 28 29 30 |
# File 'lib/s3_config/application.rb', line 27 def version version = .fetch(:version) { default_version } version end |
#version=(version) ⇒ Object
32 33 34 |
# File 'lib/s3_config/application.rb', line 32 def version=(version) [:version] = version end |
#versions_count ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/s3_config/application.rb', line 54 def versions_count begin bucket.objects({prefix: "#{environment}/"}).count rescue S3Config::ConfigNotDefinedError => e rescue ConfigNotDefinedError end end |
#write(key, value) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/s3_config/application.rb', line 71 def write(key, value) begin config = read_configuration rescue ConfigNotDefinedError config = {} end unless config[key] == value config[key] = value write_configuration config end end |