Class: Io::Flow::V0::Models::InventoryStrategy

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

Overview

Types of rules used to apply on inventory to calculate available quantity

Defined Under Namespace

Modules: Types

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ InventoryStrategy

Returns a new instance of InventoryStrategy.



4001
4002
4003
4004
4005
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4001

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

Class Method Details

.from_json(hash) ⇒ Object



4011
4012
4013
4014
4015
4016
4017
4018
4019
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4011

def InventoryStrategy.from_json(hash)
  HttpClient::Preconditions.assert_class('hash', hash, Hash)
  case HttpClient::Helper.symbolize_keys(hash)[:discriminator]
    when Types::INVENTORY_BACKORDER; InventoryBackorder.new(hash)
    when Types::INVENTORY_STOCK; InventoryStock.new(hash)
    when Types::INVENTORY_UNLIMITED; InventoryUnlimited.new(hash)
    else InventoryStrategyUndefinedType.new(:name => union_type_name)
  end
end

Instance Method Details

#to_hashObject



4007
4008
4009
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4007

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