Class: PaperTrailDiff::IgnorePolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/paper_trail_diff/configuration.rb,
sig/generated/paper_trail_diff/configuration.rbs

Overview

Immutable rules for globally and path-specifically excluded attributes.

Constant Summary collapse

ROOT_PATH =

Returns:

  • (::String)
'$'
VALID_KEYS =

Returns:

  • (Object)
%w[all paths].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(all:, paths:) ⇒ IgnorePolicy

: (all: Array, paths: Hash[String, Array[String]]) -> void

Parameters:

  • all: (Array[String])
  • paths: (Hash[String, Array[String]])


158
159
160
161
162
# File 'lib/paper_trail_diff/configuration.rb', line 158

def initialize(all:, paths:)
  @all = all.dup.freeze
  @paths = paths.dup.freeze
  freeze
end

Instance Attribute Details

#allArray[String] (readonly)

Signature:

  • Array[String]

Returns:

  • (Array[String])


154
155
156
# File 'lib/paper_trail_diff/configuration.rb', line 154

def all
  @all
end

#pathsHash[String, Array[String]] (readonly)

Signature:

  • Hash[String, Array[String]]

Returns:

  • (Hash[String, Array[String]])


155
156
157
# File 'lib/paper_trail_diff/configuration.rb', line 155

def paths
  @paths
end

Class Method Details

.build(value, association_paths:) ⇒ IgnorePolicy

: (untyped, association_paths: Array) -> IgnorePolicy

Parameters:

  • (Object)
  • association_paths: (Array[String])

Returns:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/paper_trail_diff/configuration.rb', line 89

def build(value, association_paths:)
  return new(all: normalize_names(value, context: 'ignore'), paths: {}) if value.is_a?(Array)

  unless value.is_a?(Hash)
    raise ConfigurationError, 'ignore: must be an array or a hash with all: and paths:'
  end

  options = normalize_options(value)
  empty_paths = {} #: Hash[untyped, untyped]
  new(
    all: normalize_names(options.fetch('all', []), context: 'ignore[:all]'),
    paths: normalize_paths(options.fetch('paths', empty_paths), association_paths)
  )
end

Instance Method Details

#attributes_for(path) ⇒ Array[String]

: (String) -> Array

Parameters:

  • (String)

Returns:

  • (Array[String])


165
166
167
168
# File 'lib/paper_trail_diff/configuration.rb', line 165

def attributes_for(path)
  external_path = path.empty? ? ROOT_PATH : path
  (all + paths.fetch(external_path, [])).uniq.freeze
end