activesalesforce 0.1.4 → 0.1.5
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.
File without changes
|
@@ -72,10 +72,15 @@ module ActiveRecord
|
|
72
72
|
super message
|
73
73
|
|
74
74
|
@fault = fault
|
75
|
+
|
76
|
+
puts "\nSalesforceError:\n message='#{message}'\n fault='#{fault}'\n\n"
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
78
80
|
class SalesforceAdapter < AbstractAdapter
|
81
|
+
COLUMN_NAME_REGEX = /@C_(\w+)/
|
82
|
+
COLUMN_VALUE_REGEX = /@V_'(([^']|\\')*)'/
|
83
|
+
|
79
84
|
include StringHelper
|
80
85
|
|
81
86
|
attr_accessor :batch_size
|
@@ -91,10 +96,12 @@ module ActiveRecord
|
|
91
96
|
@relationships_map = {}
|
92
97
|
end
|
93
98
|
|
99
|
+
|
94
100
|
def adapter_name #:nodoc:
|
95
101
|
'Salesforce'
|
96
102
|
end
|
97
103
|
|
104
|
+
|
98
105
|
def supports_migrations? #:nodoc:
|
99
106
|
false
|
100
107
|
end
|
@@ -103,38 +110,29 @@ module ActiveRecord
|
|
103
110
|
# QUOTING ==================================================
|
104
111
|
|
105
112
|
def quote(value, column = nil)
|
106
|
-
|
107
|
-
|
108
|
-
"
|
109
|
-
|
110
|
-
super
|
111
|
-
end
|
113
|
+
case value
|
114
|
+
when NilClass then quoted_value = "'NULL'"
|
115
|
+
when TrueClass then quoted_value = "'TRUE'"
|
116
|
+
when FalseClass then quoted_value = "'FALSE'"
|
117
|
+
else quoted_value = super(value, column)
|
118
|
+
end
|
119
|
+
|
120
|
+
"@V_#{quoted_value}"
|
112
121
|
end
|
113
122
|
|
123
|
+
|
114
124
|
def quote_column_name(name) #:nodoc:
|
115
125
|
# Mark the column name to make it easier to find later
|
116
|
-
"
|
117
|
-
end
|
118
|
-
|
119
|
-
def quote_string(string) #:nodoc:
|
120
|
-
string
|
126
|
+
"@C_#{name}"
|
121
127
|
end
|
122
128
|
|
123
|
-
def quoted_true
|
124
|
-
"TRUE"
|
125
|
-
end
|
126
|
-
|
127
|
-
def quoted_false
|
128
|
-
"FALSE"
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
129
|
# CONNECTION MANAGEMENT ====================================
|
133
130
|
|
134
131
|
def active?
|
135
132
|
true
|
136
133
|
end
|
137
134
|
|
135
|
+
|
138
136
|
def reconnect!
|
139
137
|
connect
|
140
138
|
end
|
@@ -157,11 +155,14 @@ module ActiveRecord
|
|
157
155
|
|
158
156
|
# Fixup column references to use api names
|
159
157
|
columns = columns_map(table_name)
|
160
|
-
while soql =~
|
158
|
+
while soql =~ COLUMN_NAME_REGEX
|
161
159
|
column = columns[$~[1]]
|
162
160
|
soql = $~.pre_match + column.api_name + $~.post_match
|
163
161
|
end
|
164
162
|
|
163
|
+
# Remove column value prefix
|
164
|
+
soql.gsub!(/@V_/, "")
|
165
|
+
|
165
166
|
log(soql, name)
|
166
167
|
|
167
168
|
@connection.batch_size = @batch_size if @batch_size
|
@@ -196,6 +197,7 @@ module ActiveRecord
|
|
196
197
|
result
|
197
198
|
end
|
198
199
|
|
200
|
+
|
199
201
|
def select_one(sql, name = nil) #:nodoc:
|
200
202
|
self.batch_size = 1
|
201
203
|
|
@@ -214,21 +216,26 @@ module ActiveRecord
|
|
214
216
|
end
|
215
217
|
end
|
216
218
|
|
219
|
+
|
217
220
|
def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
|
218
|
-
|
221
|
+
log(sql, name)
|
219
222
|
|
220
223
|
# Convert sql to sobject
|
221
|
-
table_name =
|
224
|
+
table_name = sql.match(/INSERT INTO (\w+) /)[1].singularize
|
222
225
|
entity_name = entity_name_from_table(table_name)
|
223
226
|
columns = columns_map(table_name)
|
224
227
|
|
225
|
-
# Extract array of
|
226
|
-
names =
|
227
|
-
values = tokens[(tokens.length / 2) + 2 .. tokens.length]
|
228
|
+
# Extract array of column names
|
229
|
+
names = extract_columns(sql)
|
228
230
|
|
231
|
+
# Extract arrays of values
|
232
|
+
values = extract_values(sql)
|
233
|
+
|
234
|
+
pp names
|
235
|
+
pp values
|
236
|
+
|
229
237
|
fields = {}
|
230
|
-
names.
|
231
|
-
name = names[n]
|
238
|
+
names.each_with_index do | name, n |
|
232
239
|
value = values[n]
|
233
240
|
column = columns[name]
|
234
241
|
|
@@ -240,35 +247,38 @@ module ActiveRecord
|
|
240
247
|
check_result(get_result(@connection.create(:sObjects => sobject), :create))[0][:id]
|
241
248
|
end
|
242
249
|
|
250
|
+
|
243
251
|
def update(sql, name = nil) #:nodoc:
|
252
|
+
log(sql, name)
|
253
|
+
|
244
254
|
# Convert sql to sobject
|
245
255
|
table_name = sql.match(/UPDATE (\w+) /)[1].singularize
|
246
256
|
entity_name = entity_name_from_table(table_name)
|
247
257
|
columns = columns_map(table_name)
|
248
258
|
|
249
|
-
|
250
|
-
|
251
|
-
|
259
|
+
names = extract_columns(sql)
|
260
|
+
values = extract_values(sql)
|
261
|
+
|
252
262
|
fields = {}
|
253
|
-
|
263
|
+
names.each_with_index do | name, n |
|
254
264
|
column = columns[name]
|
255
|
-
|
265
|
+
value = values[n]
|
266
|
+
fields[column.api_name] = value if not column.readonly and value != "NULL"
|
256
267
|
end
|
257
|
-
|
258
|
-
id =
|
259
|
-
fields.delete("Id")
|
268
|
+
|
269
|
+
id = sql.match(/WHERE id = @V_'(\w+)'/)[1]
|
260
270
|
|
261
271
|
sobject = create_sobject(entity_name, id, fields)
|
262
272
|
|
263
273
|
check_result(get_result(@connection.update(:sObjects => sobject), :update))
|
264
274
|
end
|
265
275
|
|
276
|
+
|
266
277
|
def delete(sql, name = nil)
|
267
|
-
|
268
|
-
match = sql.match(/IN \(([^\)]*)\)/)
|
278
|
+
log(sql, name)
|
269
279
|
|
270
|
-
#
|
271
|
-
ids =
|
280
|
+
# Extract the ids
|
281
|
+
ids = extract_values(sql)
|
272
282
|
|
273
283
|
ids_element = []
|
274
284
|
ids.each { |id| ids_element << :ids << id }
|
@@ -276,25 +286,28 @@ module ActiveRecord
|
|
276
286
|
check_result(get_result(@connection.delete(ids_element), :delete))
|
277
287
|
end
|
278
288
|
|
289
|
+
|
279
290
|
def get_result(response, method)
|
280
291
|
responseName = (method.to_s + "Response").to_sym
|
281
292
|
finalResponse = response[responseName]
|
282
293
|
|
283
|
-
raise SalesforceError.new(response[:
|
294
|
+
raise SalesforceError.new(response[:fault][:faultstring], response.fault) unless finalResponse
|
284
295
|
|
285
296
|
result = finalResponse[:result]
|
286
|
-
end
|
297
|
+
end
|
298
|
+
|
287
299
|
|
288
300
|
def check_result(result)
|
289
301
|
result = [ result ] unless result.is_a?(Array)
|
290
302
|
|
291
303
|
result.each do |r|
|
292
|
-
|
304
|
+
raise SalesforceError.new(r[:errors], r[:errors][:message]) unless r[:success] == "true"
|
293
305
|
end
|
294
306
|
|
295
307
|
result
|
296
308
|
end
|
297
309
|
|
310
|
+
|
298
311
|
def columns(table_name, name = nil)
|
299
312
|
entity_name = entity_name_from_table(table_name)
|
300
313
|
|
@@ -331,6 +344,7 @@ module ActiveRecord
|
|
331
344
|
cached_columns
|
332
345
|
end
|
333
346
|
|
347
|
+
|
334
348
|
def configure_active_record(entity_name)
|
335
349
|
klass = entity_name.constantize
|
336
350
|
klass.table_name = entity_name
|
@@ -370,6 +384,7 @@ module ActiveRecord
|
|
370
384
|
|
371
385
|
end
|
372
386
|
|
387
|
+
|
373
388
|
def relationships(table_name)
|
374
389
|
entity_name = entity_name_from_table(table_name)
|
375
390
|
|
@@ -383,6 +398,7 @@ module ActiveRecord
|
|
383
398
|
@relationships_map[entity_name]
|
384
399
|
end
|
385
400
|
|
401
|
+
|
386
402
|
def columns_map(table_name, name = nil)
|
387
403
|
entity_name = entity_name_from_table(table_name)
|
388
404
|
|
@@ -397,6 +413,7 @@ module ActiveRecord
|
|
397
413
|
columns_map
|
398
414
|
end
|
399
415
|
|
416
|
+
|
400
417
|
def entity_name_from_table(table_name)
|
401
418
|
return table_name.singularize.camelize
|
402
419
|
end
|
@@ -415,17 +432,31 @@ module ActiveRecord
|
|
415
432
|
sobj
|
416
433
|
end
|
417
434
|
|
435
|
+
|
418
436
|
def table_name_from_sql(sql)
|
419
437
|
sql.match(/FROM (\w+) /)[1].singularize
|
420
438
|
end
|
421
439
|
|
440
|
+
|
422
441
|
def column_names(table_name)
|
423
442
|
columns(table_name).map { |column| column.name }
|
424
443
|
end
|
425
444
|
|
445
|
+
|
426
446
|
def api_column_names(table_name)
|
427
447
|
columns(table_name).map { |column| column.api_name }
|
428
448
|
end
|
449
|
+
|
450
|
+
|
451
|
+
def extract_columns(sql)
|
452
|
+
sql.scan(COLUMN_NAME_REGEX).flatten
|
453
|
+
end
|
454
|
+
|
455
|
+
|
456
|
+
def extract_values(sql)
|
457
|
+
sql.scan(COLUMN_VALUE_REGEX).map { |v| v[0] }
|
458
|
+
end
|
459
|
+
|
429
460
|
end
|
430
461
|
|
431
462
|
end
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activesalesforce
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
6
|
+
version: 0.1.5
|
7
7
|
date: 2006-02-03 00:00:00 -05:00
|
8
8
|
summary: ActiveSalesforce is an extension to the Rails Framework that allows for the dynamic creation and management of ActiveRecord objects through the use of Salesforce meta-data and uses a Salesforce.com organization as the backing store.
|
9
9
|
require_paths:
|
@@ -12,7 +12,7 @@ email: dchasman@salesforce.com
|
|
12
12
|
homepage: http://rubyforge.org/projects/activesfdc/
|
13
13
|
rubyforge_project:
|
14
14
|
description:
|
15
|
-
autorequire:
|
15
|
+
autorequire: activesalesforce
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
18
18
|
has_rdoc: false
|
@@ -30,7 +30,7 @@ authors:
|
|
30
30
|
files:
|
31
31
|
- lib/salesforce_login.rb
|
32
32
|
- lib/column_definition.rb
|
33
|
-
- lib/
|
33
|
+
- lib/activesalesforce.rb
|
34
34
|
- lib/rforce.rb
|
35
35
|
- lib/salesforce_connection_adapter.rb
|
36
36
|
- test/unit
|