Class: Warp::Dir::Config
- Extended by:
- Forwardable
- Defined in:
- lib/warp/dir/config.rb
Constant Summary collapse
- DEFAULTS =
{ warprc: "#{::Dir.home}/.warprc", shell: false, force: false, debug: false, no_color: false }
Instance Attribute Summary collapse
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
-
#[](key) ⇒ Object
allow syntax @config.
- #configure(opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ Config
constructor
A new instance of Config.
-
#method_missing(method, *args, &block) ⇒ Object
Dispatches redis operations to master/slaves.
Constructor Details
#initialize(opts = {}) ⇒ Config
Returns a new instance of Config.
19 20 21 |
# File 'lib/warp/dir/config.rb', line 19 def initialize(opts = {}) configure(opts) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Dispatches redis operations to master/slaves.
62 63 64 65 66 67 68 |
# File 'lib/warp/dir/config.rb', line 62 def method_missing(method, *args, &block) if method =~ /=$/ add_config_variable(method.to_s.gsub(/=$/, ''), *args) else super end end |
Instance Attribute Details
#variables ⇒ Object
Returns the value of attribute variables.
15 16 17 |
# File 'lib/warp/dir/config.rb', line 15 def variables @variables end |
Instance Method Details
#[](key) ⇒ Object
allow syntax @config
57 58 59 |
# File 'lib/warp/dir/config.rb', line 57 def [](key) self.send(key) end |
#configure(opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/warp/dir/config.rb', line 23 def configure(opts = {}) = DEFAULTS.merge(opts) # Move :config hash key->value to :warprc that is expected by the Config if [:config] [:warprc] = [:config] .delete(:config) end self.variables = [] # OK. I concede. This is very likely a total overkill :O # The thing is: I just really like calling hash members via # methods, and I didn't want to load HashieMash because # it's big. Real big. # # IRB Session that explains it all: # # c = Config.new({ foo: "bar", bar: "foo"}) # => #<Warp::Dir::Config:0x007ff8e39531f0 @variables=[:config, :foo, :bar], @config="/Users/kigster/.warprc", @foo="bar", @bar="foo"> # > c.foo # => "bar" # > c.bar # => "foo" # > c.bar? # => true # > c.config # => "/Users/kigster/.warprc" # > c.color = "red" # => "red" # > c.color # => "red" # > c.color? # => true .each_pair do |variable_name, value| self.variables << add_config_variable(variable_name, value) end end |