Class: Exwiw::MaskValue

Inherits:
Serdes::TypeBase
  • Object
show all
Defined in:
lib/exwiw/mask_value.rb

Overview

Serdes type for a replace_with value: a template String with {column} placeholders, rendered as text, or a non-String JSON scalar used verbatim so a column that is not text keeps its type (in MongoDB, its BSON type).

Constant Summary collapse

PERMITTED =
[String, Integer, Float].freeze
PLACEHOLDER =

What counts as a {column} placeholder: an empty brace pair names no column, which is what lets {} be an empty-JSON mask. One definition, shared by the adapters that parse a template and the generator that must avoid emitting one — keep it capture-free, since the splitter's scan reads whole matches.

/\{[^{}]+\}/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.scalar?(value) ⇒ Boolean

Whether value is used verbatim rather than rendered as a template.

Returns:

  • (Boolean)


22
23
24
# File 'lib/exwiw/mask_value.rb', line 22

def self.scalar?(value)
  !value.is_a?(String) && !value.nil?
end

Instance Method Details

#permit?(value) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/exwiw/mask_value.rb', line 17

def permit?(value)
  value == true || value == false || PERMITTED.any? { |type| value.is_a?(type) }
end

#to_sObject



26
27
28
# File 'lib/exwiw/mask_value.rb', line 26

def to_s
  "mask_value"
end