Class: Service::Record

Inherits:
Object
  • Object
show all
Extended by:
Finder
Includes:
Errors, Persistence
Defined in:
lib/service/record.rb

Overview

Base class use to map QuickBook record with Ruby instance QuickBook API documentation developer.intuit.com/v2/apiexplorer?apiname=V3QBO

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Finder

extended, find, find_all, find_or_initialize

Methods included from Persistence

#destroy, included, #save!

Constructor Details

#initialize(attributes = {}) ⇒ Record

Returns a new instance of Record.



26
27
28
29
# File 'lib/service/record.rb', line 26

def initialize(attributes = {})
  self.is_new_record = true
  self.attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



49
50
51
52
53
54
55
56
57
58
# File 'lib/service/record.rb', line 49

def method_missing(method_sym, *args, &block)
  attribute = method_sym.to_s
  if (args.length == 1 and method_sym.to_s[-1, 1] == "=")
    self[attribute[(0..method_sym.length - 2)].to_s] = args[0]
  elsif (self.attributes.keys.index(attribute))
    return self[attribute]
  else
    super
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



11
12
13
# File 'lib/service/record.rb', line 11

def attributes
  @attributes
end

#is_new_recordObject

Returns the value of attribute is_new_record.



11
12
13
# File 'lib/service/record.rb', line 11

def is_new_record
  @is_new_record
end

Class Method Details

.quickbook_gatewayObject



18
19
20
# File 'lib/service/record.rb', line 18

def self.quickbook_gateway
  return @@quickbook_gateway
end

.quickbook_gateway=(gateway) ⇒ Object

Set instance of Gateway::QuickBook



14
15
16
# File 'lib/service/record.rb', line 14

def self.quickbook_gateway=(gateway)
  @@quickbook_gateway = gateway
end

Instance Method Details

#[](key) ⇒ Object



41
42
43
# File 'lib/service/record.rb', line 41

def [](key)
  return self.attributes[key.to_s]
end

#[]=(key, value) ⇒ Object



45
46
47
# File 'lib/service/record.rb', line 45

def []=(key, value)
  self.attributes[key.to_s] = value
end

#quickbook_gatewayObject



22
23
24
# File 'lib/service/record.rb', line 22

def quickbook_gateway
  return @@quickbook_gateway
end