Module: MongoModel::Attributes::Typecasting
- Included in:
- Store
- Defined in:
- lib/mongomodel/attributes/typecasting.rb
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #before_type_cast(key) ⇒ Object
-
#has?(key) ⇒ Boolean
Check if key has a value that typecasts to true.
Instance Method Details
#[]=(key, value) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/mongomodel/attributes/typecasting.rb', line 4 def []=(key, value) values_before_typecast[key] = value result = super(key, typecast(key, value)) result.parent_document = instance if result.respond_to?(:parent_document=) result end |
#before_type_cast(key) ⇒ Object
29 30 31 |
# File 'lib/mongomodel/attributes/typecasting.rb', line 29 def before_type_cast(key) values_before_typecast[key] end |
#has?(key) ⇒ Boolean
Check if key has a value that typecasts to true.
attributes = Attributes::Store.new(:comments_count => Property.new(:comments_count, Integer))
attributes = 0 attributes.has?(:comments_count)
> false
attributes = 1 attributes.has?(:comments_count)
> true
24 25 26 27 |
# File 'lib/mongomodel/attributes/typecasting.rb', line 24 def has?(key) value = self[key] boolean_typecast(key, value) end |