databasedotcom-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +22 -0
- data/README.md +75 -0
- data/lib/databasedotcom-rails.rb +1 -0
- data/lib/databasedotcom/rails.rb +3 -0
- data/lib/databasedotcom/rails/controller.rb +54 -0
- data/lib/databasedotcom/rails/version.rb +5 -0
- metadata +92 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Danny Burkes
|
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,75 @@
|
|
1
|
+
# databasedotcom-rails
|
2
|
+
|
3
|
+
Convenience classes to make using the databasedotcom gem with Rails apps even easier
|
4
|
+
|
5
|
+
#Installation
|
6
|
+
gem install databasedotcom-rails
|
7
|
+
or, if you use Bundler
|
8
|
+
|
9
|
+
gem 'databasedotcom-rails'
|
10
|
+
|
11
|
+
# Usage
|
12
|
+
|
13
|
+
* Include `Databasedotcom::Rails::Controller` into your RESTful controller
|
14
|
+
|
15
|
+
* Create a YAML file at RAILS_ROOT/config/databasedotcom.yml file, like so
|
16
|
+
|
17
|
+
---
|
18
|
+
client_id: put-your-client-id-here
|
19
|
+
client_secret: put-your-client-secret-here
|
20
|
+
username: put-your-username-here
|
21
|
+
password: put-your-password-here
|
22
|
+
debugging: true
|
23
|
+
|
24
|
+
* Call `YourModel.coerce_params` before you pass parameters submitted from an HTML form to your materialized Sobject
|
25
|
+
|
26
|
+
# Example
|
27
|
+
|
28
|
+
class UsersController < ApplicationController
|
29
|
+
include Databasedotcom::Rails::Controller
|
30
|
+
before_filter :load_user, :except => [:index, :new]
|
31
|
+
|
32
|
+
def index
|
33
|
+
@users = User.all
|
34
|
+
end
|
35
|
+
|
36
|
+
def show
|
37
|
+
end
|
38
|
+
|
39
|
+
def new
|
40
|
+
@user = User.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def create
|
44
|
+
User.create User.coerce_params(params[:user])
|
45
|
+
flash[:info] = "The user was created!"
|
46
|
+
redirect_to users_path
|
47
|
+
end
|
48
|
+
|
49
|
+
def edit
|
50
|
+
end
|
51
|
+
|
52
|
+
def update
|
53
|
+
@user.update_attributes User.coerce_params(params[:user])
|
54
|
+
flash[:info] = "The user was updated!"
|
55
|
+
redirect_to user_path(@user)
|
56
|
+
end
|
57
|
+
|
58
|
+
def destroy
|
59
|
+
@user.delete
|
60
|
+
flash[:info] = "The user was deleted!"
|
61
|
+
redirect_to users_path
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def load_user
|
67
|
+
@user = User.find(params[:id])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
Note that there is no need to declare the `User` model anywhere- `Databasedotcom::Rails::Controller` recognizes it as a known Sobject type from your database.com instance, and materializes it automatically.
|
72
|
+
|
73
|
+
# License
|
74
|
+
|
75
|
+
databasedotcom-rails is released under the MIT License
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'databasedotcom/rails'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Databasedotcom
|
2
|
+
module Rails
|
3
|
+
module Controller
|
4
|
+
module ClassMethods
|
5
|
+
def dbdc_client
|
6
|
+
unless @dbdc_client
|
7
|
+
config = YAML.load_file(File.join(::Rails.root, 'config', 'databasedotcom.yml'))
|
8
|
+
username = config["username"]
|
9
|
+
password = config["password"]
|
10
|
+
@dbdc_client = Databasedotcom::Client.new(config)
|
11
|
+
@dbdc_client.authenticate(:username => username, :password => password)
|
12
|
+
end
|
13
|
+
|
14
|
+
@dbdc_client
|
15
|
+
end
|
16
|
+
|
17
|
+
def dbdc_client=(client)
|
18
|
+
@dbdc_client = client
|
19
|
+
end
|
20
|
+
|
21
|
+
def sobject_types
|
22
|
+
unless @sobject_types
|
23
|
+
@sobject_types = dbdc_client.list_sobjects
|
24
|
+
end
|
25
|
+
|
26
|
+
@sobject_types
|
27
|
+
end
|
28
|
+
|
29
|
+
def const_missing(sym)
|
30
|
+
if sobject_types.include?(sym.to_s)
|
31
|
+
dbdc_client.materialize(sym.to_s)
|
32
|
+
else
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module InstanceMethods
|
39
|
+
def dbdc_client
|
40
|
+
self.class.dbdc_client
|
41
|
+
end
|
42
|
+
|
43
|
+
def sobject_types
|
44
|
+
self.class.sobject_types
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.included(base)
|
49
|
+
base.send(:include, InstanceMethods)
|
50
|
+
base.send(:extend, ClassMethods)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: databasedotcom-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Danny Burkes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-24 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: databasedotcom
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - "="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.6.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.6
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
description: Convenience classes to make using the databasedotcom gem with Rails apps even easier
|
49
|
+
email:
|
50
|
+
- dburkes@netable.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- README.md
|
59
|
+
- MIT-LICENSE
|
60
|
+
- lib/databasedotcom/rails/controller.rb
|
61
|
+
- lib/databasedotcom/rails/version.rb
|
62
|
+
- lib/databasedotcom/rails.rb
|
63
|
+
- lib/databasedotcom-rails.rb
|
64
|
+
homepage: http://github.com/dburkes/databasedotcom-rails
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Convenience classes to make using the databasedotcom gem with Rails apps even easier
|
91
|
+
test_files: []
|
92
|
+
|