Class: BitmaskEnum::NilHandler Private

Inherits:
Object
  • Object
show all
Defined in:
lib/bitmask_enum/nil_handler.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Handles nil attribute values

Instance Method Summary collapse

Constructor Details

#initialize(handling_option) ⇒ NilHandler

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of NilHandler.



7
8
9
# File 'lib/bitmask_enum/nil_handler.rb', line 7

def initialize(handling_option)
  @handling_option = handling_option
end

Instance Method Details

#in_array(array) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handles nil for an array of values for the attribute

Parameters:

  • array (Array)

    Array of integers representing values of the attribute

Returns:

  • (Array)

    Array of integers representing values of the attribute, now corrected for nil values



24
25
26
27
28
29
# File 'lib/bitmask_enum/nil_handler.rb', line 24

def in_array(array)
  select_handling(
    array,
    include: ->(arr) { arr << nil }
  )
end

#in_attribute_eval(attribute) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handles nil when evaling the attribute

Parameters:

  • attribute (String)

    Name of the attribute

Returns:

  • (String)

    Code string to handle a nil attribute according to the handling option



14
15
16
17
18
19
# File 'lib/bitmask_enum/nil_handler.rb', line 14

def in_attribute_eval(attribute)
  select_handling(
    attribute,
    include: ->(attrib) { "(self['#{attrib}'] || 0)" }
  )
end