Module: JSONAPI::Ruby::Deserializer::Parser
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/jsonapi-ruby-deserializer/parser.rb', line 22
def method_missing(method, *args, &block)
if args.empty?
super
else
field = method[0...-1]
instance_variable_set("@#{field}", *args)
self.class.send(:attr_accessor, field.to_sym)
end
end
|
Instance Method Details
#parse!(data) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/jsonapi-ruby-deserializer/parser.rb', line 7
def parse!(data)
data.each do |field, value|
instance_variable_set("@#{field}", value)
self.class.send(:attr_accessor, field.to_sym)
end
end
|
#to_h ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/jsonapi-ruby-deserializer/parser.rb', line 14
def to_h
{}.tap do |h|
self.instance_variables.each do |variable|
h.merge!(variable.to_s[1..-1] => instance_variable_get(variable))
end
end
end
|