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

Code-Vedas / mutils / 4249393637

pending completion
4249393637

push

github

GitHub
build(deps): bump rubocop from 1.45.1 to 1.46.0 (#239)

205 of 205 relevant lines covered (100.0%)

14184.08 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
1✔
5
  # Module SerializationCore
6
  module Serialization
1✔
7
    # Module Methods
8
    module Methods
1✔
9
      # Module Relations
10
      module Relations
1✔
11
        def relationship(relationship_name, options = {})
1✔
12
          raise "if: should be a Proc object for attribute #{relationship_name}" if options[:if] && !options[:if].instance_of?(Proc)
7✔
13

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

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

23
        def prepare_options(relationship_name, options, option_name)
1✔
24
          class_name = options[:serializer]
7✔
25
          if class_name.nil?
7✔
26
            raise "Serializer is Required for belongs_to :#{relationship_name}." \
1✔
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
6✔
31

32
          options[:serializer] = class_name.to_s
5✔
33
          options[:always_include] = options[:always_include].nil? ? false : options[:always_include]
5✔
34
          options[:label] = Lib::Helper.instance.underscore options[:label] || relationship_name
5✔
35
          options
5✔
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