Class: Alchemrest::Response::Pipeline::Omit
- Inherits:
-
Morpher::Transform
- Object
- Morpher::Transform
- Alchemrest::Response::Pipeline::Omit
- Defined in:
- lib/alchemrest/response/pipeline/omit.rb
Constant Summary collapse
- PRIMITIVE =
Primitive.new(::Hash)
Instance Method Summary collapse
- #call(input) ⇒ Object
- #delete_from(input) ⇒ Object
-
#initialize(omit = nil) ⇒ Omit
constructor
A new instance of Omit.
- #omit_nodes(input) ⇒ Object
Constructor Details
#initialize(omit = nil) ⇒ Omit
Returns a new instance of Omit.
11 12 13 14 |
# File 'lib/alchemrest/response/pipeline/omit.rb', line 11 def initialize(omit = nil) @omit = omit super end |
Instance Method Details
#call(input) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/alchemrest/response/pipeline/omit.rb', line 16 def call(input) if input.is_a?(::Array) array.call(input) else PRIMITIVE .call(input) .bind { |i| omit_nodes(i) } end end |
#delete_from(input) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/alchemrest/response/pipeline/omit.rb', line 34 def delete_from(input) omit.each do |path| path.walk(input) do |_path, node, remaining_segments| if remaining_segments.count == 1 node.delete(remaining_segments.last) end end end end |
#omit_nodes(input) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/alchemrest/response/pipeline/omit.rb', line 26 def omit_nodes(input) dup = input.dup if omit.present? delete_from(dup) end success(dup) end |