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, Event, Gallery, Hero, ManufacturerSpec, Notification, Page, Product, Website
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Embeddable
embedded_name, included, #objectify, #objectify_has_many, #objectify_has_one
Constructor Details
#initialize(data, client = Reviewed::Client.new) ⇒ Base
Returns a new instance of Base.
12
13
14
15
|
# File 'lib/reviewed/base.rb', line 12
def initialize(data, client = Reviewed::Client.new)
@attributes = objectify(data)
@client = client
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/reviewed/base.rb', line 67
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
|
#client ⇒ Object
Returns the value of attribute client.
10
11
12
|
# File 'lib/reviewed/base.rb', line 10
def client
@client
end
|
Class Method Details
.association_name(klass = nil) ⇒ Object
48
49
50
51
|
# File 'lib/reviewed/base.rb', line 48
def association_name klass=nil
klass ||= self
klass.name.demodulize.underscore.pluralize
end
|
.to_path(parent_scope = nil) ⇒ Object
poor man’s polymorphic_url
40
41
42
43
44
45
46
|
# File 'lib/reviewed/base.rb', line 40
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
17
18
19
20
21
22
23
|
# File 'lib/reviewed/base.rb', line 17
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
63
64
65
|
# File 'lib/reviewed/base.rb', line 63
def respond_to?(sym, include_private=false)
super || @attributes.has_key?(sym)
end
|
#to_param ⇒ Object
59
60
61
|
# File 'lib/reviewed/base.rb', line 59
def to_param
id
end
|
#to_path ⇒ Object
55
56
57
|
# File 'lib/reviewed/base.rb', line 55
def to_path
[self.class.to_path, self.to_param].join('/')
end
|
#to_s ⇒ Object
33
34
35
|
# File 'lib/reviewed/base.rb', line 33
def to_s
"\#<#{self.class.name}:#{self.id}>"
end
|
#updated_at ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/reviewed/base.rb', line 25
def updated_at
if @attributes.has_key?(:updated_at)
Time.parse(@attributes[:updated_at])
else
nil
end
end
|