Module: Mutils::Serialization::Results::Main
- Included in:
- SerializationResults
- Defined in:
- lib/mutils/serialization/results/main.rb
Overview
Module Attributes
Instance Method Summary collapse
- #check_if_included(s_options, key) ⇒ Object
- #class_name ⇒ Object
- #format_class_name(object) ⇒ Object
- #generate_hash ⇒ Object
- #hashed_result(result_hash) ⇒ Object
- #scope_is_collection? ⇒ Boolean
Instance Method Details
#check_if_included(s_options, key) ⇒ Object
31 32 33 34 35 |
# File 'lib/mutils/serialization/results/main.rb', line 31 def check_if_included(, key) return [:if].call(scope, [:params] || {}) unless [:if].nil? || scope_is_collection? [:always_include] || [:includes]&.include?(key) end |
#class_name ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/mutils/serialization/results/main.rb', line 41 def class_name if scope_is_collection? Lib::Helper.instance.pluralize(format_class_name(scope[0])) else format_class_name(scope) end end |
#format_class_name(object) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/mutils/serialization/results/main.rb', line 49 def format_class_name(object) if self.class.serializer_name&.length&.positive? self.class.serializer_name else object.class.to_s.downcase end end |
#generate_hash ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mutils/serialization/results/main.rb', line 10 def generate_hash if scope if scope_is_collection? [:child] = true scope.map { |inner_scope| self.class.new(inner_scope, ).generate_hash } else hashed_result(Lib::ResultHash.new) end else {} end end |
#hashed_result(result_hash) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/mutils/serialization/results/main.rb', line 23 def hashed_result(result_hash) fetch_block_attributes(self.class.attributes_to_serialize_blocks, result_hash) fetch_attributes(self.class.attributes_to_serialize, result_hash) hash_relationships(self.class.relationships, result_hash) result_hash.hash end |