Module: SmoothOperator::FinderMethods::HelperMethods
- Extended by:
- HelperMethods
- Included in:
- HelperMethods
- Defined in:
- lib/smooth_operator/finder_methods.rb
Instance Method Summary collapse
- #build_object(object, parsed_response, options, from_array = false) ⇒ Object
- #parse_array(parsed_response, object, options) ⇒ Object
- #parse_hash(object, parsed_response, options, from_array) ⇒ Object
Instance Method Details
#build_object(object, parsed_response, options, from_array = false) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/smooth_operator/finder_methods.rb', line 23 def build_object(object, parsed_response, , from_array = false) if parsed_response.is_a?(Array) parse_array(parsed_response, object, ) elsif parsed_response.is_a?(Hash) parse_hash(object, parsed_response, , from_array) else parsed_response end end |
#parse_array(parsed_response, object, options) ⇒ Object
33 34 35 36 37 |
# File 'lib/smooth_operator/finder_methods.rb', line 33 def parse_array(parsed_response, object, ) parsed_response.map do |array_entry| build_object(object, array_entry, , true) end end |
#parse_hash(object, parsed_response, options, from_array) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/smooth_operator/finder_methods.rb', line 39 def parse_hash(object, parsed_response, , from_array) object_class ||= object.class == Class ? object : object.class if parsed_response.include?(object_class.resources_name) && !from_array ArrayWithMetaData.new(parsed_response.dup, object_class) else object_class.new(parsed_response, data_from_server: true) end end |