Class: NetSuite::Support::Sublist

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

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.



29
30
31
# File 'lib/netsuite/support/sublist.rb', line 29

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

Class Method Details

.sublist(key, klass) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/netsuite/support/sublist.rb', line 8

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



43
44
45
46
# File 'lib/netsuite/support/sublist.rb', line 43

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

#to_recordObject



33
34
35
36
37
38
39
40
41
# File 'lib/netsuite/support/sublist.rb', line 33

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

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

  rec
end