Class: MongoMapper::Plugins::Keys::Key
- Defined in:
- lib/novelys_mongo_mapper/plugins/keys.rb
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.
- #number? ⇒ Boolean
- #set(value) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Key
Returns a new instance of Key.
267 268 269 270 271 272 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 267 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.
265 266 267 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 265 def default_value @default_value end |
#name ⇒ Object
Returns the value of attribute name.
265 266 267 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 265 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
265 266 267 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 265 def @options end |
#type ⇒ Object
Returns the value of attribute type.
265 266 267 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 265 def type @type end |
Instance Method Details
#==(other) ⇒ Object
274 275 276 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 274 def ==(other) @name == other.name && @type == other.type end |
#embeddable? ⇒ Boolean
278 279 280 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 278 def type.respond_to?(:embeddable?) && type. ? true : false end |
#get(value) ⇒ Object
286 287 288 289 290 291 292 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 286 def get(value) if value.nil? && !default_value.nil? return default_value end type.from_mongo(value) end |
#number? ⇒ Boolean
282 283 284 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 282 def number? [Integer, Float].include?(type) end |
#set(value) ⇒ Object
294 295 296 |
# File 'lib/novelys_mongo_mapper/plugins/keys.rb', line 294 def set(value) type.to_mongo(value) end |