wolas_channel 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/wolas_channel/version.rb +1 -1
- data/lib/wolas_channel.rb +260 -84
- metadata +2 -3
- data/wolas_channel-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55de7197e5d2e624f3972aef8e06e325a6357348
|
4
|
+
data.tar.gz: de983cb3a62ea09cb43665e0c2db6223b4f6bd50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afc89a3a1262dbd2716b27124c4ad9217255a14131cbdbc7f69750076bbc139199af2c9057a6ec75a9f5103858cf4a293cd90e12ad66269770413da97d9ae29e
|
7
|
+
data.tar.gz: 938e14b4bc6f7920a12c7e47ecd2ce4947e483c89b67d2255c3daf1e077be4d788d260ee6fa07a1a4fa88f40247f1d8a7b2182275b00aac6444f96b8ab421b1f
|
data/lib/wolas_channel.rb
CHANGED
@@ -8,6 +8,11 @@ module ErrorHandling
|
|
8
8
|
# This error is raised when a tenant requests a channel that does not belong
|
9
9
|
# to their tenant id
|
10
10
|
class PermissionFailure < StandardError; end
|
11
|
+
# This error is thrown when an insert request is made on an object without an
|
12
|
+
# identifiable body field
|
13
|
+
class InvalidObject < StandardError; end
|
14
|
+
# This error is thrown when attempting to access a channel that doesn't exist
|
15
|
+
class InvalidChannel < StandardError; end
|
11
16
|
end
|
12
17
|
|
13
18
|
# This class handles mapping the channel items from and to the database
|
@@ -26,13 +31,14 @@ class WolasChannel
|
|
26
31
|
begin
|
27
32
|
# Connect to the database
|
28
33
|
connect = Connection.new.open(@database, @host, @user, @pw)
|
29
|
-
# Generate a UUID for the new channel
|
30
|
-
channel_id = SecureRandom.uuid
|
31
34
|
|
32
|
-
insert = "INSERT INTO `channel`.`channels` (`
|
35
|
+
insert = "INSERT INTO `channel`.`channels` (`tenant_id`, `type`) VALUES (?, ?)"
|
33
36
|
# This method performs the insert. Mysql2 does not return an object on a successful
|
34
37
|
# insert
|
35
|
-
prepare_exe(connect, insert,
|
38
|
+
prepare_exe(connect, insert, @tenant_id, type)
|
39
|
+
|
40
|
+
# Return the last id from mysql2 object
|
41
|
+
channel_id = connect.last_id
|
36
42
|
|
37
43
|
return { channel_created: channel_id, channel_type: type }
|
38
44
|
ensure
|
@@ -50,11 +56,10 @@ class WolasChannel
|
|
50
56
|
# Determine if the tenant is able to view this entity based off the
|
51
57
|
# channel and return the type of the entity
|
52
58
|
check = tenant_entity(entity_id)
|
53
|
-
type = check[0]
|
54
59
|
return nil if check == [nil, nil]
|
55
60
|
|
56
61
|
# Now the entity is requested
|
57
|
-
entity = entity_construct(entity_id
|
62
|
+
entity = entity_construct(entity_id)
|
58
63
|
return entity
|
59
64
|
ensure
|
60
65
|
@connect.close
|
@@ -74,46 +79,203 @@ class WolasChannel
|
|
74
79
|
return nil if type == nil
|
75
80
|
|
76
81
|
# Now the entities are requested
|
77
|
-
ent_q = "SELECT
|
82
|
+
ent_q = "SELECT `entities`.`entity_id`, `entities`.`body`, `entities`.`created`, `entities`.`type` FROM `channel`.`entities` \
|
83
|
+
INNER JOIN `channel`.`channel_entities` on `entities`.`entity_id` = `channel_entities`.`entity_id` \
|
84
|
+
INNER JOIN `channel`.`channels` on `channel_entities`.`channel_id` = `channels`.`channel_id` \
|
85
|
+
WHERE `channels`.`channel_id` = ?"
|
78
86
|
ent = prepare_exe(@connect, ent_q, channel_id)
|
79
87
|
|
80
|
-
#
|
88
|
+
# And their metadata
|
89
|
+
data_q = "SELECT `data`.`entity_id`, `data`.`key`, `data`.`value` FROM `channel`.`data` \
|
90
|
+
INNER JOIN `channel`.`channel_entities` on `data`.`entity_id` = `channel_entities`.`entity_id` \
|
91
|
+
INNER JOIN `channel`.`channels` on `channel_entities`.`channel_id` = `channels`.`channel_id` \
|
92
|
+
WHERE `channels`.`channel_id` = ?"
|
93
|
+
data = prepare_exe(@connect, data_q, channel_id)
|
94
|
+
# Return nil if nothing is returned from the select from the entities table
|
81
95
|
return nil if ent.count == 0
|
82
96
|
|
83
97
|
# Construct the object requested using the generic method
|
84
|
-
entitys = object_constructor(ent)
|
98
|
+
entitys = object_constructor(ent, data)
|
99
|
+
|
100
|
+
return entitys
|
101
|
+
ensure
|
102
|
+
@connect.close
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# This method returns the 20 most recent entries for a channel
|
107
|
+
def get_channel_recent(channel_id)
|
108
|
+
begin
|
109
|
+
# Connect to the database. Instance variable used to pass connection to
|
110
|
+
# private methods
|
111
|
+
@connect = Connection.new.open(@database, @host, @user, @pw)
|
112
|
+
# Determine if this channel is valid for the tenant and returns its type
|
113
|
+
type = tenant_channel(channel_id)
|
114
|
+
return nil if type == nil
|
115
|
+
|
116
|
+
# Now the 20 most recent entities are requested
|
117
|
+
ent_q = "SELECT `entities`.`entity_id`, `entities`.`body`, `entities`.`created`, `entities`.`type` FROM `channel`.`entities` \
|
118
|
+
INNER JOIN `channel`.`channel_entities` on `entities`.`entity_id` = `channel_entities`.`entity_id` \
|
119
|
+
INNER JOIN `channel`.`channels` on `channel_entities`.`channel_id` = `channels`.`channel_id` \
|
120
|
+
WHERE `channels`.`channel_id` = ? \
|
121
|
+
ORDER BY `entities`.`created` DESC LIMIT 20"
|
122
|
+
ent = prepare_exe(@connect, ent_q, channel_id)
|
123
|
+
|
124
|
+
# All meta data is selected for the channel as the entity_ids are unknown.
|
125
|
+
# However any data that does not match an entity id from the query above will
|
126
|
+
# not be inserted anywhere.
|
127
|
+
data_q = "SELECT `data`.`entity_id`, `data`.`key`, `data`.`value` FROM `channel`.`data` \
|
128
|
+
INNER JOIN `channel`.`channel_entities` on `data`.`entity_id` = `channel_entities`.`entity_id` \
|
129
|
+
INNER JOIN `channel`.`channels` on `channel_entities`.`channel_id` = `channels`.`channel_id` \
|
130
|
+
WHERE `channels`.`channel_id` = ?"
|
131
|
+
data = prepare_exe(@connect, data_q, channel_id)
|
132
|
+
# Return nil if nothing is returned from the select from the entities table
|
133
|
+
return nil if ent.count == 0
|
134
|
+
|
135
|
+
# Construct the object requested using the generic method
|
136
|
+
entitys = object_constructor(ent, data)
|
137
|
+
|
138
|
+
return entitys
|
139
|
+
ensure
|
140
|
+
@connect.close
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# This method allows an entity to be received by a channel and key/value match
|
145
|
+
def get_channel_kv(channel_id, *kv)
|
146
|
+
begin
|
147
|
+
# Connect to the database. Instance variable used to pass the connection to
|
148
|
+
# private methods
|
149
|
+
@connect = Connection.new.open(@database, @host, @user, @pw)
|
150
|
+
# Determine if the tenant is able to view this entity based off the
|
151
|
+
# channel and return the type of the entity
|
152
|
+
type = tenant_channel(channel_id)
|
153
|
+
return nil if type == nil
|
154
|
+
return nil if kv.length == 0
|
155
|
+
byebug
|
156
|
+
|
157
|
+
# This count determines the number of key / value matches that exist per
|
158
|
+
# entity. If the number of matches equals the number of kvs passed to the
|
159
|
+
# method, then the search criteria is met and the entity is returned.
|
160
|
+
match_q = "SELECT `entities`.`entity_id`, count(*) AS `matches` FROM `channel`.`entities` \
|
161
|
+
INNER JOIN `channel`.`data` ON `entities`.`entity_id` = `data`.`entity_id` \
|
162
|
+
INNER JOIN `channel`.`channel_entities` ON `data`.`entity_id` = `channel_entities`.`entity_id` \
|
163
|
+
INNER JOIN `channel`.`channels` ON `channel_entities`.`channel_id` = `channels`.`channel_id` \
|
164
|
+
WHERE `channels`.`channel_id` = ? AND ("
|
165
|
+
kv_arr = []
|
166
|
+
kv.each_with_index do |hash, index|
|
167
|
+
if index != kv.length - 1
|
168
|
+
match_q = match_q + "(`data`.`key` = ? AND `data`.`value` = ?) OR "
|
169
|
+
else
|
170
|
+
match_q = match_q + "(`data`.`key` = ? AND `data`.`value` = ?))"
|
171
|
+
end
|
172
|
+
# Push the key followed by the value into the array to match ?s
|
173
|
+
hash[:key] ? kv_arr << hash[:key] : kv_arr << hash['key']
|
174
|
+
hash[:value] ? kv_arr << hash[:value] : kv_arr << hash['value']
|
175
|
+
end
|
176
|
+
match_q = match_q + "GROUP BY `entities`.`entity_id`"
|
177
|
+
match = prepare_exe(@connect, match_q, channel_id, *kv_arr)
|
85
178
|
|
86
|
-
|
87
|
-
|
88
|
-
|
179
|
+
match_raw = match.map{ |e| e }
|
180
|
+
entity_ids = []
|
181
|
+
# The entity id is only push into the array if the matches count is equal to
|
182
|
+
# the number of key / values used in the search
|
183
|
+
match_raw.each do |hash|
|
184
|
+
if hash['matches'] == kv.length
|
185
|
+
entity_ids << hash['entity_id']
|
186
|
+
end
|
89
187
|
end
|
188
|
+
|
189
|
+
# Return nil if nothing is pushed into the entity_ids array
|
190
|
+
return nil if entity_ids.count == 0
|
191
|
+
|
192
|
+
# Determine the number of question marks required for the in statements,
|
193
|
+
# based of the number of entity_ids
|
194
|
+
q_marks = in_prepare(entity_ids)
|
195
|
+
|
196
|
+
# Now the entities are requested
|
197
|
+
ent_q = "SELECT `entities`.`entity_id`, `entities`.`body`, `entities`.`created`, `entities`.`type` FROM `channel`.`entities` \
|
198
|
+
INNER JOIN `channel`.`channel_entities` on `entities`.`entity_id` = `channel_entities`.`entity_id` \
|
199
|
+
INNER JOIN `channel`.`channels` on `channel_entities`.`channel_id` = `channels`.`channel_id` \
|
200
|
+
WHERE `channels`.`channel_id` = ? AND `entities`.`entity_id` IN (#{q_marks})"
|
201
|
+
ent = prepare_exe(@connect, ent_q, channel_id, *entity_ids)
|
202
|
+
|
203
|
+
# And their metadata
|
204
|
+
data_q = "SELECT `data`.`entity_id`, `data`.`key`, `data`.`value` FROM `channel`.`data` \
|
205
|
+
INNER JOIN `channel`.`channel_entities` on `data`.`entity_id` = `channel_entities`.`entity_id` \
|
206
|
+
INNER JOIN `channel`.`channels` on `channel_entities`.`channel_id` = `channels`.`channel_id` \
|
207
|
+
WHERE `channels`.`channel_id` = ? AND `data`.`entity_id` IN (#{q_marks})"
|
208
|
+
data = prepare_exe(@connect, data_q, channel_id, *entity_ids)
|
209
|
+
|
210
|
+
# Construct the object requested using the generic method
|
211
|
+
entitys = object_constructor(ent, data)
|
212
|
+
|
90
213
|
return entitys
|
91
214
|
ensure
|
92
215
|
@connect.close
|
93
216
|
end
|
94
217
|
end
|
95
218
|
|
96
|
-
# This method allows the creation of a new entity against a channel.
|
97
|
-
# id must match the id of the channel passed or an error is raised
|
98
|
-
def insert_entity(
|
219
|
+
# This method allows the creation of a new entity against a channel / channels.
|
220
|
+
# The tenant id must match the id of the channel passed or an error is raised
|
221
|
+
def insert_entity(obj, *channel_ids)
|
99
222
|
begin
|
100
223
|
# Connect to the database. Instance variable used to pass connection to
|
101
224
|
# private methods
|
102
225
|
@connect = Connection.new.open(@database, @host, @user, @pw)
|
103
|
-
# Determine if the tenant has access to
|
104
|
-
|
226
|
+
# Determine if the tenant has access to all channels requested
|
227
|
+
channel_ids.each do |channel_id|
|
228
|
+
tenant_channel(channel_id)
|
229
|
+
end
|
105
230
|
|
106
|
-
#
|
107
|
-
|
108
|
-
|
109
|
-
|
231
|
+
# Scan object for type, if it doesn't exist, make it equal to default
|
232
|
+
type = obj[:type] || obj['type']
|
233
|
+
unless type
|
234
|
+
type = 'Text'
|
235
|
+
end
|
236
|
+
|
237
|
+
# Throw errors if Video and Image types do not have required field
|
238
|
+
if type == 'Video' || type == 'Image'
|
239
|
+
bucket_key = obj[:bucket_key] || obj['bucket_key']
|
240
|
+
unless bucket_key
|
241
|
+
message = 'A video or image entity object must include an S3 bucketkey'
|
242
|
+
raise ErrorHandling::InvalidObject, message
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
# Define body and created
|
247
|
+
created = Time.now.utc
|
248
|
+
body = obj[:body] || obj['body']
|
249
|
+
unless body
|
250
|
+
raise ErrorHandling::InvalidObject, 'The entity object must include a body field'
|
251
|
+
end
|
252
|
+
|
253
|
+
insert = "INSERT INTO `channel`.`entities` (`body`, `created`, `type`) VALUES (?, ?, ?)"
|
254
|
+
insert_sql = prepare_exe(@connect, insert, body, created, type)
|
255
|
+
# The last_id mysql2 method provides direct access to the last id inserted
|
256
|
+
entity_id = @connect.last_id
|
257
|
+
|
258
|
+
# Delete body key from object in preparation for k/v insert
|
259
|
+
obj['body'] ? obj.delete('body') : obj.delete(:body)
|
260
|
+
|
261
|
+
# Insert remaining as k/vs, with entity id from above
|
110
262
|
obj.each do |key, value|
|
111
|
-
insert = "INSERT INTO `channel`.`data` (`
|
112
|
-
VALUES (?, ?,
|
263
|
+
insert = "INSERT INTO `channel`.`data` (`key`, `value`, `entity_id`)\
|
264
|
+
VALUES (?, ?, ?)"
|
113
265
|
# This method performs the insert. Mysql2 does not return an object on a successful
|
114
266
|
# insert
|
115
|
-
prepare_exe(@connect, insert,
|
267
|
+
prepare_exe(@connect, insert, key.to_s, value, entity_id)
|
116
268
|
end
|
269
|
+
|
270
|
+
# Insert link entries based on channel_ids passed to method
|
271
|
+
channel_ids.each do |channel_id|
|
272
|
+
insert = "INSERT INTO `channel`.`channel_entities` (`channel_id`, `entity_id`)\
|
273
|
+
VALUES (?, ?)"
|
274
|
+
# This method performs the insert. Mysql2 does not return an object on a successful
|
275
|
+
# insert
|
276
|
+
prepare_exe(@connect, insert, channel_id, entity_id)
|
277
|
+
end
|
278
|
+
|
117
279
|
return { entity_id: entity_id, insert: 'SUCCESS' }
|
118
280
|
ensure
|
119
281
|
@connect.close
|
@@ -128,31 +290,39 @@ class WolasChannel
|
|
128
290
|
@connect = Connection.new.open(@database, @host, @user, @pw)
|
129
291
|
# Determine if the tenant has access to the entity requested
|
130
292
|
check = tenant_entity(entity_id)
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
#
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
prepare_exe(@connect, update, value, entity_id, key.to_s)
|
143
|
-
|
144
|
-
# Now that the insert has been completed, the entire object is returned
|
145
|
-
# from the database and constructed to return to the user
|
146
|
-
entity = entity_construct(entity_id, type)
|
293
|
+
|
294
|
+
# If the key requested for the update is the body, the entity itself is updated.
|
295
|
+
# If it is not, the key is searched for in the data table and either updated or
|
296
|
+
# inserted
|
297
|
+
if key == 'body' || key == :body
|
298
|
+
# update the existing entity body
|
299
|
+
update = "UPDATE `channel`.`entities` SET `entities`.`body` = ? WHERE `entities`.`entity_id` = ?"
|
300
|
+
prepare_exe(@connect, update, value, entity_id)
|
301
|
+
|
302
|
+
# Return the updated entity to the
|
303
|
+
entity = entity_construct(entity_id)
|
147
304
|
else
|
148
|
-
#
|
149
|
-
|
150
|
-
|
151
|
-
|
305
|
+
# Lookup the key to be changed on the entity, insert it if it doesn't exist
|
306
|
+
ent_q = "SELECT * FROM `channel`.`data` WHERE `data`.`entity_id` = ? AND `data`.`key` = ?"
|
307
|
+
ent = prepare_exe(@connect, ent_q, entity_id, key)
|
308
|
+
|
309
|
+
if ent.count != 0
|
310
|
+
# update the existing key value
|
311
|
+
update = "UPDATE `channel`.`data` SET `data`.`value`= ? \
|
312
|
+
WHERE `data`.`entity_id` = ? AND `data`.`key` = ?"
|
313
|
+
prepare_exe(@connect, update, value, entity_id, key.to_s)
|
152
314
|
|
153
|
-
|
154
|
-
|
155
|
-
|
315
|
+
# Return the updated entity to the
|
316
|
+
entity = entity_construct(entity_id)
|
317
|
+
else
|
318
|
+
# insert the new key as it does not exist for the entity
|
319
|
+
insert = "INSERT INTO `channel`.`data` (`key`, `value`, `entity_id`)\
|
320
|
+
VALUES (?, ?, ?)"
|
321
|
+
prepare_exe(@connect, insert, key.to_s, value, entity_id)
|
322
|
+
|
323
|
+
# Return the updated entity to the
|
324
|
+
entity = entity_construct(entity_id)
|
325
|
+
end
|
156
326
|
end
|
157
327
|
|
158
328
|
return entity
|
@@ -161,49 +331,39 @@ class WolasChannel
|
|
161
331
|
end
|
162
332
|
end
|
163
333
|
|
334
|
+
|
164
335
|
private
|
165
336
|
# This method constructs a single object from key-values returned from a
|
166
337
|
# query
|
167
|
-
def object_constructor(ent)
|
168
|
-
#
|
169
|
-
|
170
|
-
entity =
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
#
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
entity_h = {}
|
338
|
+
def object_constructor(ent, data)
|
339
|
+
# Build the entity objects from the entity table. Each row will always represent
|
340
|
+
# one entity
|
341
|
+
entity = ent.map{ |e| e }
|
342
|
+
# For each metadata entry, match it to an entity by id and add the key and value
|
343
|
+
data_raw = data.map{ |e| e }
|
344
|
+
data_raw = data_raw.sort_by{ |k| k['entity_id'] }
|
345
|
+
# This method scans the entity array to match on entity id, and then pushed the
|
346
|
+
# key and value to that hash
|
347
|
+
data_raw.each do |hash|
|
348
|
+
match = entity.find {|e| e['entity_id'] == hash['entity_id']}
|
349
|
+
if match
|
350
|
+
match[hash['key']] = hash['value']
|
181
351
|
end
|
182
|
-
entity_h[hash['key'].to_sym] = hash['value']
|
183
|
-
# Init is used to determine when to push to the array
|
184
|
-
@init = hash['entity_id']
|
185
|
-
# The resource_id for the current hash is stored and added to the entity
|
186
|
-
# hash before it is finalised and pushed to an array
|
187
|
-
@channel_id = hash['channel_id']
|
188
352
|
end
|
189
|
-
# Push the last built hash to the array
|
190
|
-
entity_h[:channel_id] = @channel_id
|
191
|
-
entity_h[:entity_id] = @init
|
192
|
-
entity << entity_h
|
193
353
|
return entity
|
194
354
|
end
|
195
355
|
|
196
356
|
# This method determines the if the channel on an entity is availble to the tenant
|
197
357
|
# and returns the type of channel
|
198
358
|
def tenant_entity(entity_id)
|
199
|
-
res_q = "SELECT
|
200
|
-
INNER JOIN `channel`.`
|
201
|
-
|
359
|
+
res_q = "SELECT `channels`.`tenant_id`, `channels`.`channel_id`, `channels`.`type` FROM `channel`.`channels` \
|
360
|
+
INNER JOIN `channel`.`channel_entities` ON `channels`.`channel_id` = `channel_entities`.`channel_id` \
|
361
|
+
INNER JOIN `channel`.`entities` ON `channel_entities`.`entity_id` = `entities`.`entity_id` \
|
362
|
+
WHERE `entities`.`entity_id` = ?"
|
202
363
|
res = prepare_exe(@connect, res_q, entity_id)
|
203
364
|
return [nil, nil] if res.count == 0
|
204
365
|
|
205
|
-
# Check the tenant_id on each row returned
|
206
|
-
# will all join to the same row on the channels table
|
366
|
+
# Check the tenant_id on each row returned
|
207
367
|
channels = res.map{ |a| a }
|
208
368
|
channels.each do |check|
|
209
369
|
unless check['tenant_id'] == @tenant_id
|
@@ -220,7 +380,9 @@ class WolasChannel
|
|
220
380
|
def tenant_channel(channel_id)
|
221
381
|
res_q = "SELECT * FROM `channel`.`channels` WHERE `channels`.`channel_id` = ?"
|
222
382
|
res = prepare_exe(@connect, res_q, channel_id)
|
223
|
-
|
383
|
+
if res.count == 0
|
384
|
+
raise ErrorHandling::InvalidChannel, 'The channel requested is invalid'
|
385
|
+
end
|
224
386
|
|
225
387
|
# Check the tenant_id on each row returned. They should all be the same, and in this
|
226
388
|
# instance their should only be one row.
|
@@ -230,24 +392,23 @@ class WolasChannel
|
|
230
392
|
raise ErrorHandling::PermissionFailure, 'You do not have permission to access information for this tenant'
|
231
393
|
end
|
232
394
|
@type = check['type']
|
233
|
-
@channel_id = check['channel_id']
|
234
395
|
end
|
235
396
|
return @type
|
236
397
|
end
|
237
398
|
|
238
399
|
# This method returns a constructed entity from an entity id
|
239
|
-
def entity_construct(entity_id
|
240
|
-
ent_q = "SELECT * FROM `channel`.`
|
400
|
+
def entity_construct(entity_id)
|
401
|
+
ent_q = "SELECT * FROM `channel`.`entities` WHERE `entity_id` = ?"
|
241
402
|
ent = prepare_exe(@connect, ent_q, entity_id)
|
242
403
|
|
404
|
+
data_q = "SELECT * FROM `channel`.`data` WHERE `entity_id` = ?"
|
405
|
+
data = prepare_exe(@connect, data_q, entity_id)
|
406
|
+
|
243
407
|
# Return nil if nothing is returned from the select
|
244
408
|
return nil if ent.count == 0
|
245
409
|
|
246
410
|
# Construct the object requested using the generic method.
|
247
|
-
entity = object_constructor(ent)[0]
|
248
|
-
|
249
|
-
# Apply the type to the entity
|
250
|
-
entity[:type] = type
|
411
|
+
entity = object_constructor(ent, data)[0]
|
251
412
|
return entity
|
252
413
|
end
|
253
414
|
|
@@ -258,5 +419,20 @@ class WolasChannel
|
|
258
419
|
result = sqlobj.execute(*inputs)
|
259
420
|
return result
|
260
421
|
end
|
422
|
+
|
423
|
+
# This operation determines the number of question marks to be used for an
|
424
|
+
# IN (), in the SQL prepare statement.
|
425
|
+
def in_prepare(ids)
|
426
|
+
ins = ids.length
|
427
|
+
q_marks = []
|
428
|
+
x = 0
|
429
|
+
while x < ins
|
430
|
+
q_marks << '?'
|
431
|
+
x += 1
|
432
|
+
end
|
433
|
+
# convert ?s array to comma delimited string for IN query
|
434
|
+
q_marks = q_marks.join(',')
|
435
|
+
return q_marks
|
436
|
+
end
|
261
437
|
end
|
262
438
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wolas_channel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WOLAS
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,7 +99,6 @@ files:
|
|
99
99
|
- lib/connection.rb
|
100
100
|
- lib/wolas_channel.rb
|
101
101
|
- lib/wolas_channel/version.rb
|
102
|
-
- wolas_channel-0.1.0.gem
|
103
102
|
- wolas_channel.gemspec
|
104
103
|
homepage: https://bitbucket.org/wolas-revolution/srvc-channel
|
105
104
|
licenses: []
|
data/wolas_channel-0.1.0.gem
DELETED
Binary file
|