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.



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}:#{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