salesforce-orm 1.0.0 → 1.1.0
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/Gemfile.lock +3 -7
- data/README.md +23 -4
- data/build.sh +1 -1
- data/lib/salesforce-orm/base.rb +8 -1
- data/lib/salesforce-orm/error.rb +2 -0
- data/lib/salesforce-orm/object.rb +8 -0
- data/lib/salesforce-orm/object/record_type.rb +15 -0
- data/lib/salesforce-orm/object_maker.rb +4 -0
- data/lib/salesforce-orm/record_type_manager.rb +47 -0
- data/lib/salesforce-orm/version.rb +1 -1
- data/salesforce-orm.gemspec +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b4adb5f45bbeaa6ea82b0d370e5a4c2d9dff98c
|
4
|
+
data.tar.gz: 0df34f48d1039efbe762b9a4aff5325abaf09932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7c1d7e2d91dd15152335886830b60e5e448f05a29800f13e86225f7cbce6c68f0c3b38fbb8ca99c8e57c5bfb03eb3aea36a19f166040478ad88f795b1707d0f
|
7
|
+
data.tar.gz: 8716ce9f8ec847188ef628b2dda650737ff805531d2242493ec89187d799bfe4b1c3156c70e0f566d6df1476a64f8913e712d1558d649abc49643093ec7efaf5
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
salesforce-orm (1.
|
4
|
+
salesforce-orm (1.1.0)
|
5
5
|
activerecord (~> 3)
|
6
6
|
activerecord-nulldb-adapter (~> 0)
|
7
7
|
restforce (~> 2.5)
|
@@ -24,11 +24,7 @@ GEM
|
|
24
24
|
multi_json (~> 1.0)
|
25
25
|
arel (3.0.3)
|
26
26
|
builder (3.0.4)
|
27
|
-
byebug (
|
28
|
-
columnize (>= 0.3.1)
|
29
|
-
debugger-linecache (~> 1.2.0)
|
30
|
-
columnize (0.9.0)
|
31
|
-
debugger-linecache (1.2.0)
|
27
|
+
byebug (9.0.5)
|
32
28
|
diff-lcs (1.3)
|
33
29
|
faraday (0.12.1)
|
34
30
|
multipart-post (>= 1.2, < 3)
|
@@ -65,7 +61,7 @@ PLATFORMS
|
|
65
61
|
|
66
62
|
DEPENDENCIES
|
67
63
|
bundler (~> 1.15)
|
68
|
-
byebug (~>
|
64
|
+
byebug (~> 9)
|
69
65
|
rake (~> 10.0)
|
70
66
|
rspec (~> 3.0)
|
71
67
|
salesforce-orm!
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Or, If you want to install globally
|
|
17
17
|
gem install salesforce-orm
|
18
18
|
```
|
19
19
|
|
20
|
-
This Gem internally use [Restforce](https://github.com/ejholmes/restforce), So you have configure it
|
20
|
+
This Gem internally use [Restforce](https://github.com/ejholmes/restforce), So you have to configure it
|
21
21
|
|
22
22
|
There are 2 options to configure ([Restforce config](https://github.com/ejholmes/restforce#initialization))
|
23
23
|
|
@@ -109,14 +109,34 @@ Default data type map for `SampleObject`
|
|
109
109
|
If you wanna change the data type of some fields
|
110
110
|
|
111
111
|
```
|
112
|
-
|
113
|
-
|
112
|
+
class SampleObject < SalesforceOrm::ObjectBase
|
113
|
+
self.data_type_map = {
|
114
|
+
field_one: :datetime,
|
114
115
|
field_two: :integer
|
115
116
|
}
|
117
|
+
end
|
116
118
|
```
|
117
119
|
|
118
120
|
**NOTE: It's mandatory to add data type map for boolean fields**
|
119
121
|
|
122
|
+
### record_type
|
123
|
+
|
124
|
+
By default there is no record type configured for any object
|
125
|
+
|
126
|
+
To specify a record type,
|
127
|
+
|
128
|
+
```
|
129
|
+
class SampleObject < SalesforceOrm::ObjectBase
|
130
|
+
self.record_type = 'Xyz' # DeveloperName in RecordType object
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
All the queries and `create!` method will automatically use record type
|
135
|
+
|
136
|
+
First time use the object, we make a call to Salesforce and find the record type by it's `DeveloperName`. This will be cached in memory.
|
137
|
+
|
138
|
+
With Rails in except in development or test env, we take the advantage of `Rails.cache`
|
139
|
+
|
120
140
|
### Methods
|
121
141
|
|
122
142
|
Methods are similar to ActiveRecord::Base
|
@@ -209,7 +229,6 @@ SampleObject.build({id: 'some id', field_one: 'Some value'})
|
|
209
229
|
|
210
230
|
- Default values
|
211
231
|
- Relationships
|
212
|
-
- Record type
|
213
232
|
- More data types
|
214
233
|
- Better aggregate methods
|
215
234
|
|
data/build.sh
CHANGED
data/lib/salesforce-orm/base.rb
CHANGED
@@ -19,12 +19,19 @@ module SalesforceOrm
|
|
19
19
|
@klass = klass
|
20
20
|
@client = RestforceClient.instance
|
21
21
|
@builder = QueryBuilder.select(klass.field_map.keys)
|
22
|
+
where(RecordTypeManager::FIELD_NAME => klass.record_type_id) if klass.record_type_id
|
22
23
|
end
|
23
24
|
|
24
25
|
# create! doesn't return the SalesForce object back
|
25
26
|
# It will return only the object id
|
26
27
|
def create!(attributes)
|
27
|
-
|
28
|
+
new_attributes = map_to_keys(attributes)
|
29
|
+
|
30
|
+
new_attributes = new_attributes.merge(
|
31
|
+
RecordTypeManager::FIELD_NAME => klass.record_type_id
|
32
|
+
) if klass.record_type_id
|
33
|
+
|
34
|
+
client.create!(klass.object_name, new_attributes)
|
28
35
|
end
|
29
36
|
|
30
37
|
# Transaction not guaranteed
|
data/lib/salesforce-orm/error.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
module SalesforceOrm
|
2
|
+
module RecordTypeManager
|
3
|
+
|
4
|
+
FIELD_NAME = :RecordTypeId
|
5
|
+
|
6
|
+
def record_type=(new_record_type)
|
7
|
+
@record_type = new_record_type
|
8
|
+
end
|
9
|
+
|
10
|
+
def record_type
|
11
|
+
@record_type
|
12
|
+
end
|
13
|
+
|
14
|
+
def record_type_id
|
15
|
+
return nil unless record_type
|
16
|
+
return @record_type_id if @record_type_id
|
17
|
+
|
18
|
+
record_type_sobject = if defined?(Rails)
|
19
|
+
if Rails.env.test?
|
20
|
+
Object::RecordType.build(id: 'fake_record_type')
|
21
|
+
elsif !Rails.env.development?
|
22
|
+
Rails.cache.fetch(record_type_cache_key) do
|
23
|
+
fetch_record_type
|
24
|
+
end
|
25
|
+
else
|
26
|
+
fetch_record_type
|
27
|
+
end
|
28
|
+
else
|
29
|
+
fetch_record_type
|
30
|
+
end
|
31
|
+
|
32
|
+
raise Error::RecordTypeNotFound unless record_type_sobject
|
33
|
+
|
34
|
+
@record_type_id = record_type_sobject.id
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def fetch_record_type
|
40
|
+
Object::RecordType.where(developer_name: record_type).first
|
41
|
+
end
|
42
|
+
|
43
|
+
def record_type_cache_key
|
44
|
+
['RecordTypeManager', object_name, record_type].join('/')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/salesforce-orm.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_dependency 'activerecord-nulldb-adapter', '~> 0'
|
25
25
|
s.add_dependency 'restforce', '~> 2.5'
|
26
26
|
|
27
|
-
s.add_development_dependency 'byebug', '~>
|
27
|
+
s.add_development_dependency 'byebug', '~> 9'
|
28
28
|
s.add_development_dependency 'rspec', '~> 3.0'
|
29
29
|
s.add_development_dependency 'bundler', '~> 1.15'
|
30
30
|
s.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesforce-orm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vishal Vijay
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '9'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '9'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,9 +131,12 @@ files:
|
|
131
131
|
- lib/salesforce-orm/base.rb
|
132
132
|
- lib/salesforce-orm/configuration.rb
|
133
133
|
- lib/salesforce-orm/error.rb
|
134
|
+
- lib/salesforce-orm/object.rb
|
135
|
+
- lib/salesforce-orm/object/record_type.rb
|
134
136
|
- lib/salesforce-orm/object_base.rb
|
135
137
|
- lib/salesforce-orm/object_maker.rb
|
136
138
|
- lib/salesforce-orm/query_builder.rb
|
139
|
+
- lib/salesforce-orm/record_type_manager.rb
|
137
140
|
- lib/salesforce-orm/restforce_client.rb
|
138
141
|
- lib/salesforce-orm/sql_to_soql.rb
|
139
142
|
- lib/salesforce-orm/version.rb
|