Class: Ooor::MiniActiveResource
- Inherits:
-
Object
- Object
- Ooor::MiniActiveResource
show all
- Includes:
- ActiveModel::Conversion, ActiveModel::Serializers::JSON, ActiveModel::Serializers::Xml
- Defined in:
- lib/ooor/mini_active_resource.rb
Direct Known Subclasses
Base
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *arguments) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/ooor/mini_active_resource.rb', line 71
def method_missing(method_symbol, *arguments) method_name = method_symbol.to_s
if method_name =~ /(=|\?)$/
case $1
when "="
attributes[$`] = arguments.first
when "?"
attributes[$`]
end
else
return attributes[method_name] if attributes.include?(method_name)
return nil if known_attributes.include?(method_name)
super
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
28
29
30
|
# File 'lib/ooor/mini_active_resource.rb', line 28
def attributes
@attributes
end
|
#id ⇒ Object
Returns the value of attribute id.
28
29
30
|
# File 'lib/ooor/mini_active_resource.rb', line 28
def id
@id
end
|
Class Method Details
.element_name ⇒ Object
9
10
11
|
# File 'lib/ooor/mini_active_resource.rb', line 9
def element_name
@element_name ||= model_name.element
end
|
Instance Method Details
#errors ⇒ Object
Returns the Errors object that holds all information about attribute error messages.
61
62
63
|
# File 'lib/ooor/mini_active_resource.rb', line 61
def errors
@errors ||= ActiveModel::Errors.new(self)
end
|
#new? ⇒ Boolean
Also known as:
new_record?
38
39
40
|
# File 'lib/ooor/mini_active_resource.rb', line 38
def new?
!@persisted
end
|
#persisted? ⇒ Boolean
43
44
45
|
# File 'lib/ooor/mini_active_resource.rb', line 43
def persisted?
@persisted
end
|
#reload ⇒ Object
56
57
58
|
# File 'lib/ooor/mini_active_resource.rb', line 56
def reload
self.class.find(id)
end
|
#to_json(options = {}) ⇒ Object
30
31
32
|
# File 'lib/ooor/mini_active_resource.rb', line 30
def to_json(options={})
super(include_root_in_json ? { :root => self.class.element_name }.merge(options) : options)
end
|
#to_xml(options = {}) ⇒ Object
34
35
36
|
# File 'lib/ooor/mini_active_resource.rb', line 34
def to_xml(options={})
super({ :root => self.class.element_name }.merge(options))
end
|