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

Code-Vedas / mutils / 7256910110

19 Dec 2023 03:16AM CUT coverage: 100.0%. Remained the same
7256910110

push

github

web-flow
Update master.yml

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/attributes.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 Attributes
10
      module Attributes
4✔
11
        def attributes(*attributes_list)
4✔
12
          parse_attributes_methods(attributes_list, false)
24✔
13
        end
14

15
        def custom_methods(*attributes_list)
4✔
16
          parse_attributes_methods(attributes_list, true)
16✔
17
        end
18

19
        def parse_attributes_methods(list, is_method)
4✔
20
          self.attributes_to_serialize = {} if attributes_to_serialize.nil?
40✔
21
          list&.each do |attr|
40✔
22
            value = { method: is_method, always_include: true }
52✔
23
            attributes_to_serialize[attr] = value
52✔
24
          end
25
        end
26

27
        def attribute(method_name, options = {}, &proc)
4✔
28
          raise "if: should be a Proc object for attribute #{method_name}" if options[:if] && !options[:if].instance_of?(Proc)
16✔
29

30
          if proc.instance_of? Proc
16✔
31
            self.attributes_to_serialize_blocks = {} if attributes_to_serialize_blocks.nil?
12✔
32
            options[:block] = proc
12✔
33
            attributes_to_serialize_blocks[method_name] = options
12✔
34
          else
35
            add_single_attribute(method_name, options, false)
4✔
36
          end
37
        end
38

39
        def custom_method(method_name, options = {})
4✔
40
          add_single_attribute(method_name, options, true)
36✔
41
        end
42

43
        def add_single_attribute(method_name, options, is_method)
4✔
44
          self.attributes_to_serialize = {} if attributes_to_serialize.nil?
40✔
45
          always_include = options[:always_include].nil? ? false : options[:always_include]
40✔
46
          value = { method: is_method, always_include: always_include, if: options[:if] }
40✔
47
          attributes_to_serialize[method_name] = value
40✔
48
        end
49
      end
50
    end
51
  end
52
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