salesforce_model 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/salesforce_model.rb +93 -6
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d9d2134a4617f30ff7896ab03a40da323848725
|
4
|
+
data.tar.gz: 4c8bb17f09ed69e9ffcf3670cef35df372ffed7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28b728a366fdd392e4fb7cba5790787581b8fc3d22063ef3716b5a8b4c12492a50bd0ffe6747c5b2038dd7f5ee4e0e877efa9f4151872c07faf983bfc91058bb
|
7
|
+
data.tar.gz: 43723e6b91dd072e2af5cb9a15da7319e686129ecfdd8326cecd7506d9e86c099a8adad108ec90593751cc83ad7cd42a7578e6303f5fd3e4b4c0d78e7dc49add
|
data/lib/salesforce_model.rb
CHANGED
@@ -22,19 +22,19 @@ class SalesforceModel < ActiveRecord::Base
|
|
22
22
|
if ENV['HEROKUCONNECT_SCHEMA'].nil?
|
23
23
|
raise "Please set HEROKUCONNECT_SCHEMA in your environment to use SalesforceModel"
|
24
24
|
end
|
25
|
+
cattr_accessor :schema_name
|
26
|
+
self.schema_name = ENV['HEROKUCONNECT_SCHEMA'] || 'public'
|
27
|
+
|
28
|
+
self.pluralize_table_names = false
|
29
|
+
self.table_name_prefix = self.schema_name + "."
|
30
|
+
|
25
31
|
|
26
32
|
establish_connection ENV['HEROKUCONNECT_URL']
|
27
33
|
|
28
|
-
cattr_accessor :schema_name
|
29
|
-
self.schema_name = ENV['HEROKUCONNECT_SCHEMA'] || 'public'
|
30
34
|
self.connection.schema_search_path = self.schema_name + ",public"
|
31
35
|
|
32
36
|
self.abstract_class = true
|
33
37
|
|
34
|
-
def self.table_name
|
35
|
-
return self.schema_name + '.' + self.name.downcase
|
36
|
-
end
|
37
|
-
|
38
38
|
# Introspect tables from the active schema and generate SalesforceModel subclasses
|
39
39
|
# for each table. This is meant for quick bootstrapping models at the Rails console.
|
40
40
|
def self.reflect_models
|
@@ -51,5 +51,92 @@ class SalesforceModel < ActiveRecord::Base
|
|
51
51
|
nil
|
52
52
|
end
|
53
53
|
|
54
|
+
attr_protected :createddate, :systemmodstamp, :lastmodifieddate
|
55
|
+
|
56
|
+
class TriggerLog < SalesforceModel
|
57
|
+
self.table_name = superclass.schema_name + "._trigger_log"
|
58
|
+
|
59
|
+
scope :pending, -> { where("state in ('PENDING','NEW')") }
|
60
|
+
scope :completed, -> { where("state in ('SUCCESS','FAILED')") }
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.all_errors
|
64
|
+
TriggerLog.where(:state => 'FAILED').order("id DESC").all
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.pending_count
|
68
|
+
TriggerLog.where("state in ('PENDING','NEW')").count
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.last_trigger_id
|
72
|
+
row = SalesforceModel.connection.select_all("select * From _trigger_last_id")[0]
|
73
|
+
if row
|
74
|
+
row.values[0].to_i
|
75
|
+
else
|
76
|
+
nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.pending_changes
|
81
|
+
TriggerLog.where("state in ('PENDING','NEW')")
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.recent_changes
|
85
|
+
TriggerLog.order("id DESC").limit(10).all
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.format_trigger_log_rows(rows)
|
89
|
+
require 'text-table'
|
90
|
+
|
91
|
+
tables = Hash.new {|hash,key| hash[key] = Text::Table.new}
|
92
|
+
rows.each do |tl|
|
93
|
+
table = tables[tl.table_name]
|
94
|
+
data = eval("{#{tl.values.gsub(/NULL/,'nil')}}")
|
95
|
+
header = ['log id', 'state','op','table','rec id']
|
96
|
+
row = [tl.id, tl.state, tl.action, tl.table_name, tl.record_id]
|
97
|
+
data.keys.sort.each do |key|
|
98
|
+
next if key == '_c5_source'
|
99
|
+
header.append(key[0,8])
|
100
|
+
row.append(data[key])
|
101
|
+
end
|
102
|
+
header.append('sf_msg')
|
103
|
+
row.append(tl.sf_message)
|
104
|
+
|
105
|
+
table.head ||= header
|
106
|
+
table.rows.append(row)
|
107
|
+
end
|
108
|
+
|
109
|
+
tables.each do |table|
|
110
|
+
puts table
|
111
|
+
puts
|
112
|
+
end
|
113
|
+
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.recent_updates(table = nil, limit=10)
|
118
|
+
self.format_trigger_log_rows(TriggerLog.order("id DESC").limit(limit))
|
119
|
+
end
|
120
|
+
|
121
|
+
def pending_updates
|
122
|
+
rows = TriggerLog.pending.where(:record_id => self.id)
|
123
|
+
SalesforceModel.format_trigger_log_rows(rows)
|
124
|
+
end
|
125
|
+
|
126
|
+
def recent_updates
|
127
|
+
SalesforceModel.format_trigger_log_rows(TriggerLog.where(:record_id => self.id).order("id DESC").limit(10))
|
128
|
+
end
|
129
|
+
|
130
|
+
def salesforce_errors
|
131
|
+
TriggerLog.where(:record_id => self.id, :state => 'FAILED').order("id DESC").all
|
132
|
+
end
|
133
|
+
|
134
|
+
def salesforce_error
|
135
|
+
log = TriggerLog.where(:record_id => self.id, :state => 'FAILED').order("id DESC").last
|
136
|
+
if !log.nil?
|
137
|
+
return log.sf_message
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
54
141
|
end
|
55
142
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesforce_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Persinger
|
@@ -9,7 +9,35 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-04-08 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: text-table
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
13
41
|
description: Base ActiveRecord subclass for accessing Heroku Connect sync tables
|
14
42
|
email: scottp@heroku.com
|
15
43
|
executables: []
|