Module: Mutils::Serialization::Methods::Relations
- Defined in:
- lib/mutils/serialization/methods/relations.rb
Overview
Module Relations
Instance Method Summary collapse
- #prepare_options(relationship_name, options, option_name) ⇒ Object
- #relationship(relationship_name, options = {}) ⇒ Object (also: #belongs_to, #has_many, #has_one)
Instance Method Details
#prepare_options(relationship_name, options, option_name) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mutils/serialization/methods/relations.rb', line 23 def (relationship_name, , option_name) class_name = [:serializer] if class_name.nil? raise "Serializer is Required for belongs_to :#{relationship_name}." \ "\nDefine it like:\n#{option_name} :#{relationship_name}, " \ 'serializer: SERIALIZER_CLASS' end raise "Serializer class not defined for relationship: #{relationship_name}" unless class_exists? class_name [:serializer] = class_name.to_s [:always_include] = [:always_include].nil? ? false : [:always_include] [:label] = Lib::Helper.instance.underscore [:label] || relationship_name end |
#relationship(relationship_name, options = {}) ⇒ Object Also known as: belongs_to, has_many, has_one
11 12 13 14 15 16 17 |
# File 'lib/mutils/serialization/methods/relations.rb', line 11 def relationship(relationship_name, = {}) raise "if: should be a Proc object for attribute #{relationship_name}" if [:if] && ![:if].instance_of?(Proc) = (relationship_name, , __callee__) self.relationships = {} if relationships.nil? relationships[relationship_name] = end |