Class: Panda::Base
Constant Summary
Constants included
from Router
Router::VAR_PATTERN
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Finders
included
Methods included from Builders
#create, #create!, included
Methods included from Router
included, #replace_pattern_with_self_variables
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
14
15
16
17
|
# File 'lib/panda/base.rb', line 14
def initialize(attributes = {})
clear_attributes
load(attributes)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *arguments) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/panda/base.rb', line 87
def method_missing(method_symbol, *arguments)
method_name = method_symbol.to_s
if method_name =~ /(=|\?)$/
case $1
when '='
attributes[$`] = arguments.first
@changed_attributes[$`] = arguments.first
when '?'
!! attributes[$`]
end
else
return attributes[method_name] if attributes.include?(method_name)
super
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5
6
7
|
# File 'lib/panda/base.rb', line 5
def attributes
@attributes
end
|
#errors ⇒ Object
Returns the value of attribute errors.
5
6
7
|
# File 'lib/panda/base.rb', line 5
def errors
@errors
end
|
Class Method Details
.sti_name ⇒ Object
20
21
22
|
# File 'lib/panda/base.rb', line 20
def sti_name
"#{name.split('::').last}"
end
|
Instance Method Details
#changed? ⇒ Boolean
25
26
27
|
# File 'lib/panda/base.rb', line 25
def changed?
!@changed_attributes.empty?
end
|
#id ⇒ Object
33
34
35
|
# File 'lib/panda/base.rb', line 33
def id
attributes['id']
end
|
#id=(id) ⇒ Object
37
38
39
|
# File 'lib/panda/base.rb', line 37
def id=(id)
attributes['id'] = id
end
|
#new? ⇒ Boolean
29
30
31
|
# File 'lib/panda/base.rb', line 29
def new?
id.nil?
end
|
#reload ⇒ Object
41
42
43
44
|
# File 'lib/panda/base.rb', line 41
def reload
perform_reload
self
end
|