Class: NetSuite::Support::Sublist

Inherits:
Object
  • Object
show all
Includes:
Fields
Defined in:
lib/netsuite/support/sublist.rb

Direct Known Subclasses

Records::AssemblyComponentList, Records::BaseRefList, Records::BillingScheduleMilestoneList, Records::BillingScheduleRecurrenceList, Records::BinNumberList, Records::BinTransferInventoryList, Records::CashRefundItemList, Records::CashSaleItemList, Records::ContactAccessRolesList, Records::ContactAddressbookList, Records::CreditMemoApplyList, Records::CreditMemoItemList, Records::CustomListCustomValueList, Records::CustomerAddressbookList, Records::CustomerCreditCardsList, Records::CustomerCurrencyList, Records::CustomerDepositApplyList, Records::CustomerPartnersList, Records::CustomerPaymentApplyList, Records::CustomerPaymentCreditList, Records::CustomerRefundApplyList, Records::CustomerRefundDepositList, Records::CustomerSalesTeamList, Records::DepositCashBackList, Records::DepositOtherList, Records::DepositPaymentList, Records::EstimateItemList, Records::GiftCertRedemptionList, Records::InboundShipmentItemList, Records::InterCompanyJournalEntryLineList, Records::InventoryAdjustmentInventoryList, Records::InventoryNumberLocationsList, Records::InventoryTransferInventoryList, Records::InvoiceItemList, Records::ItemFulfillmentItemList, Records::ItemFulfillmentPackageList, Records::ItemMemberList, Records::ItemReceiptItemList, Records::ItemVendorList, Records::JournalEntryLineList, Records::MemberList, Records::OpportunityItemList, Records::PriceList, Records::PricingMatrix, Records::PromotionsList, Records::PurchaseOrderItemList, Records::RecordRefList, Records::ReturnAuthorizationItemList, Records::RoleList, Records::SalesOrderItemList, Records::SalesOrderShipGroupList, Records::SerializedInventoryItemLocationsList, Records::SerializedInventoryItemNumbersList, Records::SubscriptionsList, Records::TransferOrderItemList, Records::TranslationList, Records::UnitsTypeUomList, Records::VendorBillExpenseList, Records::VendorBillItemList, Records::VendorCreditApplyList, Records::VendorCreditExpenseList, Records::VendorCreditItemList, Records::VendorCurrencyList, Records::VendorPaymentApplyList, Records::VendorReturnAuthorizationItemList, Records::WorkOrderItemList

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fields

included

Methods included from Attributes

#attributes, #attributes=, #initialize_from_attributes_hash

Constructor Details

#initialize(attributes = {}) ⇒ Sublist

Returns a new instance of Sublist.



33
34
35
# File 'lib/netsuite/support/sublist.rb', line 33

def initialize(attributes = {})
  initialize_from_attributes_hash(attributes || {})
end

Class Method Details

.inherited(subclass) ⇒ Object



6
7
8
9
10
# File 'lib/netsuite/support/sublist.rb', line 6

def self.inherited(subclass)
  subclass.class_eval do
    field :replace_all
  end
end

.sublist(key, klass) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/netsuite/support/sublist.rb', line 14

def sublist(key, klass)
  field key

  # TODO setting class methods might be better? How to reach into the subclass?

  define_method(:sublist_key) { key }
  define_method(:sublist_class) { klass }

  define_method("#{key}=") do |list|
    self.process_sublist(list)
  end

  define_method("#{key}") do
    @list ||= []
  end
end

Instance Method Details

#<<(item) ⇒ Object



47
48
49
50
# File 'lib/netsuite/support/sublist.rb', line 47

def <<(item)
  @list ||= []
  @list << self.process_sublist_item(item)
end

#to_recordObject



37
38
39
40
41
42
43
44
45
# File 'lib/netsuite/support/sublist.rb', line 37

def to_record
  rec = { "#{record_namespace}:#{NetSuite::Utilities::Strings.lower_camelcase(sublist_key.to_s)}" => send(self.sublist_key).map(&:to_record) }

  if !replace_all.nil?
    rec["#{record_namespace}:replaceAll"] = !!replace_all
  end

  rec
end