Class: Media::File
- Inherits:
-
Object
- Object
- Media::File
- Defined in:
- lib/aerogel/media/field_types.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#uid ⇒ Object
Returns the value of attribute uid.
Class Method Summary collapse
-
.demongoize(object) ⇒ Object
Get the object as it was stored in the database, and instantiate this custom class from it.
-
.evolve(object) ⇒ Object
Converts the object that was supplied to a criteria and converts it into a database friendly form.
-
.mongoize(object) ⇒ Object
Takes any possible object and converts it to how it would be stored in the database.
Instance Method Summary collapse
-
#initialize(mongoid_value) ⇒ File
constructor
A new instance of File.
-
#mongoize ⇒ Object
Converts an object of this instance into a database friendly value.
Constructor Details
#initialize(mongoid_value) ⇒ File
Returns a new instance of File.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/aerogel/media/field_types.rb', line 10 def initialize( mongoid_value ) case mongoid_value when nil @uid, @name = nil, nil when Array @uid, @name = mongoid_value[0], mongoid_value[1] when Hash @uid, @name = mongoid_value[:uid], mongoid_value[:name] when Media::File @uid, @name = mongoid_value.uid, mongoid_value.name else raise ArgumentError.new "Failed to create Media::File value from #{mongoid_value.class}" end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/aerogel/media/field_types.rb', line 8 def name @name end |
#uid ⇒ Object
Returns the value of attribute uid.
8 9 10 |
# File 'lib/aerogel/media/field_types.rb', line 8 def uid @uid end |
Class Method Details
.demongoize(object) ⇒ Object
Get the object as it was stored in the database, and instantiate this custom class from it.
33 34 35 |
# File 'lib/aerogel/media/field_types.rb', line 33 def demongoize( object ) object.nil? ? nil : Media::File.new( object ) end |
Instance Method Details
#mongoize ⇒ Object
Converts an object of this instance into a database friendly value.
26 27 28 |
# File 'lib/aerogel/media/field_types.rb', line 26 def mongoize (uid.nil? && name.nil?) ? nil : [ uid, name ] end |