Class: ImageType

Inherits:
Object
  • Object
show all
Defined in:
lib/classiccms/models/base.rb

Overview

model.validates_presence_of field if value

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image_id) ⇒ ImageType

Returns a new instance of ImageType.



11
12
13
# File 'lib/classiccms/models/base.rb', line 11

def initialize(image_id)
  @image_id
end

Instance Attribute Details

#image_idObject (readonly)

Returns the value of attribute image_id.



9
10
11
# File 'lib/classiccms/models/base.rb', line 9

def image_id
  @image_id
end

Class Method Details

.demongoize(object_id) ⇒ Object

Get the object as it was stored in the database, and instantiate this custom class from it.



19
20
21
22
23
24
25
26
# File 'lib/classiccms/models/base.rb', line 19

def demongoize(object_id)
  image = Image.where(:id => object_id).first
  if image != nil
    image.file
  else
    Dragonfly[:file].fetch_file(File.join(Dir.pwd, 'public/not_found.jpeg'))
  end
end

.evolve(object) ⇒ Object

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



36
37
38
39
40
41
# File 'lib/classiccms/models/base.rb', line 36

def evolve(object)
  case object
  when ImageType then object.mongoize
  else object
  end
end

.mongoize(object_id) ⇒ Object

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



30
31
32
# File 'lib/classiccms/models/base.rb', line 30

def mongoize(object_id)
  object_id
end