Sha256: a50d7760735d1b3b68b88ce83bababb7441cba85e32894b483789cb4e0e6ce1d

Contents?: true

Size: 875 Bytes

Versions: 34

Compression:

Stored size: 875 Bytes

Contents

module Mongoid #:nodoc:
  class Field

    attr_reader \
      :default,
      :name,
      :type

    # Create the new field with a name and optional additional options. Valid
    # options are :default
    #
    # Options:
    #
    # name: The name of the field as a +Symbol+.
    # options: A +Hash+ of options for the field.
    #
    # Example:
    #
    # <tt>Field.new(:score, :default => 0)</tt>
    def initialize(name, options = {})
      @name = name
      @default = options[:default]
      @type = options[:type] || String
    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)
      object.nil? ? default : type.set(object)
    end

    # Used for retrieving the object out of the attributes hash.
    def get(object)
      type.get(object)
    end

  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
mongoid-0.9.4 lib/mongoid/field.rb
mongoid-0.9.3 lib/mongoid/field.rb
mongoid-0.9.2 lib/mongoid/field.rb
mongoid-0.9.1 lib/mongoid/field.rb
mongoid-0.9.0 lib/mongoid/field.rb
mongoid-0.8.10 lib/mongoid/field.rb
mongoid-0.8.9 lib/mongoid/field.rb
mongoid-0.8.8 lib/mongoid/field.rb
mongoid-0.8.7 lib/mongoid/field.rb
mongoid-0.8.6 lib/mongoid/field.rb
mongoid-0.8.5 lib/mongoid/field.rb
mongoid-0.8.4 lib/mongoid/field.rb
mongoid-0.8.3 lib/mongoid/field.rb
mongoid-0.8.2 lib/mongoid/field.rb
mongoid-0.8.1 lib/mongoid/field.rb
mongoid-0.7.10 lib/mongoid/field.rb
mongoid-0.7.9 lib/mongoid/field.rb
mongoid-0.7.8 lib/mongoid/field.rb
mongoid-0.7.7 lib/mongoid/field.rb
mongoid-0.7.6 lib/mongoid/field.rb