Class: Catche::Tag::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/catche/tag/resource.rb

Class Method Summary collapse

Class Method Details

.associations(object, associations) ⇒ Object



27
28
29
# File 'lib/catche/tag/resource.rb', line 27

def associations(object, associations)
  associations.map { |association| resource(object, association) }.compact
end

.pluralize(object) ⇒ Object



7
8
9
# File 'lib/catche/tag/resource.rb', line 7

def pluralize(object)
  object.name.to_s.pluralize.downcase
end

.resource(object, name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/catche/tag/resource.rb', line 15

def resource(object, name)
  if resource = object.instance_variable_get("@#{name}")
    return resource
  elsif object.respond_to?(name)
    begin
      return object.send(name)
    rescue; end
  end

  nil
end

.singularize(object) ⇒ Object



11
12
13
# File 'lib/catche/tag/resource.rb', line 11

def singularize(object)
  object.name.to_s.singularize.downcase
end