Class: MongoMapper::Key
Instance Attribute Summary collapse
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #embeddable? ⇒ Boolean
- #get(value) ⇒ Object
-
#initialize(*args) ⇒ Key
constructor
A new instance of Key.
- #set(value) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Key
Returns a new instance of Key.
5 6 7 8 9 10 |
# File 'lib/mongomapper/key.rb', line 5 def initialize(*args) = args. @name, @type = args.shift.to_s, args.shift self. = ( || {}).symbolize_keys self.default_value = self..delete(:default) end |
Instance Attribute Details
#default_value ⇒ Object
Returns the value of attribute default_value.
3 4 5 |
# File 'lib/mongomapper/key.rb', line 3 def default_value @default_value end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/mongomapper/key.rb', line 3 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/mongomapper/key.rb', line 3 def @options end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/mongomapper/key.rb', line 3 def type @type end |
Instance Method Details
#==(other) ⇒ Object
12 13 14 |
# File 'lib/mongomapper/key.rb', line 12 def ==(other) @name == other.name && @type == other.type end |
#embeddable? ⇒ Boolean
20 21 22 |
# File 'lib/mongomapper/key.rb', line 20 def type.respond_to?(:embeddable?) && type. ? true : false end |
#get(value) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/mongomapper/key.rb', line 24 def get(value) if value.nil? && !default_value.nil? return default_value end type.from_mongo(value) end |
#set(value) ⇒ Object
16 17 18 |
# File 'lib/mongomapper/key.rb', line 16 def set(value) type.to_mongo(value) end |