Module: MuckContents::Models::MuckContent::ClassMethods

Defined in:
lib/muck-contents/models/content.rb

Instance Method Summary collapse

Instance Method Details

#contentable_to_scope(obj) ⇒ Object

Builds a path based on a contentable object. This is the value used to generate scope for the content object.



89
90
91
# File 'lib/muck-contents/models/content.rb', line 89

def contentable_to_scope(obj)
  File.join('/', obj.class.to_s.tableize, obj.to_param)
end

#find_contentable(contentable_type, contentable_id) ⇒ Object

look up a contentable object given the contentable class name and id



83
84
85
# File 'lib/muck-contents/models/content.rb', line 83

def find_contentable(contentable_type, contentable_id)
  contentable_type.constantize.find(contentable_id)
end

#find_contents_for_contentable(contentable_type, contentable_id) ⇒ Object

Look up all contents for contentable



75
76
77
78
79
80
# File 'lib/muck-contents/models/content.rb', line 75

def find_contents_for_contentable(contentable_type, contentable_id)
  find(:all,
    :conditions => ["contentable_type = ? and contentable_id = ?", contentable_type, contentable_id],
    :order => "created_at DESC"
  )
end

#id_from_uri(uri) ⇒ Object



93
94
95
96
# File 'lib/muck-contents/models/content.rb', line 93

def id_from_uri(uri)
  return '' if uri.blank?
  File.basename(uri)
end

#scope_from_uri(uri) ⇒ Object



98
99
100
101
# File 'lib/muck-contents/models/content.rb', line 98

def scope_from_uri(uri)
  return '' if uri.blank?
  File.dirname(uri)
end