Class: OpenAPISourceTools::ApiObjects::ValueSubValueReplacer
- Inherits:
-
Object
- Object
- OpenAPISourceTools::ApiObjects::ValueSubValueReplacer
- Defined in:
- lib/openapi/sourcetools/apiobjects.rb
Overview
A replacer for sub-values of a 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) ⇒ ValueSubValueReplacer
constructor
A new instance of ValueSubValueReplacer.
- #replace(obj) ⇒ Object
Constructor Details
#initialize(trigger_key, components) ⇒ ValueSubValueReplacer
Returns a new instance of ValueSubValueReplacer.
103 104 105 106 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 103 def initialize(trigger_key, components) @key = trigger_key @components = components end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
101 102 103 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 101 def components @components end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
101 102 103 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 101 def key @key end |
Instance Method Details
#replace(obj) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/openapi/sourcetools/apiobjects.rb', line 108 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 && value.is_a?(Hash) value.keys.sort!.each do |sub_key| sub_value = value[sub_key] next unless sub_value.is_a?(Hash) next if sub_value.key?('$ref') @components.to_reference_object(value[sub_key]) end else replace(value) end end end |