lib/cockpit/core/scope.rb in cockpit-0.2.0 vs lib/cockpit/core/scope.rb in cockpit-0.2.1

- old
+ new

@@ -2,32 +2,61 @@ class Scope attr_reader :key, :settings def initialize(settings, method, *args, &block) @settings = settings - process(method, *args, &block) + _process(method, *args, &block) end def value settings[key] end def value=(x) settings[key] = x end - def process(method, *args, &block) - node = method.to_s - + def to_i + value.to_i + end + + def to_s + value.to_s + end + + def to_f + value.to_f + end + + def nil? + value.nil? + end + + def empty? + value.empty? + end + + def blank? + value.blank? + end + + def _process(method, *args, &block) + method = method.to_s + node = method.dup + boolean = !!(node =~ /\?$/) node.gsub!(/\?/, "") if boolean set = !!(node =~ /=$/) node.gsub!("=", "") if set + new_key = "#{key}.#{node}" + + return value.send(method) if key && !settings.has_key?(new_key) && value.respond_to?(method) + if key - @key = "#{key}.#{node}" + @key = new_key else @key = node end if boolean == true @@ -38,9 +67,9 @@ self end end def method_missing(method, *args, &block) - process(method, *args, &block) + _process(method, *args, &block) end end end