Module: AppConfig
- Defined in:
- lib/app_config.rb,
lib/app_config/error.rb,
lib/app_config/storage.rb,
lib/app_config/version.rb,
lib/app_config/storage/base.rb,
lib/app_config/storage/yaml.rb,
lib/app_config/storage/mongo.rb,
lib/app_config/storage/mysql.rb,
lib/app_config/storage/sqlite.rb,
lib/app_config/storage/postgres.rb,
lib/app_config/storage/config_data.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'2.7.1'
Class Method Summary collapse
-
.method_missing(name, *args) ⇒ Object
Wrap ‘method_missing` to proxy to `storage`.
-
.reload! ⇒ Object
Reload the data from storage.
-
.reset! ⇒ Object
Clears the ‘@@storage`.
-
.setup!(options = {}) {|@@storage| ... } ⇒ Object
Accepts an ‘options` hash or a block.
-
.setup? ⇒ Boolean
Returns ‘true` if AppConfig.setup! has been called.
- .to_hash ⇒ Object
Class Method Details
.method_missing(name, *args) ⇒ Object
Wrap ‘method_missing` to proxy to `storage`.
65 66 67 |
# File 'lib/app_config.rb', line 65 def method_missing(name, *args) storage.send(name.to_sym, *args) end |
.reload! ⇒ Object
Reload the data from storage.
47 48 49 50 51 52 53 |
# File 'lib/app_config.rb', line 47 def reload! if storage.respond_to?(:reload!) storage.reload! else raise AppConfig::Error::MustOverride.new("#{storage.class}#reload!") end end |
.reset! ⇒ Object
Clears the ‘@@storage`.
56 57 58 |
# File 'lib/app_config.rb', line 56 def reset! @@storage = nil end |
.setup!(options = {}) {|@@storage| ... } ⇒ Object
Accepts an ‘options` hash or a block. See each storage method’s documentation for their specific options.
Valid storage methods:
-
‘:mongo` - AppConfig::Storage::Mongo
-
‘:postgres` - AppConfig::Storage::Postgres
-
‘:sqlite` - AppConfig::Storage::SQLite
-
‘:yaml` - AppConfig::Storage::YAML
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/app_config.rb', line 19 def setup!( = {}, &block) @@options = if @@options[:yaml] @@storage = AppConfig::Storage::YAML.new(@@options.delete(:yaml), @@options) elsif @@options[:mongo] @@storage = AppConfig::Storage::Mongo.new(@@options.delete(:mongo)) elsif @@options[:mysql] @@storage = AppConfig::Storage::MySQL.new(@@options.delete(:mysql)) elsif @@options[:postgres] @@storage = AppConfig::Storage::Postgres.new(@@options.delete(:postgres)) elsif @@options[:sqlite] @@storage = AppConfig::Storage::SQLite.new(@@options.delete(:sqlite)) else @@storage = AppConfig::Storage::Base.new(@@options) end yield @@storage if block_given? to_hash end |
.setup? ⇒ Boolean
Returns ‘true` if AppConfig.setup! has been called.
42 43 44 |
# File 'lib/app_config.rb', line 42 def setup? defined?(@@storage) && !@@storage.nil? end |
.to_hash ⇒ Object
60 61 62 |
# File 'lib/app_config.rb', line 60 def to_hash storage ? storage.to_hash : {} end |