Sha256: 4bb7d242d6dd369c71f855dd31a920d1d2cc876b2ccefef6cb0b4a6e91208857

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

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 process(method, *args, &block)
      node = method.to_s

      boolean = !!(node =~ /\?$/)
      node.gsub!(/\?/, "") if boolean
      
      set     = !!(node =~ /=$/)
      node.gsub!("=", "") if set
      
      if key
        @key       = "#{key}.#{node}"
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cockpit-0.2.0 lib/cockpit/core/scope.rb