Class: OpenAPISourceTools::ApiObjects::ValueRetainer
- Inherits:
-
Object
- Object
- OpenAPISourceTools::ApiObjects::ValueRetainer
- Defined in:
- lib/openapi/sourcetools/apiobjects.rb
Overview
Any value with given key has all but retained keys removed.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#retain ⇒ Object
Returns the value of attribute retain.
Instance Method Summary collapse
-
#initialize(trigger_key) ⇒ ValueRetainer
constructor
A new instance of ValueRetainer.
- #process(obj) ⇒ Object
Constructor Details
#initialize(trigger_key) ⇒ ValueRetainer
Returns a new instance of ValueRetainer.
45 46 47 48 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 45 def initialize(trigger_key) @key = trigger_key @retain = [ trigger_key ] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
42 43 44 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 42 def key @key end |
#retain ⇒ Object
Returns the value of attribute retain.
43 44 45 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 43 def retain @retain end |
Instance Method Details
#process(obj) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 50 def process(obj) if obj.is_a?(Array) obj.each { |item| process(item) } return end return unless obj.is_a?(Hash) if obj.key?(@key) obj.delete_if { |k, _v| !@retain.include?(k) } end obj.each_value do |value| process(value) end end |