databasedotcom-isolated 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/databasedotcom-isolated.gemspec +24 -0
- data/lib/databasedotcom-isolated.rb +5 -0
- data/lib/databasedotcom/isolated/runner.rb +7 -0
- data/lib/databasedotcom/isolated/scope.rb +62 -0
- data/lib/databasedotcom/isolated/version.rb +5 -0
- data/spec/scope_spec.rb +74 -0
- data/spec/spec_helper.rb +1 -0
- metadata +130 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Seba Gamboa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# databasedotcom-isolated
|
2
|
+
|
3
|
+
This gem let's you perform actions using the databasedotcom gem without having
|
4
|
+
to worry about constant pollution and modules namespacing.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'databasedotcom-isolated'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install databasedotcom-isolated
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
# define your connection options
|
24
|
+
options = {
|
25
|
+
# App credentials
|
26
|
+
client_id: 'YOUR_CLIENT_ID',
|
27
|
+
client_secret: 'YOUR_CLIENT_SECRET',
|
28
|
+
|
29
|
+
# Oauth token authentication
|
30
|
+
token: 'YOUR_AUTHENTICATION_TOKEN',
|
31
|
+
|
32
|
+
# Or alternatively
|
33
|
+
username: 'YOUR_USERNAME',
|
34
|
+
password: 'YOUR_PASSWORD_AND_SECRET_TOKEN'
|
35
|
+
}
|
36
|
+
|
37
|
+
# Perform everything inside a block
|
38
|
+
Databasedotcom::Isolated.perform(options) do
|
39
|
+
contact = Contact.last
|
40
|
+
|
41
|
+
puts contact.inspect
|
42
|
+
end
|
43
|
+
|
44
|
+
# And everything get's cleaned up behind you.
|
45
|
+
defined? Contact # => nil
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'databasedotcom/isolated/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "databasedotcom-isolated"
|
8
|
+
gem.version = Databasedotcom::Isolated::VERSION
|
9
|
+
gem.authors = ["Seba Gamboa"]
|
10
|
+
gem.email = ["me@sagmor.com"]
|
11
|
+
gem.description = %q{Isolate databasedotcom materialized clases to work with multiple orgs safely}
|
12
|
+
gem.summary = %q{Isolate databasedotcom materialized clases to work with multiple orgs safely}
|
13
|
+
gem.homepage = "https://github.com/sagmor/databasedotcom-isolated"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "databasedotcom"
|
21
|
+
gem.add_dependency "sourcify"
|
22
|
+
gem.add_development_dependency "rake"
|
23
|
+
gem.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Databasedotcom
|
2
|
+
module Isolated
|
3
|
+
# Shared functionatily of an isolated scope
|
4
|
+
class Scope
|
5
|
+
CLIENT_OPTIONS = [:client_id,:client_secret]
|
6
|
+
AUTHENTICATION_OPTIONS = [:username, :password, :token]
|
7
|
+
|
8
|
+
def Scope.new(options = {})
|
9
|
+
Class.new(self).tap do |scope|
|
10
|
+
scope.options = options
|
11
|
+
scope.client = options[:client]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :options, :client, :binding
|
17
|
+
|
18
|
+
def client
|
19
|
+
@client ||= Databasedotcom::Client.new(self.options.slice(*CLIENT_OPTIONS)).tap do |client|
|
20
|
+
client.sobject_module = scope
|
21
|
+
self.options.slice(*AUTHENTICATION_OPTIONS).tap do |auth_options|
|
22
|
+
client.authenticate(auth_options) unless auth_options.empty?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def perform(&block)
|
28
|
+
# self.new.instance_eval(&block)
|
29
|
+
self.binding = block.binding
|
30
|
+
(self.class_eval(block.to_source)).call
|
31
|
+
self.binding = nil
|
32
|
+
|
33
|
+
# self.class_eval( &eval(block.to_source) )
|
34
|
+
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(sym,*args)
|
39
|
+
if args.empty?
|
40
|
+
eval(sym.to_s,binding)
|
41
|
+
else
|
42
|
+
context = eval("self",binding)
|
43
|
+
context.send(sym,*args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Search for missing constants on the current list of sobjects if available
|
48
|
+
def const_missing(sym)
|
49
|
+
if self.list_sobjects.include?(sym.to_s)
|
50
|
+
self.client.materialize(sym.to_s)
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def list_sobjects
|
57
|
+
@list_sobjects ||= self.client.list_sobjects
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/scope_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Databasedotcom::Isolated::Scope do
|
4
|
+
before(:each) do
|
5
|
+
@scope = Databasedotcom::Isolated::Scope.new({
|
6
|
+
client: double('client', {
|
7
|
+
list_sobjects: %w{Contact Account}
|
8
|
+
})
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
it "Initializes as new anonimous subclass rather than an instance" do
|
13
|
+
expect(@scope).to be_kind_of Class
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can connect to diferent clients at hte same time" do
|
17
|
+
another_scope = Databasedotcom::Isolated::Scope.new({
|
18
|
+
client: double('client2')
|
19
|
+
})
|
20
|
+
|
21
|
+
expect(@scope.client).not_to be_eql another_scope.client
|
22
|
+
end
|
23
|
+
|
24
|
+
context "#perform" do
|
25
|
+
before(:each) do
|
26
|
+
# @scope.client.should_receive('list_sobject').and_return(%w{Contact Account})
|
27
|
+
end
|
28
|
+
|
29
|
+
it "performs the code on the block" do
|
30
|
+
@scope.perform do
|
31
|
+
'DO SOMETHING'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "search for constants on the database.com client" do
|
36
|
+
@scope.client.should_receive(:list_sobjects)
|
37
|
+
expect{
|
38
|
+
@scope.perform do
|
39
|
+
UnknownContact
|
40
|
+
end
|
41
|
+
}.to raise_error NameError
|
42
|
+
end
|
43
|
+
|
44
|
+
it "materializes known database.com classes" do
|
45
|
+
@scope.client.should_receive(:materialize).with('Contact').and_return(Class.new)
|
46
|
+
|
47
|
+
@scope.perform do
|
48
|
+
Contact.new
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "doesn't pollutes known namespaces with constants" do
|
53
|
+
@scope.client.should_receive(:materialize).with('Contact').and_return(Class.new)
|
54
|
+
|
55
|
+
@scope.perform do
|
56
|
+
Contact.new
|
57
|
+
end
|
58
|
+
|
59
|
+
expect(defined?( Contact )).to be_nil
|
60
|
+
expect(defined?( ::Contact )).to be_nil
|
61
|
+
expect(defined?( Databasedotcom::Isolated::Scope::Contact )).to be_nil
|
62
|
+
expect(defined?( Databasedotcom::Isolated::Scope.new::Contact )).to be_nil
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
it "properly pass outside variables into the block" do
|
67
|
+
variable = 1
|
68
|
+
|
69
|
+
@scope.perform do
|
70
|
+
expect(variable).to be 1
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'databasedotcom-isolated'
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: databasedotcom-isolated
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Seba Gamboa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: databasedotcom
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sourcify
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Isolate databasedotcom materialized clases to work with multiple orgs
|
79
|
+
safely
|
80
|
+
email:
|
81
|
+
- me@sagmor.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- databasedotcom-isolated.gemspec
|
92
|
+
- lib/databasedotcom-isolated.rb
|
93
|
+
- lib/databasedotcom/isolated/runner.rb
|
94
|
+
- lib/databasedotcom/isolated/scope.rb
|
95
|
+
- lib/databasedotcom/isolated/version.rb
|
96
|
+
- spec/scope_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
homepage: https://github.com/sagmor/databasedotcom-isolated
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: 351657803861277609
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
hash: 351657803861277609
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.23
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Isolate databasedotcom materialized clases to work with multiple orgs safely
|
128
|
+
test_files:
|
129
|
+
- spec/scope_spec.rb
|
130
|
+
- spec/spec_helper.rb
|