lib/relaxo/model/properties/attribute.rb in relaxo-model-0.5.1 vs lib/relaxo/model/properties/attribute.rb in relaxo-model-0.9.0

- old
+ new

@@ -29,27 +29,27 @@ def self.for_class(klass, &block) @@attributes[klass] = Proc.new(&block) end - def self.[] (klass, proc = nil) + def self.[](klass, proc = nil) self.new(klass, &proc) end def initialize(klass, &serialization) @klass = klass if block_given? - self.instance_eval &serialization + self.instance_eval(&serialization) else - self.instance_eval &@@attributes[klass] + self.instance_eval(&@@attributes[klass]) end end end class Serialized - def self.[] (klass, proc = nil) + def self.[](klass, proc = nil) self.new(klass, &proc) end def initialize(klass, &serialization) @klass = klass @@ -57,11 +57,11 @@ def convert_to_primative(value) @klass.dump(value) end - def convert_from_primative(database, value) + def convert_from_primative(dataset, value) @klass.load(value) end end Required = Attribute @@ -81,15 +81,15 @@ else @klass.convert_to_primative(value) end end - def convert_from_primative(database, value) + def convert_from_primative(dataset, value) if value.nil? or value.empty? nil else - @klass.convert_from_primative(database, value) + @klass.convert_from_primative(dataset, value) end end end class Boolean @@ -98,60 +98,60 @@ Attribute.for_class(Boolean) do def convert_to_primative(value) value ? true : false end - def convert_from_primative(database, value) + def convert_from_primative(dataset, value) [true, "on", "true"].include?(value) end end Attribute.for_class(Integer) do def convert_to_primative(value) value.to_i end - def convert_from_primative(database, value) + def convert_from_primative(dataset, value) value.to_i end end Attribute.for_class(Float) do def convert_to_primative(value) value.to_f end - def convert_from_primative(database, value) + def convert_from_primative(dataset, value) value.to_f end end Attribute.for_class(Date) do def convert_to_primative(value) value.iso8601 end - def convert_from_primative(database, value) + def convert_from_primative(dataset, value) Date.parse(value) end end Attribute.for_class(DateTime) do def convert_to_primative(value) value.iso8601 end - def convert_from_primative(database, value) + def convert_from_primative(dataset, value) DateTime.parse(value) end end Attribute.for_class(String) do def convert_to_primative(value) value.to_s end - def convert_from_primative(database, value) + def convert_from_primative(dataset, value) value.to_s end end end end