Class: Models::Item

Inherits:
Object
  • Object
show all
Defined in:
app/models/_item/container.rb,
app/models/_item/attachments.rb,
app/models/_item/slug.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dependentObject

Returns the value of attribute dependent.



2
3
4
# File 'app/models/_item/container.rb', line 2

def dependent
  @dependent
end

#slugObject



3
4
5
# File 'app/models/_item/slug.rb', line 3

def slug
  @slug ||= generate_slug
end

Class Method Details

.by_param(param) ⇒ Object



20
21
22
# File 'app/models/_item/slug.rb', line 20

def self.by_param param
  self.by_slug(param) || (BSON::ObjectId.legal?(param) && self.by_id(param))
end

.by_param!(param) ⇒ Object



16
17
18
# File 'app/models/_item/slug.rb', line 16

def self.by_param! param
  by_param(param) || raise(Mongo::NotFound, "object with slug #{param} not found!")
end

Instance Method Details

#attachmentsObject



2
3
4
# File 'app/models/_item/attachments.rb', line 2

def attachments
  @attachments ||= []
end

#attachments_as_imagesObject



9
10
11
12
13
14
# File 'app/models/_item/attachments.rb', line 9

def attachments_as_images
  # TODO3 remove sorting, use order defined in database
  _cache[:attachments_as_images] ||= attachments.
    sort{|a, b| a.file.name <=> b.file.name}.
    collect{|o| {name: o.file.name, url: o.file.url, thumb_url: o.file.thumb.url, icon_url: o.file.icon.url}.to_openobject}
end

#dependent!Object



6
# File 'app/models/_item/container.rb', line 6

def dependent!; self.dependent = true end

#dependent?Boolean

Returns:

  • (Boolean)


3
# File 'app/models/_item/container.rb', line 3

def dependent?; !!dependent end

#independent!Object



5
# File 'app/models/_item/container.rb', line 5

def independent!; remove_instance_variable :@dependent end

#independent?Boolean

Returns:

  • (Boolean)


4
# File 'app/models/_item/container.rb', line 4

def independent?; !dependent? end