Class: Ccp::Utils::Options::Proxy

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ccp/utils/options.rb

Direct Known Subclasses

FixtureOptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, *keys) ⇒ Proxy

Returns a new instance of Proxy.



19
20
21
22
23
24
25
26
27
# File 'lib/ccp/utils/options.rb', line 19

def initialize(base, *keys)
  @base = base
  @keys = keys.map(&:to_sym)

  @keys.each do |key|
    @base.dsl_accessor key
#            instance_eval "def self.#{key}; :#{key}; end"
  end
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



17
18
19
# File 'lib/ccp/utils/options.rb', line 17

def keys
  @keys
end

Instance Method Details

#[](key) ⇒ Object



29
30
31
# File 'lib/ccp/utils/options.rb', line 29

def [](key)
  @base.__send__(key)
end

#each(&block) ⇒ Object



33
34
35
36
37
# File 'lib/ccp/utils/options.rb', line 33

def each(&block)
  keys.each do |key|
    yield(self[key])
  end
end

#optionsObject



39
40
41
42
43
44
45
46
# File 'lib/ccp/utils/options.rb', line 39

def options
  opts = {}
  keys.each do |key|
    val = self[key]
    opts[key] = val unless val.nil?
  end
  return opts
end