quickbooks_api 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ class Quickbooks::API
4
4
  include Quickbooks::Support::QBXML
5
5
 
6
6
  attr_reader :dtd_parser, :qbxml_parser, :schema_type
7
+ @@instances = {}
7
8
 
8
9
  def initialize(schema_type = nil, opts = {})
9
10
  @schema_type = schema_type
@@ -18,9 +19,12 @@ def initialize(schema_type = nil, opts = {})
18
19
  @qbxml_parser = QbxmlParser.new(schema_type)
19
20
 
20
21
  load_qb_classes(use_disk_cache)
22
+ @@instances[schema_type] = self
23
+ end
21
24
 
22
- # load the container class template into memory (significantly speeds up wrapping of partial data hashes)
23
- get_container_class.template(true, use_disk_cache)
25
+ # returns the last created api instance
26
+ def self.[](schema_type)
27
+ @@instances[schema_type] || self.new(schema_type)
24
28
  end
25
29
 
26
30
  def container
@@ -31,6 +35,16 @@ def qbxml_classes
31
35
  cached_classes
32
36
  end
33
37
 
38
+ def find(class_name)
39
+ class_name = class_name.to_s
40
+ cached_classes.find { |c| to_attribute_name(c) == class_name }
41
+ end
42
+
43
+ def grep(keyword)
44
+ keyword = keyword.to_s
45
+ cached_classes.select { |c| to_attribute_name(c).include?(keyword) }
46
+ end
47
+
34
48
  # QBXML 2 RUBY
35
49
 
36
50
  def qbxml_to_obj(qbxml)
@@ -66,7 +80,7 @@ def hash_to_obj(data)
66
80
  end
67
81
 
68
82
  def hash_to_qbxml(data)
69
- hash_to_obj(data).to_qbxml.to_s
83
+ hash_to_obj(data).to_qbxml
70
84
  end
71
85
 
72
86
  # Disk Cache
@@ -94,6 +108,10 @@ def load_qb_classes(use_disk_cache = false)
94
108
  else
95
109
  rebuild_schema_cache(false, false)
96
110
  end
111
+
112
+ # load the container class template into memory (significantly speeds up wrapping of partial data hashes)
113
+ get_container_class.template(true, use_disk_cache, use_disk_cache)
114
+ true
97
115
  end
98
116
 
99
117
  # rebuilds schema cache in memory and writes to disk if desired
@@ -113,8 +131,6 @@ def dump_cached_classes
113
131
  end
114
132
  end
115
133
 
116
- # class methods
117
-
118
134
  def self.log
119
135
  @@log ||= Logger.new(STDOUT, DEFAULT_LOG_LEVEL)
120
136
  end
@@ -77,13 +77,13 @@ def to_qbxml
77
77
 
78
78
  log.debug "to_qbxml#xml_nodes_size: #{xml_nodes.size}"
79
79
  root.children = xml_nodes.join('')
80
- root
80
+ root.to_s
81
81
  end
82
82
 
83
83
 
84
- def self.template(recursive = false, use_disk_cache = false)
84
+ def self.template(recursive = false, use_disk_cache = false, reload = false)
85
85
  if recursive
86
- @template ||= load_template(true, use_disk_cache)
86
+ @template = (!reload && @template) || load_template(true, use_disk_cache)
87
87
  else build_template(false)
88
88
  end
89
89
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quickbooks_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Skryl
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-07 00:00:00 -05:00
18
+ date: 2011-06-15 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency