toolhound-ruby 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/toolhound-ruby.rb +12 -0
- data/lib/toolhound-ruby/authentication.rb +0 -4
- data/lib/toolhound-ruby/base.rb +268 -24
- data/lib/toolhound-ruby/client.rb +90 -1
- data/lib/toolhound-ruby/core_ext/string.rb +24 -12
- data/lib/toolhound-ruby/inventory.rb +81 -3
- data/lib/toolhound-ruby/project.rb +25 -2
- data/lib/toolhound-ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c0caeb8b12ac9170f28f99f65d227fbd17cffd3
|
4
|
+
data.tar.gz: ddde04f9f3fb97c0beeebe5b83250ca0f2300a79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce0815e9d2315fe05c9411e2c241f2a49f4f5e211c12bb2aa2a2dff6ef081d965ddfeb68ac12e33e17cab9ec88fd0ea4bb1387ff7f2cbd3978671b200ec2eb4d
|
7
|
+
data.tar.gz: 1f748ccb5c8bb16825528f708e5d26bf813da4f956780d0d530234533b531822a9055a7f2128fb94b990ecca5e8202379a3b5fd761a9cfc039e76020e9d6399f
|
data/lib/toolhound-ruby.rb
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
# require "nearmiss-ruby/raise_error"
|
8
8
|
# require "nearmiss-ruby/version"
|
9
9
|
require "tiny_tds"
|
10
|
+
require "toolhound-ruby/util"
|
11
|
+
|
10
12
|
require "toolhound-ruby/core_ext/string"
|
11
13
|
require "toolhound-ruby/configurable"
|
12
14
|
# require "nearmiss-ruby/response"
|
@@ -15,6 +17,16 @@ require "toolhound-ruby/default"
|
|
15
17
|
require "toolhound-ruby/base"
|
16
18
|
|
17
19
|
require "toolhound-ruby/project"
|
20
|
+
require "toolhound-ruby/inventory"
|
21
|
+
require "toolhound-ruby/inventory_item"
|
22
|
+
require "toolhound-ruby/rental"
|
23
|
+
require "toolhound-ruby/rental_item"
|
24
|
+
require "toolhound-ruby/rental_charge"
|
25
|
+
|
26
|
+
require "toolhound-ruby/vendor"
|
27
|
+
require "toolhound-ruby/manufacturer"
|
28
|
+
require "toolhound-ruby/purchase_order"
|
29
|
+
|
18
30
|
# require "nearmiss-ruby/util"
|
19
31
|
|
20
32
|
module Toolhound
|
data/lib/toolhound-ruby/base.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
module Toolhound
|
2
2
|
|
3
3
|
class Base
|
4
|
+
DB_TYPE_REGEX = /^(int|dec|var|bol|dte|bin)/
|
4
5
|
|
5
|
-
|
6
|
+
include Toolhound::Util
|
7
|
+
attr_accessor :connection
|
6
8
|
|
7
9
|
def self.table_name
|
8
|
-
@@table_name
|
10
|
+
@@table_name[self.name]
|
9
11
|
end
|
10
12
|
|
11
13
|
def self.primary_key
|
12
|
-
@@primary_key
|
14
|
+
@@primary_key[self.name]
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.table_name=(table_name)
|
16
|
-
@@table_name
|
18
|
+
@@table_name ||= {}
|
19
|
+
@@table_name[self.name] = table_name
|
17
20
|
end
|
18
21
|
|
19
22
|
def self.primary_key=(primary_key)
|
20
|
-
@@primary_key
|
23
|
+
@@primary_key ||= {}
|
24
|
+
@@primary_key[self.name] = primary_key
|
21
25
|
end
|
22
26
|
|
23
27
|
|
@@ -30,32 +34,265 @@ module Toolhound
|
|
30
34
|
@@rename_attributes ||= {}
|
31
35
|
end
|
32
36
|
|
33
|
-
def self.
|
34
|
-
|
35
|
-
|
37
|
+
# def self.connection
|
38
|
+
# @connection ||= Toolhound.connection
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
def initialize(connection, options = {})
|
42
|
+
@connection = connection
|
43
|
+
# @original = attrs
|
44
|
+
# self.attributes = transform_attributes(attrs)
|
45
|
+
end
|
46
|
+
def table_name
|
47
|
+
name = self.class.table_name || demodulize(self.class.name)
|
48
|
+
formatted_table_name(name)
|
49
|
+
end
|
50
|
+
def primary_key
|
51
|
+
id = self.class.primary_key || "int#{demodulize(self.class.name)}ID"
|
52
|
+
formmatted_column_name(id)
|
53
|
+
end
|
54
|
+
|
55
|
+
def locale
|
56
|
+
@locale ||= "EN-US"
|
57
|
+
end
|
58
|
+
|
59
|
+
def default_wheres
|
60
|
+
[]
|
61
|
+
end
|
62
|
+
|
63
|
+
def default_selects
|
64
|
+
{}
|
65
|
+
end
|
66
|
+
def default_joins
|
67
|
+
[]
|
68
|
+
end
|
69
|
+
|
70
|
+
def all(options = {})
|
71
|
+
options = merge_options({selects: default_selects, joins: default_joins, where: default_wheres}, options)
|
72
|
+
build_and_query options
|
73
|
+
end
|
74
|
+
|
75
|
+
def find(id, options = {})
|
76
|
+
# "tblInventory.bolIsActive = 1 AND tblInventory.bolDeleted = 0 AND tblInventory.intInventoryID = #{id}"
|
77
|
+
# wheres = [] + default_wheres
|
78
|
+
wheres = default_wheres + [{:"#{primary_key}" => id}]
|
79
|
+
options = merge_options({limit: 1, selects: default_selects, joins: default_joins, where: wheres}, options)
|
80
|
+
results = build_and_query options
|
36
81
|
results.first
|
37
82
|
end
|
38
83
|
|
39
|
-
def
|
40
|
-
|
84
|
+
def merge_options(defaults, options = {})
|
85
|
+
where = options.delete :where
|
86
|
+
selects = options.delete :selects
|
87
|
+
joins = options.delete :joins
|
88
|
+
defaults[:where] = (defaults[:where] || []) + (where || [])
|
89
|
+
defaults[:selects] = defaults[:selects].merge(selects || {})
|
90
|
+
defaults[:joins] = defaults[:joins] + (joins || [])
|
91
|
+
defaults.merge options
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
# def where(wheres, options = {})
|
96
|
+
#
|
97
|
+
# sql = build_sql(limit: 1, selects: default_selects, joins: default_joins, where: wheres)
|
98
|
+
#
|
99
|
+
# end
|
100
|
+
|
101
|
+
# def find(id)
|
102
|
+
# # table_includes = ""
|
103
|
+
# results = query "SELECT TOP(1) * FROM #{table_name} #{table_includes} WHERE #{primary_key} = #{id}"
|
104
|
+
# results.first
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# def all(options = {})
|
108
|
+
# results = query "SELECT * FROM #{table_name}"
|
109
|
+
# end
|
41
110
|
|
111
|
+
|
112
|
+
|
113
|
+
def formatted_table_name(table)
|
114
|
+
table = table.to_s
|
115
|
+
unless /^tbl/i =~ table
|
116
|
+
table = "tbl#{camelize(table, true)}"
|
117
|
+
end
|
118
|
+
camelize(table, false)
|
119
|
+
end
|
120
|
+
|
121
|
+
def formmatted_column_name(column)
|
122
|
+
column = column.to_s
|
123
|
+
camelize(column, false)
|
124
|
+
end
|
125
|
+
|
126
|
+
def build_selects(selects)
|
127
|
+
_build_selects(selects).join(", ")
|
42
128
|
end
|
43
129
|
|
44
|
-
def
|
45
|
-
|
130
|
+
def _build_selects(selects)
|
131
|
+
arr = []
|
132
|
+
aggs = {
|
133
|
+
count: "COUNT",
|
134
|
+
max: "MAX",
|
135
|
+
min: "MIN",
|
136
|
+
average: "AVERAGE"
|
137
|
+
}
|
138
|
+
selects.each do |table, values|
|
139
|
+
|
140
|
+
values.each do |v|
|
141
|
+
if v.is_a? Hash
|
142
|
+
|
143
|
+
end
|
144
|
+
# select = "#{formatted_table_name(table)}."
|
145
|
+
if v.is_a? Hash
|
146
|
+
select = "#{formatted_table_name(table)}.#{formmatted_column_name(v.first[0])}"
|
147
|
+
options = v.first[1]
|
148
|
+
if options.is_a? Hash
|
149
|
+
if options[:agg]
|
150
|
+
select = "#{aggs[options[:agg]]}(#{select})"
|
151
|
+
end
|
152
|
+
if options[:as]
|
153
|
+
select += " AS #{formmatted_column_name(options[:as])}"
|
154
|
+
end
|
155
|
+
else
|
156
|
+
select += " AS #{formmatted_column_name(options)}"
|
157
|
+
end
|
158
|
+
#
|
159
|
+
else
|
160
|
+
select = "#{formatted_table_name(table)}.#{formmatted_column_name(v)}"
|
161
|
+
end
|
162
|
+
arr << select
|
163
|
+
end
|
164
|
+
end
|
165
|
+
arr
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
def build_joins(joins)
|
170
|
+
_build_joins(joins).join(" ")
|
171
|
+
end
|
172
|
+
|
173
|
+
def _build_joins(joins)
|
174
|
+
join_types = {
|
175
|
+
inner: "INNER JOIN",
|
176
|
+
left: "LEFT OUTER JOIN",
|
177
|
+
left_outer: "LEFT OUTER JOIN",
|
178
|
+
left_inner: "LEFT INNER JOIN",
|
179
|
+
right: "RIGHT OUTER JOIN",
|
180
|
+
right_outer: "RIGHT OUTER JOIN",
|
181
|
+
right_inner: "RIGHT INNER JOIN",
|
182
|
+
}
|
183
|
+
|
184
|
+
# joins_query = joins.map do |join|
|
185
|
+
# type = join_types[join[:type] || :inner]
|
186
|
+
# table = formatted_table_name(join[:table])
|
187
|
+
# on = join[:on]
|
188
|
+
#
|
189
|
+
# on_str = on ? "ON #{on}" : ""
|
190
|
+
# "#{type} #{table} #{on_str}"
|
191
|
+
# end
|
192
|
+
# joins_query.join(" ")
|
193
|
+
joins
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
def build_where(wheres)
|
198
|
+
arr = _build_where(wheres)
|
199
|
+
arr.join(" AND ")
|
200
|
+
end
|
201
|
+
|
202
|
+
def _build_where(wheres)
|
203
|
+
arr = []
|
204
|
+
case wheres.class.to_s
|
205
|
+
when "String"
|
206
|
+
return wheres
|
207
|
+
when "Hash"
|
208
|
+
wheres.each do |k, v|
|
209
|
+
table, column = formatted_table_and_column(k)
|
210
|
+
op = :eq
|
211
|
+
if v.is_a? Hash
|
212
|
+
op = v.delete :op
|
213
|
+
v = v.delete :value
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
arr << "#{table}.#{column} #{get_operator(op, v)}"
|
218
|
+
# if v.is_a? Hash
|
219
|
+
# # key, value = v.first
|
220
|
+
# # op
|
221
|
+
# # arr <<
|
222
|
+
# v.each do |k1, v1|
|
223
|
+
# arr << "#{formatted_table_name(k)}.#{formmatted_column_name(k1)} = '#{v1}'"
|
224
|
+
# end
|
225
|
+
# else
|
226
|
+
# arr << "#{formatted_table_name(table_name)}.#{formmatted_column_name(k)} = '#{v}'"
|
227
|
+
# end
|
228
|
+
end
|
229
|
+
when "Array"
|
230
|
+
wheres.each do |v|
|
231
|
+
arr += _build_where(v)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
arr
|
235
|
+
end
|
236
|
+
|
237
|
+
def get_operator(op, value)
|
238
|
+
operators = {eq: "=", gt: ">", gte: ">=", lt: "<", lte: "<=", ne: "!=", in: "IN", nin: "NOT IN", like: "LIKE", between: "BETWEEN"}
|
239
|
+
ops = operators.values
|
240
|
+
operator = operators[op]
|
241
|
+
unless operator
|
242
|
+
operator = ops.include?(op) ? op : "="
|
243
|
+
end
|
244
|
+
|
245
|
+
if operator == "IN" || operator == "NOT IN"
|
246
|
+
value = "(#{value})"
|
247
|
+
elsif operator == "BETWEEN"
|
248
|
+
value = "'#{value[0]}' AND '#{value[1]}'"
|
249
|
+
else
|
250
|
+
value = "'#{value}'"
|
251
|
+
end
|
252
|
+
"#{operator} #{value}"
|
253
|
+
end
|
254
|
+
|
255
|
+
def formatted_table_and_column(key)
|
256
|
+
key = key.to_s
|
257
|
+
first, second = key.split(".")
|
258
|
+
if first && second
|
259
|
+
[formatted_table_name(first), formmatted_column_name(second)]
|
260
|
+
elsif(first)
|
261
|
+
[table_name, formmatted_column_name(first)]
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
def query(query, options)
|
267
|
+
data = []
|
46
268
|
results = connection.execute(query)
|
47
|
-
results.
|
48
|
-
|
269
|
+
results.each(:cache_rows => false) do |row|
|
270
|
+
data << transform_attributes(row)
|
49
271
|
end
|
272
|
+
data
|
50
273
|
end
|
51
274
|
|
52
|
-
def
|
53
|
-
|
275
|
+
def build_and_query(options, query_options = {})
|
276
|
+
sql = build_sql(options)
|
277
|
+
results = query(sql, query_options)
|
54
278
|
end
|
55
279
|
|
56
|
-
|
57
|
-
|
58
|
-
|
280
|
+
|
281
|
+
def build_sql(obj)
|
282
|
+
limit = obj[:limit]
|
283
|
+
selects = obj[:selects] ? build_selects(obj[:selects]) : "*"
|
284
|
+
joins = obj[:joins] ? build_joins(obj[:joins]) : ""
|
285
|
+
from = obj[:from] ? formatted_table_name(obj[:from]) : table_name
|
286
|
+
where = obj[:where] ? build_where(obj[:where]) : nil
|
287
|
+
order = obj[:order]
|
288
|
+
|
289
|
+
limit_str = limit ? "TOP(#{limit})" : ""
|
290
|
+
where_str = where.length > 0 ? "WHERE #{where}" : ""
|
291
|
+
order_str = order ? "ORDER BY #{order}" : ""
|
292
|
+
|
293
|
+
sql = "SELECT #{limit_str} #{selects} FROM #{from} #{joins} #{where_str} #{order_str}"
|
294
|
+
puts sql
|
295
|
+
sql
|
59
296
|
end
|
60
297
|
|
61
298
|
# def attributes=(hash)
|
@@ -71,7 +308,11 @@ module Toolhound
|
|
71
308
|
hash = {}
|
72
309
|
attrs.each do |k, v|
|
73
310
|
key = transform_attribute_key(k)
|
74
|
-
hash
|
311
|
+
if hash.include? key
|
312
|
+
hash[:"#{key}1"] = v
|
313
|
+
else
|
314
|
+
hash[key] = v
|
315
|
+
end
|
75
316
|
end
|
76
317
|
hash
|
77
318
|
end
|
@@ -80,13 +321,16 @@ module Toolhound
|
|
80
321
|
renamed = self.class.renamed_attributes
|
81
322
|
if renamed.include? key
|
82
323
|
renamed[key].to_sym
|
83
|
-
elsif key == self.class.primary_key
|
84
|
-
:id
|
85
324
|
else
|
86
325
|
# "varTransferReceiptPrefix"
|
87
|
-
|
88
|
-
|
326
|
+
if DB_TYPE_REGEX =~ key
|
327
|
+
word = key[3..key.length]
|
328
|
+
underscore(word).to_sym
|
329
|
+
else
|
330
|
+
underscore(key).to_sym
|
331
|
+
end
|
89
332
|
end
|
333
|
+
|
90
334
|
end
|
91
335
|
|
92
336
|
end
|
@@ -10,7 +10,7 @@ module Toolhound
|
|
10
10
|
class Client
|
11
11
|
include Toolhound::Authentication
|
12
12
|
include Toolhound::Configurable
|
13
|
-
|
13
|
+
include Toolhound::Util
|
14
14
|
include Toolhound::Client::Projects
|
15
15
|
# include Toolhound::Client::Bookmarks
|
16
16
|
# include Toolhound::Client::Categories
|
@@ -74,6 +74,7 @@ module Toolhound
|
|
74
74
|
end
|
75
75
|
|
76
76
|
|
77
|
+
|
77
78
|
# Set username for authentication
|
78
79
|
#
|
79
80
|
# @param value [String] Toolhound-field username
|
@@ -94,6 +95,94 @@ module Toolhound
|
|
94
95
|
@connection = nil
|
95
96
|
end
|
96
97
|
|
98
|
+
def inventory
|
99
|
+
@inventory ||= Toolhound::Inventory.new(connection)
|
100
|
+
end
|
101
|
+
|
102
|
+
def inventory_item
|
103
|
+
@inventory_item ||= Toolhound::InventoryItem.new(connection)
|
104
|
+
end
|
105
|
+
|
106
|
+
def project
|
107
|
+
@project ||= Toolhound::Project.new(connection)
|
108
|
+
end
|
109
|
+
|
110
|
+
def rental
|
111
|
+
@rental ||= Toolhound::Rental.new(connection)
|
112
|
+
end
|
113
|
+
|
114
|
+
def rental_item
|
115
|
+
@rental_item ||= Toolhound::RentalItem.new(connection)
|
116
|
+
end
|
117
|
+
def rental_charge
|
118
|
+
@rental_charge ||= Toolhound::RentalCharge.new(connection)
|
119
|
+
end
|
120
|
+
|
121
|
+
def vendor
|
122
|
+
@vendor ||= Toolhound::Vendor.new(connection)
|
123
|
+
end
|
124
|
+
def manufacturer
|
125
|
+
@vendor ||= Toolhound::Manufacturer.new(connection)
|
126
|
+
end
|
127
|
+
def purchase_order
|
128
|
+
@vendor ||= Toolhound::PurchaseOrder.new(connection)
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
def query(query, options = {})
|
134
|
+
klass = self
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
results = connection.execute(query)
|
139
|
+
results.map do |row|
|
140
|
+
transform_attributes(row)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def transform_attributes(attrs)
|
145
|
+
hash = {}
|
146
|
+
attrs.each do |k, v|
|
147
|
+
key = transform_attribute_key(k)
|
148
|
+
if hash.include? key
|
149
|
+
hash[:"#{key}1"] = v
|
150
|
+
else
|
151
|
+
hash[key] = v
|
152
|
+
end
|
153
|
+
end
|
154
|
+
hash
|
155
|
+
end
|
156
|
+
|
157
|
+
DB_TYPE_REGEX = /^(int|dec|var|bol|dte|bin)/
|
158
|
+
|
159
|
+
#"SELECT column_name, data_type FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tblRentalCharge' AND TABLE_SCHEMA='dbo'"
|
160
|
+
|
161
|
+
# "SELECT * FROM information_schema.tables ORDER BY table_name"
|
162
|
+
#
|
163
|
+
# Find project from job number
|
164
|
+
# "SELECT tblEntity.intEntityID, tblEntity.varEntityID AS job_no, tblLocation.intLocationID, tblLocationText.varLocationName FROM tblEntity INNER JOIN tblLocation ON tblLocation.intEntityID = tblEntity.intEntityID INNER JOIN tblLocationText ON tblLocationText.intLocationID = tblLocation.intLocationID WHERE varEntityID LIKE '%10526.00%' "
|
165
|
+
|
166
|
+
# "SELECT MAX(dteStartDate) AS max_date, MIN(dteStartDate) AS min_date FROM tblRentalCharge WHERE intEntityID = 100044"
|
167
|
+
#
|
168
|
+
def transform_attribute_key(key)
|
169
|
+
# renamed = self.class.renamed_attributes
|
170
|
+
# if renamed.include? key
|
171
|
+
# renamed[key].to_sym
|
172
|
+
# elsif key == self.class.primary_key
|
173
|
+
# :id
|
174
|
+
# else
|
175
|
+
# # "varTransferReceiptPrefix"
|
176
|
+
# word = key[3..key.length]
|
177
|
+
# word.underscore.to_sym
|
178
|
+
# end
|
179
|
+
word = key
|
180
|
+
if DB_TYPE_REGEX =~ key
|
181
|
+
word = key[3..key.length]
|
182
|
+
end
|
183
|
+
underscore(word).to_sym
|
184
|
+
end
|
185
|
+
|
97
186
|
|
98
187
|
# Wrapper around Kernel#warn to print warnings unless
|
99
188
|
# TOOLHOUND_SILENT is set to true.
|
@@ -1,16 +1,28 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
def underscore()
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
3
|
+
# def underscore()
|
4
|
+
# camel_cased_word = self
|
5
|
+
# acronym_regex = /#{["REST"].join("|")}/
|
6
|
+
# return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
|
7
|
+
# word = camel_cased_word.to_s.gsub('::'.freeze, '/'.freeze)
|
8
|
+
# word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'.freeze }#{$2.downcase}" }
|
9
|
+
# word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
|
10
|
+
# word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
|
11
|
+
# word.tr!("-".freeze, "_".freeze)
|
12
|
+
# word.downcase!
|
13
|
+
# word
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def camelize(term, uppercase_first_letter = true)
|
17
|
+
# string = term.to_s
|
18
|
+
# if uppercase_first_letter
|
19
|
+
# string = string.sub(/^[a-z\d]*/) { |match| inflections.acronyms[match] || match.capitalize }
|
20
|
+
# else
|
21
|
+
# string = string.sub(/^(?:#{inflections.acronym_regex}(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
|
22
|
+
# end
|
23
|
+
# string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }
|
24
|
+
# string.gsub!('/'.freeze, '::'.freeze)
|
25
|
+
# string
|
26
|
+
# end
|
15
27
|
|
16
28
|
end
|
@@ -8,12 +8,90 @@ module Toolhound
|
|
8
8
|
class Inventory < Base
|
9
9
|
# attr_accessor :owner, :name, :id
|
10
10
|
|
11
|
-
self.table_name = "tblInventory"
|
12
|
-
self.primary_key = "intInventoryID"
|
11
|
+
# self.table_name = "tblInventory"
|
12
|
+
# self.primary_key = "intInventoryID"
|
13
|
+
|
14
|
+
|
15
|
+
def default_selects
|
16
|
+
selects = {
|
17
|
+
inventory: ["intInventoryID", "intCategoryID", "intSubCategoryID", "intManufacturerID", "intVendorID", "dteCreatedDate", "dteModifiedDate"],
|
18
|
+
inventory_text: ["varPartNo", "varDescription", "txtNotes", {varUserField1: "varGlRevenue"}, {varUserField2: "varGlCOGSCode"}, {varUserField3: "varPhaseCode"}],
|
19
|
+
unit_of_measure_text: ["varUnitOfMeasure"],
|
20
|
+
category: ["varCategory"],
|
21
|
+
sub_category: ["varCategory"]
|
22
|
+
}
|
23
|
+
end
|
24
|
+
def default_joins
|
25
|
+
arr = []
|
26
|
+
arr << "INNER JOIN tblInventoryType ON tblInventory.intInventoryTypeID = tblInventoryType.intInventoryTypeID"
|
27
|
+
arr << "INNER JOIN tblInventoryText ON (tblInventoryText.intInventoryID = tblInventory.intInventoryID AND tblInventoryText.varLocaleID = '#{locale}')"
|
28
|
+
arr << "LEFT OUTER JOIN tblUnitOfMeasureText ON (tblUnitOfMeasureText.intUofMID = tblInventory.intUofMID )"
|
29
|
+
arr << "LEFT OUTER JOIN tblCategoryText AS tblCategory ON (tblCategory.intCategoryID = tblInventory.intCategoryID AND tblCategory.varLocaleID = '#{locale}')"
|
30
|
+
arr << "LEFT OUTER JOIN tblCategoryText AS tblSubCategory ON (tblSubCategory.intCategoryID = tblInventory.intSubCategoryID AND tblSubCategory.varLocaleID = '#{locale}')"
|
31
|
+
end
|
32
|
+
|
33
|
+
def default_wheres
|
34
|
+
[{bolIsActive: 1}, {bolDeleted: 0}]
|
35
|
+
end
|
36
|
+
# include_selects tblInventoryText: [:varPartNo, :varDescription, :txtNotes ],
|
37
|
+
# tblInventory: [:intInventoryID, :intCategoryID]
|
38
|
+
# def selects
|
39
|
+
# arr = build_selects(selects)
|
40
|
+
#
|
41
|
+
# arr.join(", ")
|
42
|
+
# end
|
43
|
+
|
44
|
+
|
45
|
+
# def joins
|
46
|
+
# # LEFT OUTER JOIN tblInventoryID ON tblInventoryID.intInventoryID = tblInventory.intInventoryID
|
47
|
+
# [
|
48
|
+
# {type: :inner, table: :inventory_type, on: "intInventoryTypeID"},
|
49
|
+
# {type: :inner, table: :inventory_text, on: ["intInventoryTypeID", varLocaleID: locale]},
|
50
|
+
# {type: :left_outer, table: :unit_of_measure_text, on: "intUofMID"},
|
51
|
+
# {type: :left_outer, table: :category_text, on: ["intUofMID", varLocaleID: locale], as: :category},
|
52
|
+
#
|
53
|
+
# ]
|
54
|
+
# arr.join(" ")
|
55
|
+
# end
|
56
|
+
|
57
|
+
def build_join(join)
|
58
|
+
join_types = {
|
59
|
+
inner: "INNER JOIN",
|
60
|
+
left: "LEFT OUTER JOIN",
|
61
|
+
left_outer: "LEFT OUTER JOIN",
|
62
|
+
left_inner: "LEFT INNER JOIN",
|
63
|
+
right: "RIGHT OUTER JOIN",
|
64
|
+
right_outer: "RIGHT OUTER JOIN",
|
65
|
+
right_inner: "RIGHT INNER JOIN",
|
66
|
+
}
|
67
|
+
|
68
|
+
type = join_types[join[:type] || :inner]
|
69
|
+
table = formatted_table_name(join[:table])
|
70
|
+
|
71
|
+
table_str = "#{table} "
|
72
|
+
if join[:as]
|
73
|
+
table = formatted_table_name(join[:as])
|
74
|
+
table_str += "AS #{table} "
|
75
|
+
end
|
76
|
+
|
77
|
+
on = join[:on]
|
78
|
+
case on.class.to_s
|
79
|
+
when "String"
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
# on_str = on ? "ON #{on}" : ""
|
84
|
+
"#{type} #{table_str} #{on_str}"
|
85
|
+
|
86
|
+
|
87
|
+
end
|
13
88
|
|
14
89
|
# includes :tblInventoryText,
|
15
90
|
# rename_attributes intLocationID: 'location_id'
|
16
91
|
|
17
|
-
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
18
96
|
end
|
19
97
|
end
|
@@ -8,10 +8,33 @@ module Toolhound
|
|
8
8
|
self.table_name = "tblLocation"
|
9
9
|
self.primary_key = "intLocationID"
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
def default_selects
|
12
|
+
#{ }"SELECT tblEntity.intEntityID, tblEntity.varEntityID AS job_no, tblLocation.intLocationID, tblLocationText.varLocationName FROM tblEntity INNER JOIN tblLocation ON tblLocation.intEntityID = tblEntity.intEntityID INNER JOIN tblLocationText ON tblLocationText.intLocationID = tblLocation.intLocationID WHERE varEntityID LIKE '%10526.00%'"
|
13
|
+
{
|
14
|
+
location: [:int_location_id, :dte_created_date, :dte_modified_date],
|
15
|
+
location_text: [:var_location_name],
|
16
|
+
entity: [:int_entity_id, var_entity_id: :job_no ]
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_joins
|
21
|
+
arr = []
|
22
|
+
arr << "INNER JOIN tblEntity ON (tblEntity.intEntityID = tblLocation.intEntityID)"
|
23
|
+
arr << "INNER JOIN tblLocationText ON (tblLocationText.intLocationID = tblLocation.intLocationID)"
|
24
|
+
|
25
|
+
arr
|
26
|
+
end
|
13
27
|
|
28
|
+
def find_by_entity_id(id)
|
29
|
+
all(limit: 1, where: [{int_entity_id: id}]).first
|
14
30
|
end
|
15
31
|
|
32
|
+
def find_by_job_no(job_no)
|
33
|
+
all(limit: 1, where: [{"entity.var_entity_id" => {value: "%#{job_no}%", op: :like} }]).first
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
# rename_attributes intLocationID: 'location_id'
|
38
|
+
|
16
39
|
end
|
17
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toolhound-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Klooth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tiny_tds
|