Sha256: 9c1a4f57cd90a46f1bbc77e99a30ffc7ddc4b8b6871a1ac21843dd868bc241e1
Contents?: true
Size: 745 Bytes
Versions: 3
Compression:
Stored size: 745 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 # Gets the value for the supplied object. If the object is nil, then the # default value will be returned. def value(object) object ? type.cast(object) : default end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mongoid-0.5.5 | lib/mongoid/field.rb |
mongoid-0.5.4 | lib/mongoid/field.rb |
mongoid-0.5.3 | lib/mongoid/field.rb |