Class: OpenAPISourceTools::ApiObjects::ValueReplacer
- Inherits:
-
Object
- Object
- OpenAPISourceTools::ApiObjects::ValueReplacer
- Defined in:
- lib/openapi/sourcetools/apiobjects.rb
Overview
A replacer for value of a given key.
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(trigger_key, components) ⇒ ValueReplacer
constructor
A new instance of ValueReplacer.
- #replace(obj) ⇒ Object
Constructor Details
#initialize(trigger_key, components) ⇒ ValueReplacer
Returns a new instance of ValueReplacer.
69 70 71 72 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 69 def initialize(trigger_key, components) @key = trigger_key @components = components end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
67 68 69 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 67 def components @components end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
67 68 69 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 67 def key @key end |
Instance Method Details
#replace(obj) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 74 def replace(obj) if obj.is_a?(Array) obj.each { |item| replace(item) } return end return unless obj.is_a?(Hash) obj.each do |key, value| if key == @key if value.is_a?(Array) value.each do |item| next unless item.is_a?(Hash) next if item.key?('$ref') @components.to_reference_object(item) end elsif value.is_a?(Hash) next if value.key?('$ref') @components.to_reference_object(value) end else replace(value) end end end |