Sha256: 68bb6e1510714d722edd5af08f1ffe70a899c7cfc75c0b922eea6041cf8ffbd5

Contents?: true

Size: 1.44 KB

Versions: 21

Compression:

Stored size: 1.44 KB

Contents

module NetSuite
  module Support
    module Records
      include Attributes
      include Namespaces::PlatformCore

      def to_record
        attributes.reject { |k,v| self.class.read_only_fields.include?(k) }.inject({}) do |hash, (k,v)|
          kname = if k == :klass
                    "#{record_namespace}:class"
                  else
                    "#{record_namespace}:#{k.to_s.lower_camelcase}"
                  end
          if v.respond_to?(:internal_id) && v.internal_id
            hash[:attributes!] ||= {}
            hash[:attributes!][kname] ||= {}
            hash[:attributes!][kname]['internalId'] = v.internal_id
          end
          if v.respond_to?(:external_id) && v.external_id
            hash[:attributes!] ||= {}
            hash[:attributes!][kname] ||= {}
            hash[:attributes!][kname]['externalId'] = v.external_id
          end
          if v.kind_of?(NetSuite::Records::RecordRef) && v.type
            hash[:attributes!] ||= {}
            hash[:attributes!][kname] ||= {}
            hash[:attributes!][kname]['type'] = v.type.lower_camelcase
          end
          if Array === v
            v = v.map { |i| i.respond_to?(:to_record) ? i.to_record : i }
          else
            v = v.to_record if v.respond_to?(:to_record)
          end
          hash[kname] = v
          hash
        end
      end

      def record_type
        "#{record_namespace}:#{self.class.to_s.split('::').last}"
      end

    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
netsuite-0.0.35 lib/netsuite/support/records.rb
netsuite-0.0.34 lib/netsuite/support/records.rb
netsuite-0.0.33 lib/netsuite/support/records.rb
netsuite-0.0.32 lib/netsuite/support/records.rb
netsuite-0.0.31 lib/netsuite/support/records.rb
netsuite-0.0.30 lib/netsuite/support/records.rb
netsuite-0.0.29 lib/netsuite/support/records.rb
netsuite-0.0.28 lib/netsuite/support/records.rb
netsuite-0.0.27 lib/netsuite/support/records.rb
netsuite-0.0.26 lib/netsuite/support/records.rb
netsuite-0.0.25 lib/netsuite/support/records.rb
netsuite-0.0.23 lib/netsuite/support/records.rb
netsuite-0.0.22 lib/netsuite/support/records.rb
netsuite-0.0.21 lib/netsuite/support/records.rb
netsuite-0.0.20 lib/netsuite/support/records.rb
netsuite-0.0.19 lib/netsuite/support/records.rb
netsuite-0.0.18 lib/netsuite/support/records.rb
netsuite-0.0.17 lib/netsuite/support/records.rb
netsuite-0.0.16 lib/netsuite/support/records.rb
netsuite-0.0.15 lib/netsuite/support/records.rb