module Cockpit class Scope attr_reader :key, :settings def initialize(settings, method, *args, &block) @settings = settings _process(method, *args, &block) end def value settings[key] end def value=(x) settings[key] = x end 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 = new_key else @key = node end if boolean == true settings.has_key?(key) elsif set == true self.value = args.pop else self end end def method_missing(method, *args, &block) _process(method, *args, &block) end end end