Class: NetSuite::Records::CustomFieldList

Inherits:
Object
  • Object
show all
Includes:
Namespaces::PlatformCore
Defined in:
lib/netsuite/records/custom_field_list.rb

Instance Method Summary collapse

Methods included from Namespaces::PlatformCore

#record_namespace

Constructor Details

#initialize(attributes = {}) ⇒ CustomFieldList

Returns a new instance of CustomFieldList.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/netsuite/records/custom_field_list.rb', line 6

def initialize(attributes = {})
  case attributes[:custom_field]
  when Hash
    extract_custom_field(attributes[:custom_field])
  when Array
    attributes[:custom_field].each { |custom_field| extract_custom_field(custom_field) }
  end
  
  @custom_fields_assoc = Hash.new
  custom_fields.each { |custom_field| @custom_fields_assoc[custom_field.internal_id.to_sym] = custom_field }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



22
23
24
25
# File 'lib/netsuite/records/custom_field_list.rb', line 22

def method_missing(sym, *args, &block)
  return @custom_fields_assoc[sym] if @custom_fields_assoc.include? sym
  super(sym, *args, &block)
end

Instance Method Details

#custom_fieldsObject



18
19
20
# File 'lib/netsuite/records/custom_field_list.rb', line 18

def custom_fields
  @custom_fields ||= []
end

#respond_to?(sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/netsuite/records/custom_field_list.rb', line 27

def respond_to?(sym, include_private = false)
  return true if @custom_fields_assoc.include? sym
  super
end

#to_recordObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/netsuite/records/custom_field_list.rb', line 32

def to_record
  # TODO this is the best way I could find to handle this, there *has* to be a better way
  # http://stackoverflow.com/questions/7001957/savon-array-of-xml-tags

  {
    "#{record_namespace}:customField" => custom_fields.map(&:to_record),
    :attributes! => {
      "#{record_namespace}:customField" => {
        'internalId' => custom_fields.map(&:internal_id),
        'xsi:type' => custom_fields.map(&:type)
      }
    }
  }
end