lib/bikepoa/helpers.rb in bikepoa-tools-0.2.0 vs lib/bikepoa/helpers.rb in bikepoa-tools-0.3.0
- old
+ new
@@ -1,18 +1,21 @@
module BikePOA
module Helpers
module ForceField
+ FORCED_FIELDS = {}
def self.included(base)
base.send :extend, ClassMethods
end
+ def []=(property, value)
+ transform = FORCED_FIELDS[property.to_sym]
+ value = transform.call(value) if transform
+ super(property, value)
+ end
+
module ClassMethods
def force_integer(field)
- class_eval do
- define_method("#{field}=".to_sym) do |value|
- self.[]=(field, Integer(value))
- end
- end
+ FORCED_FIELDS[field.to_sym] = lambda { |value| Integer(value) }
end
end
end
end
end