• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Code-Vedas / mutils / 9707403017

28 Jun 2024 04:22AM CUT coverage: 100.0%. Remained the same
9707403017

push

github

niteshpurohit
fix: rubocop >= 1.63.3

205 of 205 relevant lines covered (100.0%)

28368.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/mutils/serialization/methods/relations.rb
1
# frozen_string_literal: true
2

3
# Module Mutils
4
module Mutils
2✔
5
  # Module SerializationCore
6
  module Serialization
2✔
7
    # Module Methods
8
    module Methods
2✔
9
      # Module Relations
10
      module Relations
2✔
11
        def relationship(relationship_name, options = {})
2✔
12
          raise "if: should be a Proc object for attribute #{relationship_name}" if options[:if] && !options[:if].instance_of?(Proc)
14✔
13

14
          options = prepare_options(relationship_name, options, __callee__)
14✔
15
          self.relationships = {} if relationships.nil?
10✔
16
          relationships[relationship_name] = options
10✔
17
        end
18

19
        alias belongs_to relationship
2✔
20
        alias has_many relationship
2✔
21
        alias has_one relationship
2✔
22

23
        def prepare_options(relationship_name, options, option_name)
2✔
24
          class_name = options[:serializer]
14✔
25
          if class_name.nil?
14✔
26
            raise "Serializer is Required for belongs_to :#{relationship_name}." \
2✔
27
                  "\nDefine it like:\n#{option_name} :#{relationship_name}, " \
28
                  'serializer: SERIALIZER_CLASS'
29
          end
30
          raise "Serializer class not defined for relationship: #{relationship_name}" unless class_exists? class_name
12✔
31

32
          options[:serializer] = class_name.to_s
10✔
33
          options[:always_include] = options[:always_include].nil? ? false : options[:always_include]
10✔
34
          options[:label] = Lib::Helper.instance.underscore options[:label] || relationship_name
10✔
35
          options
10✔
36
        end
37
      end
38
    end
39
  end
40
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc