Class: Panda::Base
- Inherits:
-
Object
show all
- Includes:
- Router
- Defined in:
- lib/panda/base.rb
Constant Summary
Constants included
from Router
Router::DEFAULT_FORMAT, Router::VAR_PATTERN
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Router
included, #object_url_map
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
6
7
8
9
|
# File 'lib/panda/base.rb', line 6
def initialize(attributes = {})
init_load
load(attributes)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *arguments) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/panda/base.rb', line 85
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.
3
4
5
|
# File 'lib/panda/base.rb', line 3
def attributes
@attributes
end
|
#errors ⇒ Object
Returns the value of attribute errors.
3
4
5
|
# File 'lib/panda/base.rb', line 3
def errors
@errors
end
|
Class Method Details
.end_class_name ⇒ Object
16
17
18
|
# File 'lib/panda/base.rb', line 16
def end_class_name
"#{name.split('::').last}"
end
|
.id(this_id) ⇒ Object
12
13
14
|
# File 'lib/panda/base.rb', line 12
def id(this_id)
find(this_id)
end
|
Instance Method Details
#changed? ⇒ Boolean
21
22
23
|
# File 'lib/panda/base.rb', line 21
def changed?
!@changed_attributes.empty?
end
|
#delete ⇒ Object
29
30
31
32
|
# File 'lib/panda/base.rb', line 29
def delete
response = connection.delete(object_url_map(self.class.one_path))
!!response['deleted']
end
|
#id ⇒ Object
34
35
36
|
# File 'lib/panda/base.rb', line 34
def id
attributes['id']
end
|
#id=(id) ⇒ Object
38
39
40
|
# File 'lib/panda/base.rb', line 38
def id=(id)
attributes['id'] = id
end
|
#new? ⇒ Boolean
25
26
27
|
# File 'lib/panda/base.rb', line 25
def new?
id.nil?
end
|
#reload ⇒ Object
42
43
44
45
|
# File 'lib/panda/base.rb', line 42
def reload
perform_reload
self
end
|
#to_json ⇒ Object
47
48
49
|
# File 'lib/panda/base.rb', line 47
def to_json
attributes.to_json
end
|