Class: Io::Flow::V0::Models::FieldValidationRule

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Defined Under Namespace

Modules: Types

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ FieldValidationRule

Returns a new instance of FieldValidationRule.



12100
12101
12102
12103
12104
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12100

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:discriminator], 'FieldValidationRule')
  @discriminator = HttpClient::Preconditions.assert_class('discriminator', opts.delete(:discriminator), String)
end

Instance Attribute Details

#discriminatorObject (readonly)

Returns the value of attribute discriminator.



12098
12099
12100
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12098

def discriminator
  @discriminator
end

Class Method Details

.from_json(hash) ⇒ Object



12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12114

def FieldValidationRule.from_json(hash)
  HttpClient::Preconditions.assert_class('hash', hash, Hash)
  discriminator = HttpClient::Helper.symbolize_keys(hash)[:discriminator].to_s.strip
  if discriminator.empty?
    raise "Union type[field_validation_rule] requires a field named 'discriminator'"
  end
  case discriminator
    when Types::FIELD_VALIDATION_REQUIRED; FieldValidationRequired.new(hash)
    when Types::FIELD_VALIDATION_REQUIRED_IF_PRESENT; FieldValidationRequiredIfPresent.new(hash)
    when Types::FIELD_VALIDATION_MIN; FieldValidationMin.new(hash)
    when Types::FIELD_VALIDATION_MAX; FieldValidationMax.new(hash)
    when Types::FIELD_VALIDATION_PATTERN; FieldValidationPattern.new(hash)
    else FieldValidationRuleUndefinedType.new(:discriminator => discriminator)
  end
end

Instance Method Details

#subtype_to_hashObject



12106
12107
12108
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12106

def subtype_to_hash
  raise 'Cannot serialize an instance of field_validation_rule directly - must use one of the specific types: field_validation_required, field_validation_required_if_present, field_validation_min, field_validation_max, field_validation_pattern'
end

#to_hashObject



12110
12111
12112
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12110

def to_hash
  subtype_to_hash.merge(:discriminator => @discriminator)
end