nulogy-sequel-rails 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +29 -0
- data/Gemfile +3 -0
- data/History.md +77 -0
- data/LICENSE +20 -0
- data/README.rdoc +102 -0
- data/Rakefile +9 -0
- data/lib/rails/generators/sequel/active_model.rb +39 -0
- data/lib/rails/generators/sequel/base.rb +26 -0
- data/lib/rails/generators/sequel/generated_attribute_ext.rb +9 -0
- data/lib/rails/generators/sequel/migration/migration_generator.rb +43 -0
- data/lib/rails/generators/sequel/migration/templates/migration.rb +48 -0
- data/lib/rails/generators/sequel/model/model_generator.rb +28 -0
- data/lib/rails/generators/sequel/model/templates/migration.rb +14 -0
- data/lib/rails/generators/sequel/model/templates/model.rb +6 -0
- data/lib/rails/generators/sequel/observer/observer_generator.rb +16 -0
- data/lib/rails/generators/sequel/observer/templates/observer.rb +4 -0
- data/lib/rails/generators/sequel.rb +9 -0
- data/lib/sequel/plugins/rails_extensions.rb +25 -0
- data/lib/sequel/rails/configuration.rb +56 -0
- data/lib/sequel/rails/core.rb +50 -0
- data/lib/sequel/rails/ext.rb +25 -0
- data/lib/sequel/rails/log_subscriber.rb +71 -0
- data/lib/sequel/rails/migrations.rb +22 -0
- data/lib/sequel/rails/railtie.rb +76 -0
- data/lib/sequel/rails/railties/controller_runtime.rb +48 -0
- data/lib/sequel/rails/railties/database.rake +185 -0
- data/lib/sequel/rails/railties/i18n_support.rb +9 -0
- data/lib/sequel/rails/session_store.rb +69 -0
- data/lib/sequel/rails/setup.rb +14 -0
- data/lib/sequel/rails/storage.rb +225 -0
- data/lib/sequel/rails/version.rb +6 -0
- data/lib/sequel/rails.rb +26 -0
- data/lib/sequel-rails.rb +2 -0
- data/nulogy-sequel-rails.gemspec +19 -0
- metadata +101 -0
@@ -0,0 +1,225 @@
|
|
1
|
+
|
2
|
+
# TODO: Review this class, document
|
3
|
+
|
4
|
+
module Sequel
|
5
|
+
module Rails
|
6
|
+
|
7
|
+
def self.storage
|
8
|
+
Storage
|
9
|
+
end
|
10
|
+
|
11
|
+
class Storage
|
12
|
+
attr_reader :config
|
13
|
+
|
14
|
+
def self.create_all
|
15
|
+
with_local_repositories { |config| create_environment(config) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.drop_all
|
19
|
+
with_local_repositories { |config| drop_environment(config) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.create_environment(config)
|
23
|
+
new(config).create
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.drop_environment(config)
|
27
|
+
new(config).drop
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.new(config)
|
31
|
+
config = Sequel::Rails.configuration.db_config_for(config) unless config.kind_of?(Hash)
|
32
|
+
|
33
|
+
klass = lookup_class(config['adapter'])
|
34
|
+
if klass.equal?(self)
|
35
|
+
super(config)
|
36
|
+
else
|
37
|
+
klass.new(config)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class << self
|
42
|
+
private
|
43
|
+
|
44
|
+
def with_local_repositories
|
45
|
+
Sequel::Rails.configuration.db_environments.each_value do |config|
|
46
|
+
next if config['database'].blank?
|
47
|
+
if config['host'].blank? || %w[ 127.0.0.1 localhost ].include?(config['host'])
|
48
|
+
yield(config)
|
49
|
+
else
|
50
|
+
puts "This task only modifies local databases. #{config['database']} is on a remote host."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def lookup_class(adapter)
|
56
|
+
klass_name = adapter.camelize.to_sym
|
57
|
+
|
58
|
+
unless Storage.const_defined?(klass_name)
|
59
|
+
raise "Adapter #{adapter} not supported (#{klass_name.inspect})"
|
60
|
+
end
|
61
|
+
|
62
|
+
const_get(klass_name)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
def initialize(config)
|
68
|
+
@config = config
|
69
|
+
end
|
70
|
+
|
71
|
+
def create
|
72
|
+
_create
|
73
|
+
puts "[sequel] Created database '#{database}'"
|
74
|
+
end
|
75
|
+
|
76
|
+
def drop
|
77
|
+
Sequel::Model.db.disconnect
|
78
|
+
_drop
|
79
|
+
puts "[sequel] Dropped database '#{database}'"
|
80
|
+
end
|
81
|
+
|
82
|
+
def database
|
83
|
+
@database ||= config['database'] || config['path']
|
84
|
+
end
|
85
|
+
|
86
|
+
def username
|
87
|
+
@username ||= config['username'] || config['user'] || ''
|
88
|
+
end
|
89
|
+
|
90
|
+
def password
|
91
|
+
@password ||= config['password'] || ''
|
92
|
+
end
|
93
|
+
|
94
|
+
def host
|
95
|
+
@host ||= config['host'] || ''
|
96
|
+
end
|
97
|
+
|
98
|
+
def port
|
99
|
+
@port ||= config['port'] || ''
|
100
|
+
end
|
101
|
+
|
102
|
+
def owner
|
103
|
+
@owner ||= config['owner'] || ''
|
104
|
+
end
|
105
|
+
|
106
|
+
def charset
|
107
|
+
@charset ||= config['charset'] || ENV['CHARSET'] || 'utf8'
|
108
|
+
end
|
109
|
+
|
110
|
+
class Sqlite < Storage
|
111
|
+
def _create
|
112
|
+
return if in_memory?
|
113
|
+
Sequel.connect(config.merge('database' => path))
|
114
|
+
end
|
115
|
+
|
116
|
+
def _drop
|
117
|
+
return if in_memory?
|
118
|
+
path.unlink if path.file?
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def in_memory?
|
124
|
+
database == ':memory:'
|
125
|
+
end
|
126
|
+
|
127
|
+
def path
|
128
|
+
@path ||= Pathname(File.expand_path(database, ::Rails.root))
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
class Mysql < Storage
|
134
|
+
def _create
|
135
|
+
execute("CREATE DATABASE IF NOT EXISTS `#{database}` DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}")
|
136
|
+
end
|
137
|
+
|
138
|
+
def _drop
|
139
|
+
execute("DROP DATABASE IF EXISTS `#{database}`")
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def execute(statement)
|
145
|
+
commands = ["mysql"]
|
146
|
+
commands << "--user" << username unless username.blank?
|
147
|
+
commands << "--password=#{password}" unless password.blank?
|
148
|
+
commands << "--host" << host unless host.blank?
|
149
|
+
commands << "-e" << statement
|
150
|
+
system(*commands)
|
151
|
+
end
|
152
|
+
|
153
|
+
def collation
|
154
|
+
@collation ||= config['collation'] || ENV['COLLATION'] || 'utf8_unicode_ci'
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
class Mysql2 < Mysql
|
159
|
+
end
|
160
|
+
|
161
|
+
class Postgres < Storage
|
162
|
+
def _create
|
163
|
+
ENV["PGPASSWORD"] = password unless password.blank?
|
164
|
+
commands = ["createdb", "--encoding", charset]
|
165
|
+
commands << "--username" << username unless username.blank?
|
166
|
+
commands << "--owner" << owner unless owner.blank?
|
167
|
+
commands << "--port" << port unless port.blank?
|
168
|
+
commands << "--host" << host unless host.blank?
|
169
|
+
commands << database
|
170
|
+
res = system(*commands)
|
171
|
+
ENV["PGPASSWORD"] = nil
|
172
|
+
res
|
173
|
+
end
|
174
|
+
|
175
|
+
def _drop
|
176
|
+
system("dropdb", "-U", username, database)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
class Jdbc < Storage
|
181
|
+
|
182
|
+
def _is_mysql?
|
183
|
+
database.match(/^jdbc:mysql/)
|
184
|
+
end
|
185
|
+
|
186
|
+
def _root_url
|
187
|
+
database.scan /^jdbc:mysql:\/\/\w*:?\d*/
|
188
|
+
end
|
189
|
+
|
190
|
+
def db_name
|
191
|
+
database.scan(/^jdbc:mysql:\/\/\w+:?\d*\/(\w+)/).flatten.first
|
192
|
+
end
|
193
|
+
|
194
|
+
def _params
|
195
|
+
database.scan /\?.*$/
|
196
|
+
end
|
197
|
+
|
198
|
+
def _create
|
199
|
+
if _is_mysql?
|
200
|
+
Sequel.connect("#{_root_url}#{_params}") do |db|
|
201
|
+
db.execute("CREATE DATABASE IF NOT EXISTS `#{db_name}` DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}")
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def _drop
|
207
|
+
if _is_mysql?
|
208
|
+
Sequel.connect("#{_root_url}#{_params}") do |db|
|
209
|
+
db.execute("DROP DATABASE IF EXISTS `#{db_name}`")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
def collation
|
217
|
+
@collation ||= config['collation'] || ENV['COLLATION'] || 'utf8_unicode_ci'
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
data/lib/sequel/rails.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('../rails/core', __FILE__)
|
3
|
+
|
4
|
+
module Sequel::Rails
|
5
|
+
def self.configuration
|
6
|
+
Configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.connect(environment)
|
10
|
+
@db = Sequel.connect(configuration.db_config_for(environment))
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.db
|
14
|
+
@db
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.connected?
|
18
|
+
!!@db
|
19
|
+
end
|
20
|
+
|
21
|
+
require libpath('sequel/rails/ext')
|
22
|
+
require libpath('sequel/rails/configuration')
|
23
|
+
require libpath('sequel/rails/log_subscriber')
|
24
|
+
require libpath('sequel/rails/railtie')
|
25
|
+
end
|
26
|
+
|
data/lib/sequel-rails.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/sequel/rails/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "nulogy-sequel-rails"
|
7
|
+
s.version = Sequel::Rails.version
|
8
|
+
s.authors = ["Brasten Sager (brasten)", "Jonathan TRON", "Elliot Winkler", "Nulogy"]
|
9
|
+
s.email = ["brasten@gmail.com", "jonathan.tron@thetalentbox.com", "elliot.winkler@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/nulogy/sequel-rails"
|
11
|
+
s.description = "Ruby gem for integrating Sequel with your Rails 3 app"
|
12
|
+
s.summary = "Ruby gem for integrating Sequel with your Rails 3 app"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_runtime_dependency("sequel", ["~> 3.28"])
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nulogy-sequel-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.8
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brasten Sager (brasten)
|
9
|
+
- Jonathan TRON
|
10
|
+
- Elliot Winkler
|
11
|
+
- Nulogy
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
date: 2012-09-19 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: sequel
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '3.28'
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.28'
|
33
|
+
description: Ruby gem for integrating Sequel with your Rails 3 app
|
34
|
+
email:
|
35
|
+
- brasten@gmail.com
|
36
|
+
- jonathan.tron@thetalentbox.com
|
37
|
+
- elliot.winkler@gmail.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- .document
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- History.md
|
46
|
+
- LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
- Rakefile
|
49
|
+
- lib/rails/generators/sequel.rb
|
50
|
+
- lib/rails/generators/sequel/active_model.rb
|
51
|
+
- lib/rails/generators/sequel/base.rb
|
52
|
+
- lib/rails/generators/sequel/generated_attribute_ext.rb
|
53
|
+
- lib/rails/generators/sequel/migration/migration_generator.rb
|
54
|
+
- lib/rails/generators/sequel/migration/templates/migration.rb
|
55
|
+
- lib/rails/generators/sequel/model/model_generator.rb
|
56
|
+
- lib/rails/generators/sequel/model/templates/migration.rb
|
57
|
+
- lib/rails/generators/sequel/model/templates/model.rb
|
58
|
+
- lib/rails/generators/sequel/observer/observer_generator.rb
|
59
|
+
- lib/rails/generators/sequel/observer/templates/observer.rb
|
60
|
+
- lib/sequel-rails.rb
|
61
|
+
- lib/sequel/plugins/rails_extensions.rb
|
62
|
+
- lib/sequel/rails.rb
|
63
|
+
- lib/sequel/rails/configuration.rb
|
64
|
+
- lib/sequel/rails/core.rb
|
65
|
+
- lib/sequel/rails/ext.rb
|
66
|
+
- lib/sequel/rails/log_subscriber.rb
|
67
|
+
- lib/sequel/rails/migrations.rb
|
68
|
+
- lib/sequel/rails/railtie.rb
|
69
|
+
- lib/sequel/rails/railties/controller_runtime.rb
|
70
|
+
- lib/sequel/rails/railties/database.rake
|
71
|
+
- lib/sequel/rails/railties/i18n_support.rb
|
72
|
+
- lib/sequel/rails/session_store.rb
|
73
|
+
- lib/sequel/rails/setup.rb
|
74
|
+
- lib/sequel/rails/storage.rb
|
75
|
+
- lib/sequel/rails/version.rb
|
76
|
+
- nulogy-sequel-rails.gemspec
|
77
|
+
homepage: https://github.com/nulogy/sequel-rails
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.24
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Ruby gem for integrating Sequel with your Rails 3 app
|
101
|
+
test_files: []
|