Class: Resourcerer::ResourceConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/resourcerer/resource_configuration.rb

Direct Known Subclasses

Configuration::StrongParameters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ResourceConfiguration

Returns a new instance of ResourceConfiguration.



7
8
9
# File 'lib/resourcerer/resource_configuration.rb', line 7

def initialize(options={})
  @options = options || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



11
12
13
14
15
# File 'lib/resourcerer/resource_configuration.rb', line 11

def method_missing(name, *args)
  super if args.size > 1
  define_option_method(name)
  send(name, args.first)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/resourcerer/resource_configuration.rb', line 5

def options
  @options
end

Instance Method Details

#assign(&block) ⇒ Object



37
38
39
# File 'lib/resourcerer/resource_configuration.rb', line 37

def assign(&block)
  options[:attributes] = block
end

#build(&block) ⇒ Object



33
34
35
# File 'lib/resourcerer/resource_configuration.rb', line 33

def build(&block)
  options[:builder] = block
end

#define_option_method(name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/resourcerer/resource_configuration.rb', line 17

def define_option_method(name)
  # We chose not caching the value inside the method because it's more flexible
  self.class.class_eval <<-EVAL
    def #{name}(value=nil)
      options[:#{name}] = value if value
      options[:#{name}]
    end
  EVAL
end

#find(&block) ⇒ Object

DSL



29
30
31
# File 'lib/resourcerer/resource_configuration.rb', line 29

def find(&block)
  options[:finder] = block
end