Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

actions are now dynamically defined in modules that are then included

  • Loading branch information...
commit 167d090860c012007abe4c1a1ecd33f405c95dd1 1 parent 3a7ebb3
@ryanmoran ryanmoran authored
View
3  Rakefile
@@ -12,7 +12,6 @@ end
desc 'Generate code coverage'
RSpec::Core::RakeTask.new(:coverage) do |t|
- t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
t.rcov = true
- t.rcov_opts = ['--exclude', 'spec']
+ t.rcov_opts = ['--exclude', '/gems/,spec']
end
View
1  lib/netsuite.rb
@@ -20,6 +20,7 @@ module Namespaces
end
module Support
+ autoload :Actions, 'netsuite/support/actions'
autoload :Attributes, 'netsuite/support/attributes'
autoload :Fields, 'netsuite/support/fields'
autoload :RecordRefs, 'netsuite/support/record_refs'
View
12 lib/netsuite/records/account.rb
@@ -3,6 +3,9 @@ module Records
class Account
include Support::Fields
include Support::RecordRefs
+ include Support::Actions
+
+ actions :get
fields :acct_name, :acct_number, :acct_type, :cash_flow_rate, :cur_doc_num, :description, :eliminate, :exchange_rate,
:general_rate, :include_children, :inventory, :is_inactive, :opening_balance, :revalue, :tran_date
@@ -18,15 +21,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
end
end
end
View
12 lib/netsuite/records/classification.rb
@@ -2,6 +2,9 @@ module NetSuite
module Records
class Classification
include Support::Fields
+ include Support::Actions
+
+ actions :get
fields :name, :include_children, :is_inactive, :class_translation_list, :subsidiary_list, :custom_field_list
@@ -14,15 +17,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
end
end
end
View
26 lib/netsuite/records/credit_memo.rb
@@ -4,8 +4,11 @@ class CreditMemo
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::TranCust
+ actions :get, :add, :initialize
+
fields :alt_handling_cost, :alt_shipping_cost, :amount_paid, :amount_remaining, :auto_apply, :balance,
:bill_address, :contrib_pct, :created_date, :currency_name, :deferred_revenue, :discount_rate, :email,
:est_gross_profit, :est_gross_profit_percent, :exchange_rate, :exclude_commission, :fax, :gift_cert_applied,
@@ -31,29 +34,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
- def self.initialize(object)
- response = Actions::Initialize.call(self, object)
- if response.success?
- new(response.body)
- else
- raise InitializationError, "#{self}.initialize with #{object} failed."
- end
- end
-
- def add
- response = Actions::Add.call(self)
- response.success?
- end
-
end
end
end
View
16 lib/netsuite/records/custom_record.rb
@@ -4,8 +4,11 @@ class CustomRecord
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::SetupCustom
+ actions :get, :add
+
fields :allow_attachments, :allow_inline_editing, :allow_numbering_override, :allow_quick_search, :created,
:custom_record_id, :description, :disclaimer, :enabl_email_merge, :enable_numbering, :include_name,
:is_available_offline, :is_inactive, :is_numbering_updateable, :is_ordered, :last_modified, :name,
@@ -28,17 +31,8 @@ def initialize(attributes = {})
def self.get(options = {})
options.merge!(:type_id => type_id) unless options[:type_id]
- response = Actions::Get.call(self, options.merge!(:custom => true))
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
- def add
- response = Actions::Add.call(self)
- response.success?
+ options.merge!(:custom => true)
+ super(options)
end
def self.type_id(id = nil)
View
12 lib/netsuite/records/custom_record_type.rb
@@ -3,6 +3,9 @@ module Records
class CustomRecordType
include Support::Fields
include Support::RecordRefs
+ include Support::Actions
+
+ actions :get
fields :allow_attachments, :allow_inline_editing, :allow_numbering_override, :allow_quick_search, :description,
:disclaimer, :enable_mail_merge, :enable_numbering, :include_name, :is_available_offline, :is_inactive,
@@ -22,15 +25,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
end
end
end
View
17 lib/netsuite/records/customer.rb
@@ -4,8 +4,11 @@ class Customer
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::ListRel
+ actions :get, :add
+
fields :access_role, :account_number, :aging, :alt_email, :alt_name, :alt_phone, :bill_pay,
:buying_reason, :buying_time_frame, :campaign_category, :category, :click_stream, :comments, :company_name,
:consol_aging, :consol_days_overdue, :contact_roles_list, :contrib_pct, :credit_cards_list, :credit_hold_override,
@@ -38,20 +41,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
- def add
- response = Actions::Add.call(self)
- response.success?
- end
-
end
end
end
View
26 lib/netsuite/records/customer_payment.rb
@@ -4,8 +4,11 @@ class CustomerPayment
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::TranCust
+ actions :get, :initialize, :add
+
fields :auth_code, :auto_apply, :cc_approved, :cc_avs_street_match, :cc_avs_zip_match,
:cc_expire_date, :cc_name, :cc_number, :cc_security_code, :cc_security_code_match, :cc_street, :cc_zip_code,
:charge_it, :check_num, :created_date, :currency_name, :debit_card_issue_no, :exchange_rate, :ignore_avs,
@@ -28,29 +31,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
- def self.initialize(object)
- response = Actions::Initialize.call(self, object)
- if response.success?
- new(response.body)
- else
- raise InitializationError, "#{self}.initialize with #{object} failed."
- end
- end
-
- def add
- response = Actions::Add.call(self)
- response.success?
- end
-
end
end
end
View
26 lib/netsuite/records/customer_refund.rb
@@ -4,8 +4,11 @@ class CustomerRefund
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::TranCust
+ actions :get, :initialize, :add
+
fields :address, :balance, :cc_approved, :cc_expire_date, :cc_name, :cc_number, :cc_street, :cc_zip_code, :charge_it,
:created_date, :currency_name, :debit_card_issue_no, :exchange_rate, :last_modified_date, :memo, :pn_ref_num, :status,
:to_be_printed, :tran_date, :tran_id, :valid_from
@@ -23,29 +26,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
- def self.initialize(object)
- response = Actions::Initialize.call(self, object)
- if response.success?
- new(response.body)
- else
- raise InitializationError, "#{self}.initialize with #{object} failed."
- end
- end
-
- def add
- response = Actions::Add.call(self)
- response.success?
- end
-
end
end
end
View
17 lib/netsuite/records/inventory_item.rb
@@ -4,8 +4,11 @@ class InventoryItem
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::ListAcct
+ actions :get, :add
+
fields :auto_lead_time, :auto_preferred_stock_level, :auto_reorder_point, :available_to_partners, :average_cost,
:copy_description, :cost, :cost_estimate, :cost_estimate_type, :cost_estimate_units, :cost_units, :costing_method,
:costing_method_display, :country_of_manufacture, :created_date, :currency, :date_converted_to_inv,
@@ -46,20 +49,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
- def add
- response = Actions::Add.call(self)
- response.success?
- end
-
end
end
end
View
26 lib/netsuite/records/invoice.rb
@@ -4,8 +4,11 @@ class Invoice
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::TranSales
+ actions :get, :initialize, :add
+
fields :alt_handling_cost, :alt_shipping_cost, :balance, :bill_address,
:billing_schedule, :contrib_pct, :created_date, :created_from, :currency_name, :custom_field_list,
:deferred_revenue, :department, :discount_amount, :discount_date, :discount_item, :discount_rate,
@@ -45,29 +48,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
- def self.initialize(object)
- response = Actions::Initialize.call(self, object)
- if response.success?
- new(response.body)
- else
- raise InitializationError, "#{self}.initialize with #{object} failed."
- end
- end
-
- def add
- response = Actions::Add.call(self)
- response.success?
- end
-
end
end
end
View
17 lib/netsuite/records/job.rb
@@ -4,8 +4,11 @@ class Job
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::ListRel
+ actions :get, :add
+
fields :account_number, :allocate_payroll_expenses, :allow_all_resources_for_tasks, :allow_expenses, :allow_time,
:alt_name, :alt_phone, :bill_pay, :calculated_end_date, :calculated_end_date_baseline, :comments, :company_name,
:date_created, :default_address, :email, :email_preference, :end_date, :entity_id, :estimated_cost,
@@ -32,20 +35,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
- def add
- response = Actions::Add.call(self)
- response.success?
- end
-
end
end
end
View
17 lib/netsuite/records/journal_entry.rb
@@ -4,8 +4,11 @@ class JournalEntry
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::TranGeneral
+ actions :get, :add
+
fields :approved, :created_date, :exchange_rate, :last_modified_date, :reversal_date, :reversal_defer, :reversal_entry,
:tran_date, :tran_id
@@ -19,20 +22,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
- def add
- response = Actions::Add.call(self)
- response.success?
- end
-
end
end
end
View
12 lib/netsuite/records/location.rb
@@ -3,6 +3,9 @@ module Records
class Location
include Support::Fields
include Support::RecordRefs
+ include Support::Actions
+
+ actions :get
fields :addr1, :addr2, :addr3, :addr_phone, :addr_text, :addressee, :attention, :city, :country, :include_children,
:is_inactive, :make_inventory_available, :make_inventory_available_store, :name, :override, :state, :tran_prefix, :zip
@@ -18,15 +21,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
end
end
end
View
12 lib/netsuite/records/non_inventory_sale_item.rb
@@ -4,8 +4,11 @@ class NonInventorySaleItem
include Support::Fields
include Support::RecordRefs
include Support::Records
+ include Support::Actions
include Namespaces::ListAcct
+ actions :get
+
fields :available_to_partners, :cost_estimate, :cost_estimate_type, :cost_estimate_units, :country_of_manufacture,
:created_date, :custom_field_list, :display_name, :dont_show_price, :enforce_min_qty_internally, :exclude_from_sitemap,
:featured_description, :handling_cost, :handling_cost_units, :include_children, :is_donation_item, :is_fulfillable,
@@ -36,15 +39,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
end
end
end
View
12 lib/netsuite/records/payment_method.rb
@@ -3,6 +3,9 @@ module Records
class PaymentMethod
include Support::Fields
include Support::RecordRefs
+ include Support::Actions
+
+ actions :get
fields :credit_card, :express_checkout_arrangement, :is_debit_card, :is_inactive, :is_online, :name,
:pay_pal_email_address, :undep_funds, :use_express_checkout
@@ -18,15 +21,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end
- def self.get(options = {})
- response = Actions::Get.call(self, options)
- if response.success?
- new(response.body)
- else
- raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
- end
- end
-
end
end
end
View
80 lib/netsuite/support/actions.rb
@@ -0,0 +1,80 @@
+module NetSuite
+ module Support
+ module Actions
+
+ def self.included(base)
+ base.send(:extend, ClassMethods)
+ end
+
+ module ClassMethods
+
+ def actions(*args)
+ instance_module = Module.new
+ class_module = Module.new
+ args.each do |action|
+ define_action(instance_module, class_module, action)
+ end
+ self.send(:include, instance_module)
+ self.send(:extend, class_module)
+ end
+
+ def define_action(instance_module, class_module, action)
+ case action
+ when :get
+ define_get(class_module)
+ when :add
+ define_add(instance_module)
+ when :initialize
+ define_initialize(class_module)
+ else
+ raise "Unknown action: #{action.inspect}"
+ end
+ end
+
+ def define_get(class_module)
+ class_module.module_eval do
+ define_method :get do |*args|
+ options, *ignored = *args
+ response = NetSuite::Actions::Get.call(self, options)
+ if response.success?
+ new(response.body)
+ else
+ raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
+ end
+ end
+ end
+ end
+
+ def define_add(instance_module)
+ instance_module.module_eval do
+ define_method :add do
+ response = NetSuite::Actions::Add.call(self)
+ response.success?
+ end
+ end
+ end
+
+ def define_initialize(class_module)
+ (class << self; self; end).instance_eval do
+ define_method :initialize do |*args|
+ super(*args)
+ end
+ end
+
+ class_module.module_eval do
+ define_method :initialize do |object|
+ response = NetSuite::Actions::Initialize.call(self, object)
+ if response.success?
+ new(response.body)
+ else
+ raise InitializationError, "#{self}.initialize with #{object} failed."
+ end
+ end
+ end
+ end
+
+ end
+
+ end
+ end
+end
View
5 spec/netsuite/support/actions_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe NetSuite::Support::Actions do
+ pending
+end
Please sign in to comment.
Something went wrong with that request. Please try again.