Module: BikePOA::Helpers::ForceField

Included in:
Station
Defined in:
lib/bikepoa/helpers.rb

Defined Under Namespace

Modules: Enforcers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/bikepoa/helpers.rb', line 4

def self.included(base)
  enforcers = {}
  enforcer_installers = Module.new do
    Enforcers.methods.grep(/^force_/).each do |meth_name|
      define_method(meth_name) do |field|
        enforcers[field] = lambda { |value| Enforcers.send(meth_name, value) }
      end
    end
  end
  base.send(:extend, enforcer_installers)
  base.send(:define_method, :enforcers) { enforcers }
end

Instance Method Details

#[]=(property, value) ⇒ Object



17
18
19
20
21
# File 'lib/bikepoa/helpers.rb', line 17

def []=(property, value)
  enforcer = enforcers[property.to_sym]
  value = enforcer.call(value) if enforcer
  super(property, value)
end