sequella 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +7 -2
- data/CHANGELOG.md +7 -0
- data/lib/sequella/plugin.rb +39 -26
- data/lib/sequella/service.rb +16 -7
- data/lib/sequella/version.rb +1 -1
- data/spec/sequella/service_spec.rb +36 -4
- metadata +25 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0bdf5e1ab2671f320f5f33765a231801b3a7a3e
|
4
|
+
data.tar.gz: 2969740d19233ce04ba00da1e7e6569bc7ed373a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bc8902ed56d9cb2a6750ecb48f08934a40f2c9e427425eca73d2959d9b5d9391bcf605f1a7b81c4dcf8f8f4b697c0a63bfa9649794ef732d20548d8f5fe21b4
|
7
|
+
data.tar.gz: 7d272f5288b8cd9ba4cd93d0ec35b6343b7a785993cb0d7e5c3f075d50f9670a3e507fe41e5414c0ac560e8950fd14a935db03378e072947b5221f03ab9dfec1
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# develop
|
2
|
+
|
3
|
+
# [1.1.0](https://github.com/bklang/sequella/compare/v1.0.0...v1.1.0) - [2014-01-14](https://rubygems.org/gems/sequella/versions/1.1.0)
|
4
|
+
* Feature: Rake tasks to clean and reset the database
|
5
|
+
* Feature: Automatically use JDBC on JRuby
|
6
|
+
* Cleanup: No more autoloading (or dependency on activesupport)
|
7
|
+
|
1
8
|
# [1.0.0](https://github.com/bklang/sequella/tags/v1.0.0) - [2013-05-20](https://rubygems.org/gems/sequella/versions/1.0.0)
|
2
9
|
|
3
10
|
* Initial release
|
data/lib/sequella/plugin.rb
CHANGED
@@ -1,34 +1,47 @@
|
|
1
1
|
require 'sequel'
|
2
2
|
require 'sequella/service'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
module Sequella
|
5
|
+
class Plugin < Adhearsion::Plugin
|
6
|
+
# Configure a database to use Sequel-backed models.
|
7
|
+
# See http://sequel.rubyforge.org/rdoc/classes/Sequel/Database.html
|
8
|
+
#
|
9
|
+
# MySQL options are preconfigured. If you want o use another adapter, make sure to include the
|
10
|
+
# required options in your configuration file
|
11
|
+
config :sequella do
|
12
|
+
uri '' , :desc => 'URI to the database instance. Use this or specify each piece of connection information separately below.'
|
13
|
+
adapter 'mysql' , :desc => 'Database adapter. It should be an adapter supported by Sequel'
|
14
|
+
database 'test' , :desc => 'Database name'
|
15
|
+
username 'admin' , :desc => 'valid database username'
|
16
|
+
password '' , :desc => 'valid database password'
|
17
|
+
host 'localhost' , :desc => 'host where the database is running'
|
18
|
+
port 3306 , :desc => 'port where the database is listening'
|
19
|
+
model_paths [] , :desc => 'paths to model files to load', :transform => Proc.new {|v| Array(v)}
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
init :sequella do
|
23
|
+
Service.start Adhearsion.config[:sequella]
|
24
|
+
end
|
25
|
+
|
26
|
+
tasks do
|
27
|
+
namespace :sequella do
|
28
|
+
desc "Run Sequel migrations"
|
29
|
+
task :migrate => :environment do
|
30
|
+
Service.start Adhearsion.config[:sequella]
|
31
|
+
Sequel.extension :migration
|
32
|
+
Sequel::Migrator.run Sequella::Service.connection, File.join(Adhearsion.root, 'db', 'migrations'), :use_transactions => true
|
33
|
+
puts "Successfully migrated database"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Drop all tables in the database"
|
37
|
+
task :clean => :environment do
|
38
|
+
Service.start Adhearsion.config[:sequella]
|
39
|
+
Service.connection.tables.each { |t| Service.connection.drop_table t }
|
40
|
+
logger.info "Successfully dropped all tables in the database"
|
41
|
+
end
|
23
42
|
|
24
|
-
|
25
|
-
|
26
|
-
desc "Run Sequel migrations"
|
27
|
-
task :migrate => :environment do
|
28
|
-
Service.start Adhearsion.config[:sequella]
|
29
|
-
Sequel.extension :migration
|
30
|
-
Sequel::Migrator.run Sequella::Service.connection, File.join(Adhearsion.root, 'db', 'migrations'), :use_transactions=>true
|
31
|
-
puts "Successfully migrated database"
|
43
|
+
desc "clean and then migrate"
|
44
|
+
task :reset => [:clean, :migrate]
|
32
45
|
end
|
33
46
|
end
|
34
47
|
end
|
data/lib/sequella/service.rb
CHANGED
@@ -3,15 +3,12 @@ module Sequella
|
|
3
3
|
cattr_accessor :connection
|
4
4
|
|
5
5
|
class << self
|
6
|
-
|
7
6
|
##
|
8
7
|
# Start the Sequel connection with the configured database
|
9
8
|
def start(config)
|
10
|
-
|
11
|
-
|
12
|
-
params = config.to_hash.select { |k,v| !v.nil? }
|
9
|
+
params = config.to_hash.select { |k, v| !v.nil? }
|
13
10
|
|
14
|
-
@@connection = establish_connection params
|
11
|
+
@@connection = establish_connection connection_string(params)
|
15
12
|
require_models(*params.delete(:model_paths))
|
16
13
|
|
17
14
|
# Provide Sequel a handle on the Adhearsion logger
|
@@ -54,9 +51,21 @@ module Sequella
|
|
54
51
|
##
|
55
52
|
# Start the Sequel connection with the configured database
|
56
53
|
#
|
54
|
+
# @param connection_uri [String] Connection URI for connecting to the database
|
55
|
+
def establish_connection(connection_uri)
|
56
|
+
logger.info "Sequella connecting: #{connection_uri}"
|
57
|
+
::Sequel.connect connection_uri
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Construct the database connection string for Sequel
|
62
|
+
#
|
57
63
|
# @param params [Hash] Options to establish the database connection
|
58
|
-
def
|
59
|
-
|
64
|
+
def connection_string(params)
|
65
|
+
return params[:uri] unless params[:uri].blank?
|
66
|
+
raise "Must supply an adapter argument to the Sequel configuration" if params[:adapter].blank?
|
67
|
+
|
68
|
+
"#{params[:adapter]}://#{params[:username]}:#{params[:password]}@#{params[:host]}:#{params[:port]}/#{params[:database]}"
|
60
69
|
end
|
61
70
|
|
62
71
|
end # class << self
|
data/lib/sequella/version.rb
CHANGED
@@ -2,12 +2,44 @@ require 'spec_helper'
|
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
4
|
describe Sequella::Service do
|
5
|
-
subject {
|
5
|
+
subject { described_class }
|
6
6
|
|
7
7
|
describe '#start' do
|
8
|
-
it 'should raise if start attempted
|
9
|
-
config = OpenStruct.new
|
10
|
-
|
8
|
+
it 'should not raise an error if start attempted with a uri specified' do
|
9
|
+
config = OpenStruct.new uri: 'postgres://user:password@localhost/blog'
|
10
|
+
subject.should_receive(:establish_connection).with(config.uri)
|
11
|
+
subject.should_receive(:require_models)
|
12
|
+
|
13
|
+
expect { subject.start config.marshal_dump }.to_not raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#connection_string' do
|
18
|
+
it 'should use uri if specified in params' do
|
19
|
+
params = { uri: 'this-is-a-connection-uri' }
|
20
|
+
|
21
|
+
connection_string = subject.connection_string params
|
22
|
+
expect(connection_string).to eq(params[:uri])
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should raise error if adapter is not specified' do
|
26
|
+
params = { }
|
27
|
+
|
28
|
+
expect { subject.connection_string(params) }.to raise_error 'Must supply an adapter argument to the Sequel configuration'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should build successfully' do
|
32
|
+
connection_params = {
|
33
|
+
adapter: 'postgres',
|
34
|
+
host: 'localhost',
|
35
|
+
port: 5432,
|
36
|
+
database: 'test',
|
37
|
+
username: 'test-user',
|
38
|
+
password: 'password'
|
39
|
+
}
|
40
|
+
|
41
|
+
connection_string = subject.connection_string connection_params
|
42
|
+
expect(connection_string).to eq('postgres://test-user:password@localhost:5432/test')
|
11
43
|
end
|
12
44
|
end
|
13
45
|
|
metadata
CHANGED
@@ -1,139 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequella
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Klang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: adhearsion
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sequel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 3.40.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.40.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.5'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: mocha
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: guard-rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: simplecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: simplecov-rcov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
description: This gem provides a plugin for Adhearsion, allowing you to create and
|
@@ -144,8 +144,8 @@ executables: []
|
|
144
144
|
extensions: []
|
145
145
|
extra_rdoc_files: []
|
146
146
|
files:
|
147
|
-
- .gitignore
|
148
|
-
- .travis.yml
|
147
|
+
- ".gitignore"
|
148
|
+
- ".travis.yml"
|
149
149
|
- CHANGELOG.md
|
150
150
|
- Gemfile
|
151
151
|
- README.md
|
@@ -167,17 +167,17 @@ require_paths:
|
|
167
167
|
- lib
|
168
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
|
-
- -
|
170
|
+
- - ">="
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
174
|
requirements:
|
175
|
-
- -
|
175
|
+
- - ">="
|
176
176
|
- !ruby/object:Gem::Version
|
177
177
|
version: '0'
|
178
178
|
requirements: []
|
179
179
|
rubyforge_project: sequella
|
180
|
-
rubygems_version: 2.0
|
180
|
+
rubygems_version: 2.2.0
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: Sequel ORM plugin for Adhearsion
|