Class: CrazyDoll::Config::Instance
- Inherits:
-
Object
- Object
- CrazyDoll::Config::Instance
- Defined in:
- lib/crazy_doll/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Instance Method Summary collapse
-
#initialize(owner, config = {}) ⇒ Instance
constructor
A new instance of Instance.
- #register(owner, key, description, value) ⇒ Object
Constructor Details
#initialize(owner, config = {}) ⇒ Instance
Returns a new instance of Instance.
73 74 75 76 77 |
# File 'lib/crazy_doll/config.rb', line 73 def initialize(owner, config={}) @config = config.empty? ? {} : config @owner = owner @config.keys.each { |k| create_key(k) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/crazy_doll/config.rb', line 102 def method_missing(name, *args, &block) if name.to_s.match(/=$/) and args.size == 1 key = name.to_s.gsub(/=$/,'').to_sym puts "!!! key #{key} missing, but creating !!!" @config[key] = CrazyDoll::Config.parse(@owner, key, 'created by method_missing', args[0]) create_key(key) @config[key] elsif name.to_s.match(/\?$/) and self.respond_to?((k=name.to_s.gsub(/\?$/,''))) puts "!!! method #{name} missing, creating it !!!" self.instance_eval " def \#{name}\n @config[:\#{k}]\n end\n EVAL\n send(name)\n else\n puts \"!!! method \#{name} missing !!!\"\n nil\n end\nend\n" |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
72 73 74 |
# File 'lib/crazy_doll/config.rb', line 72 def config @config end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
72 73 74 |
# File 'lib/crazy_doll/config.rb', line 72 def owner @owner end |
Instance Method Details
#register(owner, key, description, value) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/crazy_doll/config.rb', line 79 def register(owner, key, description, value) k = key.to_sym return false if @config[k] @config[k] = CrazyDoll::Config.parse(@owner, key, description, value) create_key(k) end |