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

Code-Vedas / mutils / 6060940963

02 Sep 2023 10:54PM CUT coverage: 100.0%. Remained the same
6060940963

push

github

niteshpurohit
chore: maintainance

1 of 1 new or added line in 1 file covered. (100.0%)

205 of 205 relevant lines covered (100.0%)

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

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

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

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

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