Class: Garlic::Configurator::BlockParser

Inherits:
Object
  • Object
show all
Defined in:
lib/garlic/configurator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, whitelist = [], &block) ⇒ BlockParser

Returns a new instance of BlockParser.



44
45
46
47
48
# File 'lib/garlic/configurator.rb', line 44

def initialize(options, whitelist = [], &block)
  @options = options
  @whitelist = whitelist
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/garlic/configurator.rb', line 50

def method_missing(method, *args, &block)
  if block_given? && args.empty? && (whitelist.empty? || whitelist.include?(method))
    options[method.to_sym] = block
  else
    raise ArgumentError, "Don't know how to parse #{method} #{args.inspect unless args.empty?}"
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



42
43
44
# File 'lib/garlic/configurator.rb', line 42

def options
  @options
end

#whitelistObject (readonly)

Returns the value of attribute whitelist.



42
43
44
# File 'lib/garlic/configurator.rb', line 42

def whitelist
  @whitelist
end