Class: DryOpenApi::Discriminator
- Inherits:
-
Object
- Object
- DryOpenApi::Discriminator
- Includes:
- EquatableAsContent
- Defined in:
- lib/dry_open_api/discriminator.rb
Overview
Instance Attribute Summary collapse
-
#mapping ⇒ Object
Returns the value of attribute mapping.
-
#property_name ⇒ Object
Returns the value of attribute property_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(property_name: nil, mapping: {}, **other_fields_hash) ⇒ Discriminator
constructor
A new instance of Discriminator.
Methods included from EquatableAsContent
Constructor Details
#initialize(property_name: nil, mapping: {}, **other_fields_hash) ⇒ Discriminator
Returns a new instance of Discriminator.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dry_open_api/discriminator.rb', line 8 def initialize(property_name: nil, mapping: {}, **other_fields_hash) self.property_name = property_name self.mapping = mapping.with_indifferent_access self.other_fields_hash = other_fields_hash other_fields_hash.keys.each do |field_name| define_singleton_method(field_name) do other_fields_hash[field_name] end define_singleton_method("#{field_name}=") do |value| other_fields_hash[field_name] = value end end end |
Instance Attribute Details
#mapping ⇒ Object
Returns the value of attribute mapping.
6 7 8 |
# File 'lib/dry_open_api/discriminator.rb', line 6 def mapping @mapping end |
#property_name ⇒ Object
Returns the value of attribute property_name.
6 7 8 |
# File 'lib/dry_open_api/discriminator.rb', line 6 def property_name @property_name end |
Class Method Details
.load(hash) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dry_open_api/discriminator.rb', line 23 def self.load(hash) return unless hash fixed_field_names = %w[propertyName mapping] other_fields_hash = hash.reject { |key| key.to_s.in?(fixed_field_names) } new( property_name: hash['propertyName'].to_s, mapping: hash['mapping'], **other_fields_hash.symbolize_keys, ) end |