Class: Reviewed::Base
- Inherits:
-
Object
show all
- Extended by:
- ActiveModel::Naming
- Includes:
- Embeddable
- Defined in:
- lib/reviewed/base.rb
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.
11
12
13
|
# File 'lib/reviewed/base.rb', line 11
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
65
66
67
68
69
70
71
|
# File 'lib/reviewed/base.rb', line 65
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.
9
10
11
|
# File 'lib/reviewed/base.rb', line 9
def attributes
@attributes
end
|
Class Method Details
.association_name(klass = nil) ⇒ Object
46
47
48
49
|
# File 'lib/reviewed/base.rb', line 46
def association_name klass=nil
klass ||= self
klass.name.demodulize.downcase.pluralize
end
|
.to_path(parent_scope = nil) ⇒ Object
poor man’s polymorphic_url
38
39
40
41
42
43
44
|
# File 'lib/reviewed/base.rb', line 38
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
15
16
17
18
19
20
21
|
# File 'lib/reviewed/base.rb', line 15
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
61
62
63
|
# File 'lib/reviewed/base.rb', line 61
def respond_to?(sym, include_private=false)
super || @attributes.has_key?(sym)
end
|
#to_param ⇒ Object
57
58
59
|
# File 'lib/reviewed/base.rb', line 57
def to_param
id
end
|
#to_path ⇒ Object
53
54
55
|
# File 'lib/reviewed/base.rb', line 53
def to_path
[self.class.to_path, self.to_param].join('/')
end
|
#to_s ⇒ Object
31
32
33
|
# File 'lib/reviewed/base.rb', line 31
def to_s
"\#<#{self.class.name}:#{self.id}>"
end
|
#updated_at ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/reviewed/base.rb', line 23
def updated_at
if @attributes.has_key?(:updated_at)
Time.parse(@attributes[:updated_at])
else
nil
end
end
|