lib/mongoid/field.rb in mongoid-pre-2.0.0.beta1 vs lib/mongoid/field.rb in mongoid-pre-2.0.0.pre
- old
+ new
@@ -1,28 +1,14 @@
# encoding: utf-8
module Mongoid #:nodoc:
class Field
- attr_reader :name, :type
- # Determine if the field is able to be accessible via a mass update.
- #
- # Returns:
- #
- # true if accessible, false if not.
- def accessible?
- !!@accessible
- end
+ attr_reader \
+ :default,
+ :name,
+ :type
- # Get the default value for the field.
- #
- # Returns:
- #
- # The primitive value or a copy of the default.
- def default
- (@default.is_a?(Array) || @default.is_a?(Hash)) ? @default.dup : @default
- end
-
# Create the new field with a name and optional additional options. Valid
# options are :default
#
# Options:
#
@@ -31,13 +17,13 @@
#
# Example:
#
# <tt>Field.new(:score, :default => 0)</tt>
def initialize(name, options = {})
- @name, @default = name, options[:default]
+ @name = name
+ @default = options[:default]
@type = options[:type] || String
- @accessible = options.has_key?(:accessible) ? options[:accessible] : true
end
# Used for setting an object in the attributes hash. If nil is provided the
# default will get returned if it exists.
def set(object)
@@ -46,7 +32,8 @@
# Used for retrieving the object out of the attributes hash.
def get(object)
type.get(object)
end
+
end
end