lib/mixlib/config.rb in mixlib-config-1.1.0 vs lib/mixlib/config.rb in mixlib-config-1.1.2.rc01

- old
+ new

@@ -16,16 +16,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # -class Object # http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html - def meta_def name, &blk - (class << self; self; end).instance_eval { define_method name, &blk } - end -end - module Mixlib module Config def self.extended(base) class << base; attr_accessor :configuration; end @@ -123,11 +117,11 @@ # method_symbol<Symbol>:: Name of the method (variable setter) # value<Object>:: Value to be set in config hash # def internal_set(method_symbol,value) method_name = method_symbol.id2name - if (self.public_methods - ["[]="]).include?("#{method_name}=") + if self.respond_to?("#{method_name}=".to_sym) self.send("#{method_name}=", value) else self.configuration[method_symbol] = value end end @@ -140,11 +134,12 @@ # method_symbol<Symbol>:: Name of the method (variable setter) # blk<Block>:: logic block to run in setting slot method_symbol to value # value<Object>:: Value to be set in config hash # def config_attr_writer(method_symbol, &blk) - method_name = "#{method_symbol.to_s}=" - meta_def method_name do |value| + meta = class << self; self; end + method_name = "#{method_symbol.to_s}=".to_sym + meta.send :define_method, method_name do |value| self.configuration[method_symbol] = blk.call(value) end end # Allows for simple lookups and setting of configuration options via method calls