salesforce_model 0.0.1
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 +7 -0
- data/lib/salesforce_model.rb +55 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9b5f3c2637368db3fa8ad9bb80509885edc931c1
|
4
|
+
data.tar.gz: e0e3a34e0f9aee403ee1c95f8d3c880abdf439c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 721a7e2e2bc73f516574b17d0ac2650e9fdf0bbf0a36b0806ab7a6e48e67d64c890346363d54e0578828df948a454fb55224cabba0427d7a8a7b3c4652378d67
|
7
|
+
data.tar.gz: 05a44bcdb7bc1e832af932c667141dbb5d2eaad962a9602336120899c55f84b662a7aae7113bde4446b89ce638f1f729aea86669ed9cfcbd8e4108e94bb4f0eb
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
# Abstract ActiveRecord subclass for easy access to Heroku Connect tables.
|
4
|
+
# To use, just inherit your model class from this class:
|
5
|
+
#
|
6
|
+
# require 'salesforce_model'
|
7
|
+
#
|
8
|
+
# class Account << SalesforceModel
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# You must set <tt>HEROKUCONNECT_URL</tt> and <tt>HEROKUCONNNECT_SCHEMA</tt> in your environment
|
12
|
+
# to point to your Heroku Connect database.
|
13
|
+
#
|
14
|
+
# For simple interactive usage, you can call <tt>reflect_models</tt>. This will
|
15
|
+
# introspect your database and automatically create AR models for the tables
|
16
|
+
# that it finds.
|
17
|
+
|
18
|
+
class SalesforceModel < ActiveRecord::Base
|
19
|
+
if ENV['HEROKUCONNECT_URL'].nil?
|
20
|
+
raise "Please set HEROKUCONNECT_URL in your environment to use SalesforceModel"
|
21
|
+
end
|
22
|
+
if ENV['HEROKUCONNECT_SCHEMA'].nil?
|
23
|
+
raise "Please set HEROKUCONNECT_SCHEMA in your environment to use SalesforceModel"
|
24
|
+
end
|
25
|
+
|
26
|
+
establish_connection ENV['HEROKUCONNECT_URL']
|
27
|
+
|
28
|
+
cattr_accessor :schema_name
|
29
|
+
self.schema_name = ENV['HEROKUCONNECT_SCHEMA'] || 'public'
|
30
|
+
self.connection.schema_search_path = self.schema_name + ",public"
|
31
|
+
|
32
|
+
self.abstract_class = true
|
33
|
+
|
34
|
+
def self.table_name
|
35
|
+
return self.schema_name + '.' + self.name.downcase
|
36
|
+
end
|
37
|
+
|
38
|
+
# Introspect tables from the active schema and generate SalesforceModel subclasses
|
39
|
+
# for each table. This is meant for quick bootstrapping models at the Rails console.
|
40
|
+
def self.reflect_models
|
41
|
+
self.connection.tables.each do |table|
|
42
|
+
next if table.starts_with?("_") || table.starts_with?("c5")
|
43
|
+
next if !self.connection.table_exists?(self.schema_name + "." + table)
|
44
|
+
klass = table.dup
|
45
|
+
klass[0] = klass[0].capitalize
|
46
|
+
if !Object.const_defined?(klass)
|
47
|
+
Object.const_set(klass, Class.new(SalesforceModel))
|
48
|
+
puts klass
|
49
|
+
end
|
50
|
+
end
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: salesforce_model
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Persinger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Base ActiveRecord subclass for accessing Heroku Connect sync tables
|
14
|
+
email: scottp@heroku.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/salesforce_model.rb
|
20
|
+
homepage: https://github.com/heroku/salesforce_model
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.1.11
|
41
|
+
signing_key:
|
42
|
+
specification_version: 3
|
43
|
+
summary: AR subclass for accessing Heroku Connect tables
|
44
|
+
test_files: []
|