Module: Shutl::Resource::Rest
- Includes:
- ActiveModel::Serialization
- Defined in:
- lib/shutl/resource/rest.rb
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, *args, &block) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/shutl/resource/rest.rb', line 53
def method_missing(method, *args, &block)
if self.instance_variables.include?(:"@#{method}")
return self.instance_variable_get(:"@#{method}")
end
super
end
|
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
12
13
14
|
# File 'lib/shutl/resource/rest.rb', line 12
def errors
@errors
end
|
Returns the value of attribute pagination.
12
13
14
|
# File 'lib/shutl/resource/rest.rb', line 12
def
@pagination
end
|
Class Method Details
.included(base) ⇒ Object
14
15
16
17
18
19
|
# File 'lib/shutl/resource/rest.rb', line 14
def self.included(base)
base.send :extend, Shutl::Resource::RestClassMethods
base.send :resource_name, base.name.split('::').last.underscore
base.send :resource_id, :id
end
|
Instance Method Details
#as_json(_) ⇒ Object
25
26
27
|
# File 'lib/shutl/resource/rest.rb', line 25
def as_json(_)
attributes
end
|
#attributes ⇒ Object
81
82
83
84
85
|
# File 'lib/shutl/resource/rest.rb', line 81
def attributes
(instance_variables).inject({}.with_indifferent_access) do |h, var|
h.merge( { var.to_s.gsub('@','').to_sym => instance_variable_get(var)})
end
end
|
#destroy(options) ⇒ Object
49
50
51
|
# File 'lib/shutl/resource/rest.rb', line 49
def destroy options
self.class.destroy self, options
end
|
#initialize(args = {}) ⇒ Object
21
22
23
|
# File 'lib/shutl/resource/rest.rb', line 21
def initialize(args = {})
update_attributes args
end
|
#next_resource ⇒ Object
65
66
67
|
# File 'lib/shutl/resource/rest.rb', line 65
def next_resource
["next_resource"] if
end
|
#previous_resource ⇒ Object
69
70
71
|
# File 'lib/shutl/resource/rest.rb', line 69
def previous_resource
["previous_resource"] if
end
|
#resource_id ⇒ Object
77
78
79
|
# File 'lib/shutl/resource/rest.rb', line 77
def resource_id
instance_variable_get :"@#{self.class.resource_id_name}"
end
|
#respond_to?(method) ⇒ Boolean
60
61
62
|
# File 'lib/shutl/resource/rest.rb', line 60
def respond_to? method
self.instance_variables.include?(:"@#{method}") ? true : super
end
|
#save(options = {}) ⇒ Object
45
46
47
|
# File 'lib/shutl/resource/rest.rb', line 45
def save options={}
self.class.save self, options
end
|
#to_json(options = nil) ⇒ Object
29
30
31
32
33
|
# File 'lib/shutl/resource/rest.rb', line 29
def to_json(options = nil)
{
:"#{prefix}" => attributes
}.to_json(options)
end
|
#update!(attrs) ⇒ Object
39
40
41
42
43
|
# File 'lib/shutl/resource/rest.rb', line 39
def update!(attrs)
new_attributes = attributes.merge attrs
update_attributes(self.class.add_resource_id_to new_attributes)
save
end
|
#update_attributes(attrs) ⇒ Object
35
36
37
|
# File 'lib/shutl/resource/rest.rb', line 35
def update_attributes(attrs)
attrs.each { |a, v| instance_variable_set(:"@#{a}", v) }
end
|
#valid? ⇒ Boolean
73
74
75
|
# File 'lib/shutl/resource/rest.rb', line 73
def valid?
errors.blank?
end
|