Class: Media::File

Inherits:
Object
  • Object
show all
Defined in:
lib/aerogel/media/field_types.rb

Direct Known Subclasses

Image

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/aerogel/media/field_types.rb', line 8

def name
  @name
end

#uidObject

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

.evolve(object) ⇒ Object

Converts the object that was supplied to a criteria and converts it into a database friendly form.



45
46
47
48
49
50
51
# File 'lib/aerogel/media/field_types.rb', line 45

def evolve( object )
  case object
  when Media::File then object.mongoize
  else
    object
  end
end

.mongoize(object) ⇒ Object

Takes any possible object and converts it to how it would be stored in the database.



39
40
41
# File 'lib/aerogel/media/field_types.rb', line 39

def mongoize( object )
  Media::File.new(object).mongoize
end

Instance Method Details

#mongoizeObject

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