Class: LinkedRails::ParamsParser
- Inherits:
-
Object
- Object
- LinkedRails::ParamsParser
- Includes:
- Empathy::EmpJson::Helpers::Parsing, Empathy::EmpJson::Helpers::Slices
- Defined in:
- lib/linked_rails/params_parser.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#slice ⇒ Object
Returns the value of attribute slice.
-
#user_context ⇒ Object
Returns the value of attribute user_context.
Instance Method Summary collapse
- #attributes_from_filters(klass) ⇒ Object
-
#initialize(slice: nil, params: {}, user_context: nil) ⇒ ParamsParser
constructor
A new instance of ParamsParser.
- #parse_param(klass, predicate, object) ⇒ Object
-
#parse_resource(subject, klass) ⇒ Object
Recursively parses a resource from slice.
Constructor Details
#initialize(slice: nil, params: {}, user_context: nil) ⇒ ParamsParser
Returns a new instance of ParamsParser.
11 12 13 14 15 |
# File 'lib/linked_rails/params_parser.rb', line 11 def initialize(slice: nil, params: {}, user_context: nil) self.slice = slice self.params = params self.user_context = user_context end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
8 9 10 |
# File 'lib/linked_rails/params_parser.rb', line 8 def params @params end |
#slice ⇒ Object
Returns the value of attribute slice.
8 9 10 |
# File 'lib/linked_rails/params_parser.rb', line 8 def slice @slice end |
#user_context ⇒ Object
Returns the value of attribute user_context.
8 9 10 |
# File 'lib/linked_rails/params_parser.rb', line 8 def user_context @user_context end |
Instance Method Details
#attributes_from_filters(klass) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/linked_rails/params_parser.rb', line 17 def attributes_from_filters(klass) ActionController::Parameters.new( filter_params.each_with_object({}) do |(predicate, value), hash| key_and_value = filter_to_param(klass, predicate, value) hash[key_and_value.first] = key_and_value.second if key_and_value end ) end |
#parse_param(klass, predicate, object) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/linked_rails/params_parser.rb', line 26 def parse_param(klass, predicate, object) = serializer_field(klass, predicate) unless predicate == '_id' if .is_a?(FastJsonapi::Attribute) parse_attribute(klass, , emp_to_primitive(object)) elsif .is_a?(FastJsonapi::Relationship) parse_association(klass, , emp_to_primitive(object)) end end |
#parse_resource(subject, klass) ⇒ Object
Recursively parses a resource from slice
36 37 38 39 40 41 42 43 44 |
# File 'lib/linked_rails/params_parser.rb', line 36 def parse_resource(subject, klass) (record_from_slice(slice, subject) || {}).reduce({}) do |h, (k, v)| (v.is_a?(Array) ? v : [v]).each do |value| param = parse_param(klass, RDF::URI(k), value) param ? add_param(h, param.first, param.second) : h end h end end |