Class: JsonPath::PathContextCollection

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/json-path-builder/path_context_collection.rb

Overview

rubocop:disable Metrics/ParameterLists

Constant Summary collapse

ROOT_PATHS =
%w[* .].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths_builder) ⇒ PathContextCollection

Returns a new instance of PathContextCollection.



8
9
10
11
12
13
14
# File 'lib/json-path-builder/path_context_collection.rb', line 8

def initialize(paths_builder)
  @builder = paths_builder
  @source_data = nil
  @nested_paths = []

  super([])
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



6
7
8
# File 'lib/json-path-builder/path_context_collection.rb', line 6

def builder
  @builder
end

#source_dataObject (readonly)

Returns the value of attribute source_data.



6
7
8
# File 'lib/json-path-builder/path_context_collection.rb', line 6

def source_data
  @source_data
end

Instance Method Details

#add_path(path, paths_builder, iterable_data:, transform:, defaults:, fallback_proc:, skip_if_proc:, to: nil, use_builder: true) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/json-path-builder/path_context_collection.rb', line 34

def add_path(path, paths_builder,
             iterable_data:,
             transform:,
             defaults:,
             fallback_proc:,
             skip_if_proc:,
             to: nil,
             use_builder: true)
  push(PathContext.new(path, paths_builder,
                       to: to,
                       iterable_data: iterable_data,
                       transform: transform,
                       use_builder: use_builder,
                       defaults: defaults,
                       fallback_proc: fallback_proc,
                       skip_if_proc: skip_if_proc))
  self
end

#data_wrapper_classObject



20
21
22
# File 'lib/json-path-builder/path_context_collection.rb', line 20

def data_wrapper_class
  @data_wrapper_class || DefaultDataWrapper
end

#nested_pathsObject



24
25
26
# File 'lib/json-path-builder/path_context_collection.rb', line 24

def nested_paths
  @nested_paths.reject { |p| p.blank? || ROOT_PATHS.include?(p) }
end

#reject_from_paths!(from_paths) ⇒ Object



16
17
18
# File 'lib/json-path-builder/path_context_collection.rb', line 16

def reject_from_paths!(from_paths)
  reject! { |path_context| from_paths.include?(path_context.from.to_s) }
end

#with_source_data(data) ⇒ Object



53
54
55
56
57
58
# File 'lib/json-path-builder/path_context_collection.rb', line 53

def with_source_data(data)
  @source_data = data

  each { |path| path.with_source_data(data) }
  self
end

#with_wrapped_data_class(klass) ⇒ Object



60
61
62
# File 'lib/json-path-builder/path_context_collection.rb', line 60

def with_wrapped_data_class(klass)
  @data_wrapper_class = klass
end

#within(json_path) {|builder| ... } ⇒ Object

Yields:



28
29
30
31
32
# File 'lib/json-path-builder/path_context_collection.rb', line 28

def within(json_path)
  @nested_paths.push(json_path)
  yield builder
  @nested_paths.pop
end