Class: Reviewed::Base
- Inherits:
-
Object
show all
- Extended by:
- ActiveModel::Naming
- Includes:
- Embeddable
- Defined in:
- lib/reviewed/base.rb
Direct Known Subclasses
Article, Attachment, Author, Award, Brand, Deal, Hero, ManufacturerSpec, Page, Product, Website
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Embeddable
embedded_class, embedded_name, included, #objectify, #objectify_has_many, #objectify_has_one
Constructor Details
#initialize(data) ⇒ Base
Returns a new instance of Base.
12
13
14
|
# File 'lib/reviewed/base.rb', line 12
def initialize(data)
self.attributes = objectify(data)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/reviewed/base.rb', line 66
def method_missing(sym, *args, &block)
if @attributes.has_key?(sym)
@attributes[sym]
else
super
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
10
11
12
|
# File 'lib/reviewed/base.rb', line 10
def attributes
@attributes
end
|
Class Method Details
.association_name(klass = nil) ⇒ Object
47
48
49
50
|
# File 'lib/reviewed/base.rb', line 47
def association_name klass=nil
klass ||= self
klass.name.demodulize.downcase.pluralize
end
|
.to_path(parent_scope = nil) ⇒ Object
poor man’s polymorphic_url
39
40
41
42
43
44
45
|
# File 'lib/reviewed/base.rb', line 39
def to_path parent_scope=nil
if parent_scope && parent_scope.respond_to?(:to_param)
[association_name(parent_scope.class), parent_scope.to_param, association_name].join('/')
else
association_name
end
end
|
Instance Method Details
#created_at ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/reviewed/base.rb', line 16
def created_at
if @attributes.has_key?(:created_at)
Time.parse(@attributes[:created_at])
else
nil
end
end
|
#respond_to?(sym, include_private = false) ⇒ Boolean
62
63
64
|
# File 'lib/reviewed/base.rb', line 62
def respond_to?(sym, include_private=false)
super || @attributes.has_key?(sym)
end
|
#to_param ⇒ Object
58
59
60
|
# File 'lib/reviewed/base.rb', line 58
def to_param
id
end
|
#to_path ⇒ Object
54
55
56
|
# File 'lib/reviewed/base.rb', line 54
def to_path
[self.class.to_path, self.to_param].join('/')
end
|
#to_s ⇒ Object
32
33
34
|
# File 'lib/reviewed/base.rb', line 32
def to_s
"\#<#{self.class.name}:#{self.id}>"
end
|
#updated_at ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/reviewed/base.rb', line 24
def updated_at
if @attributes.has_key?(:updated_at)
Time.parse(@attributes[:updated_at])
else
nil
end
end
|