class ActiveNetsuite::Record
{urn:core_2013_2.platform.webservices.netsuite.com}Record abstract
nullFieldList - ActiveNetsuite::NullField
Attributes
nullFieldList[RW]
Public Class Methods
all()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 50 def all search.response end
basic_search_class()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 39 def basic_search_class "::#{to_s}SearchBasic".constantize end
client()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 9 def client @@client ||= nil end
client=(client)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 13 def client=(client) @@client = client end
delete(objects)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 54 def delete(objects) objects = [objects] unless objects.respond_to?(:map) client.delete_list(refs(objects)) end
deleted(op, val)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 64 def deleted(op, val) op = ('ActiveNetsuite::SearchDateFieldOperator::' + op.to_s.camelize).constantize val = ('ActiveNetsuite::SearchDate::' + val.to_s.camelize).constantize search_value = SearchDateField.new search_value.xmlattr_operator = op search_value.predefinedSearchValue = val search_type = SearchEnumMultiSelectField.new search_type.xmlattr_operator = SearchEnumMultiSelectFieldOperator::AnyOf search_type.searchValue = type get_deleted_filter = GetDeletedFilter.new(search_value, search_type) client.get_deleted(get_deleted_filter) end
find(id)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 26 def find(id) find_by_id(internal_id: id) or raise_not_found_error(internal_id: id) end
Also aliased as: get
find_by_external_id(id)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 31 def find_by_external_id(id) find_by_id(external_id: id) end
find_by_id(args)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 35 def find_by_id(args) client.get(ref(args)).record end
find_by_internal_id(id)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 22 def find_by_internal_id(id) find_by_id(internal_id: id) end
list(objects)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 45 def list(objects) objects = [objects] unless objects.respond_to?(:map) client.get_list(refs(objects)) end
new(nullFieldList = nil)
click to toggle source
# File lib/activenetsuite/soap/default.rb, line 188 def initialize(nullFieldList = nil) @nullFieldList = nullFieldList end
raise_not_found_error(arg)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 104 def raise_not_found_error(arg) raise NotFoundError, not_found_error_message(ref(arg)) end
ref(arg)
click to toggle source
Convert arg to RecordRef
@overload ref(internal_id)
@param [String] internal_id
@overload ref(hash)
@param [Hash] hash with internal_id or external_id @option opts [String] :internal_id @option opts [String] :external_id
@return RecordRef
@example
ref = Record.arg(12) ref.class # => RecordRef ref.type # => 'record' ref.internal_id # => 12 ref = Record.arg(external_id: 12) ref.external_id # => 12
# File lib/activenetsuite/core/record.rb, line 95 def ref(arg) ref = RecordRef.new ref.type = type arg = {internal_id: arg} unless arg.is_a?(Hash) ref.internal_id = arg[:internal_id] ref.external_id = arg[:external_id] ref end
type()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 17 def type type = to_s.split('::').last type[0,1].downcase + type[1..-1] end
update(records)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 59 def update(records) records = [records] unless records.respond_to?(:map) client.update_list(records) end
Private Class Methods
not_found_error_message(ref)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 129 def not_found_error_message(ref) "type: #{ref.type}, internal_id: #{ref.internal_id}, " \ "external_id: #{ref.external_id}" end
refs(objects)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 116 def refs(objects) objects.map do |object| case object when RecordRef object when Record object.ref when String, Integer ref(object) end end end
search()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 110 def search search = basic_search_class.new search.record_class = self search end
Public Instance Methods
active=(value)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 214 def active=(value) self.is_inactive = !value end
active?()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 206 def active? !is_inactive end
add()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 135 def add res = client.add(self) if res.success? self.internal_id = res.internal_id end res end
add!()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 143 def add! raise_on_fail(:add) end
client()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 187 def client self.class.client end
delete()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 175 def delete res = client.delete(ref) if res.success? self.internal_id = nil end res end
delete!()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 183 def delete! raise_on_error(:delete) end
getters()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 230 def getters setters.map(&:to_s).map(&:chop).map(&:to_sym) end
inactive=(value)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 218 def inactive=(value) self.is_inactive = !!value end
inactive?()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 210 def inactive? !active? end
load()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 191 def load return self if loaded? result = find_by_id result.getters.each do |getter| send :"#{getter}=", result.send(getter) end @loaded = true self end
loaded?()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 202 def loaded? !!@loaded end
new?()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 171 def new? !internal_id end
ref()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 222 def ref self.class.ref(internal_id) end
save()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 155 def save if new? add else update end end
save!()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 163 def save! if new? add! else update! end end
setters()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 226 def setters public_methods(false).grep(/=$/) end
update()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 147 def update client.update(self) end
update!()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 151 def update! raise_on_fail(:update) end
Private Instance Methods
by_external_id()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 258 def by_external_id self.class.find_by_external_id(external_id) if external_id end
by_internal_id()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 254 def by_internal_id self.class.find_by_internal_id(internal_id) if internal_id end
find_by_id()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 250 def find_by_id by_internal_id || by_external_id or raise_not_found_error end
not_found_error_message()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 246 def not_found_error_message self.class.not_found_error_message(ref) end
raise_not_found_error()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 242 def raise_not_found_error self.class.raise_not_found_error(ref) end
raise_on_fail(method)
click to toggle source
# File lib/activenetsuite/core/record.rb, line 236 def raise_on_fail(method) res = send(method) return res if res.success? raise NetsuiteError, res end
type()
click to toggle source
# File lib/activenetsuite/core/record.rb, line 262 def type self.class.type end