appetizer-activerecord 0.0.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/README.md +30 -0
- data/Rakefile +2 -0
- data/appetizer-activerecord.gemspec +21 -0
- data/lib/appetizer/activerecord.rb +57 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Appetizer ActiveRecord
|
2
|
+
|
3
|
+
An painfully under-documented and opinionated Appetizer extension for
|
4
|
+
initializing ActiveRecord from a `DATABASE_URL` environment
|
5
|
+
variable. Also provides basic transactional support for
|
6
|
+
`Appetizer::Test`.
|
7
|
+
|
8
|
+
## License (MIT)
|
9
|
+
|
10
|
+
Copyright 2011 Audiosocket (tech@audiosocket.com)
|
11
|
+
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
a copy of this software and associated documentation files (the
|
14
|
+
'Software'), to deal in the Software without restriction, including
|
15
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
the following conditions:
|
19
|
+
|
20
|
+
The above copyright notice and this permission notice shall be
|
21
|
+
included in all copies or substantial portions of the Software.
|
22
|
+
|
23
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
26
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
27
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
28
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
29
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Audiosocket"]
|
5
|
+
gem.email = ["tech@audiosocket.com"]
|
6
|
+
gem.description = "An Appetizer extension for ActiveRecord."
|
7
|
+
gem.summary = "Provides connection initialization and test support."
|
8
|
+
gem.homepage = "https://github.com/audiosocket/appetizer-activerecord"
|
9
|
+
|
10
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
gem.name = "appetizer-activerecord"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = "0.0.0"
|
16
|
+
|
17
|
+
gem.required_ruby_version = ">= 1.9.2"
|
18
|
+
|
19
|
+
gem.add_dependency "activerecord", "~> 3.1.2"
|
20
|
+
gem.add_dependency "appetizer", "~> 0.0"
|
21
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
App.on :initializing do
|
2
|
+
require "active_record"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
unless ENV["DATABASE_URL"]
|
6
|
+
App.log.warn "No DATABASE_URL environment variable set."
|
7
|
+
end
|
8
|
+
|
9
|
+
url = URI.parse ENV["DATABASE_URL"]
|
10
|
+
|
11
|
+
cfg = {
|
12
|
+
adapter: url.scheme,
|
13
|
+
database: url.path[1..-1],
|
14
|
+
encoding: "utf8",
|
15
|
+
host: url.host,
|
16
|
+
min_messages: "WARNING",
|
17
|
+
password: url.password,
|
18
|
+
port: url.port,
|
19
|
+
username: url.user
|
20
|
+
}
|
21
|
+
|
22
|
+
case url.scheme
|
23
|
+
when "sqlite"
|
24
|
+
cfg[:adapter] = "sqlite3"
|
25
|
+
cfg[:database] = url.host
|
26
|
+
when "postgres"
|
27
|
+
cfg[:adapter] = "postgresql"
|
28
|
+
end
|
29
|
+
|
30
|
+
ActiveRecord::Base.configurations = { App.env.to_s => cfg }
|
31
|
+
ActiveRecord::Base.logger = App.log
|
32
|
+
|
33
|
+
ActiveRecord::Base.establish_connection App.env
|
34
|
+
end
|
35
|
+
|
36
|
+
if defined? Appetizer::Test
|
37
|
+
class Appetizer::Test
|
38
|
+
module Transactional
|
39
|
+
def run runner
|
40
|
+
result = nil
|
41
|
+
|
42
|
+
ActiveRecord::Base.transaction do
|
43
|
+
result = super
|
44
|
+
raise ActiveRecord::Rollback
|
45
|
+
end
|
46
|
+
|
47
|
+
result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
include Transactional
|
52
|
+
|
53
|
+
setup do
|
54
|
+
ActiveRecord::IdentityMap.clear
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: appetizer-activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Audiosocket
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-10 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: &70225952110740 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70225952110740
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: appetizer
|
27
|
+
requirement: &70225952131520 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70225952131520
|
36
|
+
description: An Appetizer extension for ActiveRecord.
|
37
|
+
email:
|
38
|
+
- tech@audiosocket.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- appetizer-activerecord.gemspec
|
48
|
+
- lib/appetizer/activerecord.rb
|
49
|
+
homepage: https://github.com/audiosocket/appetizer-activerecord
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.9.2
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.11
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Provides connection initialization and test support.
|
73
|
+
test_files: []
|