lib/mongoid/fields.rb in mongoid-2.0.0 vs lib/mongoid/fields.rb in mongoid-2.0.1

- old
+ new

@@ -33,11 +33,10 @@ # @option options [ String ] :label The label for the field. # @option options [ Object, Proc ] :default The field's default def field(name, options = {}) access = name.to_s set_field(access, options) - attr_protected name if options[:accessible] == false end # Return the fields for this class. # # @example Get the fields. @@ -118,10 +117,14 @@ # @param [ Symbol ] name The name of the field. # @param [ Symbol ] meth The name of the accessor. # @param [ Hash ] options The options. def create_accessors(name, meth, options = {}) generated_field_methods.module_eval do - define_method(meth) { read_attribute(name) } + if [ Time, DateTime ].include?(options[:type]) + define_method(meth) { Time.get(read_attribute(name)) } + else + define_method(meth) { read_attribute(name) } + end define_method("#{meth}=") { |value| write_attribute(name, value) } define_method("#{meth}?") do attr = read_attribute(name) (options[:type] == Boolean) ? attr == true : attr.present? end