sequel-rails 0.1.8 → 0.4.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/.travis.yml +12 -0
- data/Gemfile +13 -16
- data/History.md +142 -0
- data/README.md +124 -0
- data/Rakefile +6 -30
- data/config.ru +7 -0
- data/lib/generators/sequel.rb +11 -8
- data/lib/generators/sequel/migration/migration_generator.rb +36 -11
- data/lib/generators/sequel/migration/templates/migration.rb.erb +48 -0
- data/lib/generators/sequel/model/model_generator.rb +8 -2
- data/lib/generators/sequel/model/templates/migration.rb.erb +16 -0
- data/lib/generators/sequel/model/templates/{model.rb → model.rb.erb} +4 -1
- data/lib/generators/sequel/observer/observer_generator.rb +2 -2
- data/lib/generators/sequel/observer/templates/{observer.rb → observer.rb.erb} +0 -0
- data/lib/sequel-rails.rb +1 -1
- data/lib/sequel_rails.rb +2 -0
- data/lib/sequel_rails/configuration.rb +64 -0
- data/lib/sequel_rails/migrations.rb +22 -0
- data/lib/sequel_rails/railtie.rb +94 -0
- data/lib/sequel_rails/railties/controller_runtime.rb +40 -0
- data/lib/sequel_rails/railties/database.rake +175 -0
- data/lib/sequel_rails/railties/i18n_support.rb +10 -0
- data/lib/sequel_rails/railties/log_subscriber.rb +56 -0
- data/lib/sequel_rails/sequel/database/active_support_notification.rb +28 -0
- data/lib/sequel_rails/sequel/plugins/rails_extensions.rb +35 -0
- data/lib/sequel_rails/session_store.rb +80 -0
- data/lib/sequel_rails/storage.rb +58 -0
- data/lib/sequel_rails/storage/abstract.rb +52 -0
- data/lib/sequel_rails/storage/jdbc.rb +45 -0
- data/lib/sequel_rails/storage/mysql.rb +31 -0
- data/lib/sequel_rails/storage/mysql2.rb +6 -0
- data/lib/sequel_rails/storage/postgres.rb +22 -0
- data/lib/sequel_rails/storage/sqlite.rb +26 -0
- data/lib/sequel_rails/version.rb +3 -0
- data/sequel-rails.gemspec +22 -86
- data/spec/internal/app/models/user.rb +2 -0
- data/spec/internal/config/database.yml +7 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/schema.rb +8 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/lib/generators/sequel/migration_spec.rb +256 -0
- data/spec/lib/sequel_rails/railtie_spec.rb +85 -0
- data/spec/lib/sequel_rails/railties/log_subscriber_spec.rb +29 -0
- data/spec/lib/sequel_rails/storage_spec.rb +108 -0
- data/spec/spec_helper.rb +30 -16
- data/tasks/spec.rake +63 -29
- metadata +194 -142
- data/CHANGELOG +0 -15
- data/README.rdoc +0 -86
- data/VERSION +0 -1
- data/autotest/discover.rb +0 -1
- data/lib/generators/sequel/migration/templates/migration.rb +0 -16
- data/lib/sequel-rails/configuration.rb +0 -61
- data/lib/sequel-rails/migrations.rb +0 -30
- data/lib/sequel-rails/railtie.rb +0 -90
- data/lib/sequel-rails/railties/benchmarking_mixin.rb +0 -23
- data/lib/sequel-rails/railties/controller_runtime.rb +0 -43
- data/lib/sequel-rails/railties/database.rake +0 -148
- data/lib/sequel-rails/railties/i18n_support.rb +0 -12
- data/lib/sequel-rails/railties/log_subscriber.rb +0 -31
- data/lib/sequel-rails/runtime.rb +0 -14
- data/lib/sequel-rails/session_store.rb +0 -82
- data/lib/sequel-rails/setup.rb +0 -19
- data/lib/sequel-rails/storage.rb +0 -210
- data/spec/rcov.opts +0 -6
- data/spec/setup_spec.rb +0 -7
- data/spec/spec.opts +0 -4
- data/tasks/ci.rake +0 -1
- data/tasks/clean.rake +0 -6
- data/tasks/metrics.rake +0 -37
- data/tasks/yard.rake +0 -9
- data/tasks/yardstick.rake +0 -20
@@ -1,31 +0,0 @@
|
|
1
|
-
module Sequel
|
2
|
-
module Railties
|
3
|
-
|
4
|
-
class LogSubscriber < ActiveSupport::LogSubscriber
|
5
|
-
|
6
|
-
def sql(event)
|
7
|
-
name = '%s (%.1fms)' % [event.payload[:name], event.duration]
|
8
|
-
sql = event.payload[:sql].squeeze(' ')
|
9
|
-
|
10
|
-
if odd?
|
11
|
-
name = color(name, :cyan, true)
|
12
|
-
sql = color(sql, nil, true)
|
13
|
-
else
|
14
|
-
name = color(name, :magenta, true)
|
15
|
-
end
|
16
|
-
|
17
|
-
debug " #{name} #{sql}"
|
18
|
-
end
|
19
|
-
|
20
|
-
def odd?
|
21
|
-
@odd_or_even = !@odd_or_even
|
22
|
-
end
|
23
|
-
|
24
|
-
def logger
|
25
|
-
::Rails::Sequel.configuration.logger
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
data/lib/sequel-rails/runtime.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'sequel'
|
2
|
-
|
3
|
-
# Implements Sequel-specific session store.
|
4
|
-
|
5
|
-
module Rails
|
6
|
-
module Sequel
|
7
|
-
|
8
|
-
class SessionStore < ActionDispatch::Session::AbstractStore
|
9
|
-
|
10
|
-
class Session < ::Sequel::Model
|
11
|
-
|
12
|
-
# property :id, Serial
|
13
|
-
# property :session_id, String, :required => true, :unique => true, :unique_index => true
|
14
|
-
# property :data, Object, :required => true, :default => ActiveSupport::Base64.encode64(Marshal.dump({}))
|
15
|
-
# property :updated_at, DateTime, :required => false, :index => true
|
16
|
-
|
17
|
-
class << self
|
18
|
-
|
19
|
-
def auto_migrate!
|
20
|
-
self.db.create_table :sessions do
|
21
|
-
primary_key :id
|
22
|
-
column :session_id, String,
|
23
|
-
:null => false,
|
24
|
-
:unique => true,
|
25
|
-
:index => true
|
26
|
-
|
27
|
-
column :data, :text,
|
28
|
-
:null => false
|
29
|
-
|
30
|
-
column :updated_at, DateTime,
|
31
|
-
:null => true,
|
32
|
-
:index => true
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.name
|
39
|
-
'session'
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
SESSION_RECORD_KEY = 'rack.session.record'.freeze
|
45
|
-
|
46
|
-
cattr_accessor :session_class
|
47
|
-
self.session_class = Session
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def get_session(env, sid)
|
52
|
-
sid ||= generate_sid
|
53
|
-
session = find_session(sid)
|
54
|
-
env[SESSION_RECORD_KEY] = session
|
55
|
-
[ sid, session.data ]
|
56
|
-
end
|
57
|
-
|
58
|
-
def set_session(env, sid, session_data)
|
59
|
-
session = get_session_resource(env, sid)
|
60
|
-
session.data = session_data
|
61
|
-
session.updated_at = Time.now if session.dirty?
|
62
|
-
session.save
|
63
|
-
end
|
64
|
-
|
65
|
-
def get_session_resource(env, sid)
|
66
|
-
if env[ENV_SESSION_OPTIONS_KEY][:id].nil?
|
67
|
-
env[SESSION_RECORD_KEY] = find_session(sid)
|
68
|
-
else
|
69
|
-
env[SESSION_RECORD_KEY] ||= find_session(sid)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def find_session(sid)
|
74
|
-
klass = self.class.session_class
|
75
|
-
|
76
|
-
klass.where(:session_id => sid).first || klass.new(:session_id => sid)
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
data/lib/sequel-rails/setup.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/except'
|
2
|
-
|
3
|
-
require 'sequel/extensions/migration'
|
4
|
-
|
5
|
-
require 'sequel-rails/configuration'
|
6
|
-
require 'sequel-rails/runtime'
|
7
|
-
require 'sequel-rails/railties/benchmarking_mixin'
|
8
|
-
|
9
|
-
module Rails
|
10
|
-
module Sequel
|
11
|
-
|
12
|
-
def self.setup(environment)
|
13
|
-
puts "[sequel] Setting up the #{environment.inspect} environment:"
|
14
|
-
|
15
|
-
::Sequel.connect({:logger => configuration.logger}.merge(::Rails::Sequel.configuration.environment_for(environment.to_s)))
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
data/lib/sequel-rails/storage.rb
DELETED
@@ -1,210 +0,0 @@
|
|
1
|
-
module Rails
|
2
|
-
module Sequel
|
3
|
-
|
4
|
-
def self.storage
|
5
|
-
Storage
|
6
|
-
end
|
7
|
-
|
8
|
-
class Storage
|
9
|
-
attr_reader :config
|
10
|
-
|
11
|
-
def self.create_all
|
12
|
-
with_local_repositories { |config| create_environment(config) }
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.drop_all
|
16
|
-
with_local_repositories { |config| drop_environment(config) }
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.create_environment(config)
|
20
|
-
new(config).create
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.drop_environment(config)
|
24
|
-
new(config).drop
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.new(config)
|
28
|
-
config = Rails::Sequel.configuration.environments[config.to_s] unless config.kind_of?(Hash)
|
29
|
-
|
30
|
-
klass = lookup_class(config['adapter'])
|
31
|
-
if klass.equal?(self)
|
32
|
-
super(config)
|
33
|
-
else
|
34
|
-
klass.new(config)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class << self
|
39
|
-
private
|
40
|
-
|
41
|
-
def with_local_repositories
|
42
|
-
Rails::Sequel.configuration.environments.each_value do |config|
|
43
|
-
if config['host'].blank? || %w[ 127.0.0.1 localhost ].include?(config['host'])
|
44
|
-
yield(config)
|
45
|
-
else
|
46
|
-
puts "This task only modifies local databases. #{config['database']} is on a remote host."
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def lookup_class(adapter)
|
52
|
-
klass_name = adapter.camelize.to_sym
|
53
|
-
|
54
|
-
unless Storage.const_defined?(klass_name)
|
55
|
-
raise "Adapter #{adapter} not supported (#{klass_name.inspect})"
|
56
|
-
end
|
57
|
-
|
58
|
-
const_get(klass_name)
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
def initialize(config)
|
64
|
-
@config = config
|
65
|
-
end
|
66
|
-
|
67
|
-
def create
|
68
|
-
_create
|
69
|
-
puts "[sequel] Created database '#{database}'"
|
70
|
-
end
|
71
|
-
|
72
|
-
def drop
|
73
|
-
_drop
|
74
|
-
puts "[sequel] Dropped database '#{database}'"
|
75
|
-
end
|
76
|
-
|
77
|
-
def database
|
78
|
-
@database ||= config['database'] || config['path']
|
79
|
-
end
|
80
|
-
|
81
|
-
def username
|
82
|
-
@username ||= config['username'] || ''
|
83
|
-
end
|
84
|
-
|
85
|
-
def password
|
86
|
-
@password ||= config['password'] || ''
|
87
|
-
end
|
88
|
-
|
89
|
-
def charset
|
90
|
-
@charset ||= config['charset'] || ENV['CHARSET'] || 'utf8'
|
91
|
-
end
|
92
|
-
|
93
|
-
class Sqlite < Storage
|
94
|
-
def _create
|
95
|
-
return if in_memory?
|
96
|
-
::Sequel.connect(config.merge('database' => path))
|
97
|
-
end
|
98
|
-
|
99
|
-
def _drop
|
100
|
-
return if in_memory?
|
101
|
-
path.unlink if path.file?
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def in_memory?
|
107
|
-
database == ':memory:'
|
108
|
-
end
|
109
|
-
|
110
|
-
def path
|
111
|
-
@path ||= Pathname(File.expand_path(database, Rails.root))
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
class Mysql < Storage
|
117
|
-
def _create
|
118
|
-
execute("CREATE DATABASE IF NOT EXISTS `#{database}` DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}")
|
119
|
-
end
|
120
|
-
|
121
|
-
def _drop
|
122
|
-
execute("DROP DATABASE IF EXISTS `#{database}`")
|
123
|
-
end
|
124
|
-
|
125
|
-
private
|
126
|
-
|
127
|
-
def execute(statement)
|
128
|
-
system(
|
129
|
-
'mysql',
|
130
|
-
(username.blank? ? '' : "--user=#{username}"),
|
131
|
-
(password.blank? ? '' : "--password=#{password}"),
|
132
|
-
'-e',
|
133
|
-
statement
|
134
|
-
)
|
135
|
-
end
|
136
|
-
|
137
|
-
def collation
|
138
|
-
@collation ||= config['collation'] || ENV['COLLATION'] || 'utf8_unicode_ci'
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
class Postgres < Storage
|
144
|
-
def _create
|
145
|
-
system(
|
146
|
-
'createdb',
|
147
|
-
'-E',
|
148
|
-
charset,
|
149
|
-
'-U',
|
150
|
-
username,
|
151
|
-
database
|
152
|
-
)
|
153
|
-
end
|
154
|
-
|
155
|
-
def _drop
|
156
|
-
system(
|
157
|
-
'dropdb',
|
158
|
-
'-U',
|
159
|
-
username,
|
160
|
-
database
|
161
|
-
)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
class Jdbc < Storage
|
166
|
-
|
167
|
-
def _is_mysql?
|
168
|
-
database.match(/^jdbc:mysql/)
|
169
|
-
end
|
170
|
-
|
171
|
-
def _root_url
|
172
|
-
database.scan /^jdbc:mysql:\/\/\w*:?\d*/
|
173
|
-
end
|
174
|
-
|
175
|
-
def db_name
|
176
|
-
database.scan(/^jdbc:mysql:\/\/\w+:?\d*\/(\w+)/).flatten.first
|
177
|
-
end
|
178
|
-
|
179
|
-
def _params
|
180
|
-
database.scan /\?.*$/
|
181
|
-
end
|
182
|
-
|
183
|
-
def _create
|
184
|
-
if _is_mysql?
|
185
|
-
::Sequel.connect("#{_root_url}#{_params}") do |db|
|
186
|
-
db.execute("CREATE DATABASE IF NOT EXISTS `#{db_name}` DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}")
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
def _drop
|
192
|
-
if _is_mysql?
|
193
|
-
::Sequel.connect("#{_root_url}#{_params}") do |db|
|
194
|
-
db.execute("DROP DATABASE IF EXISTS `#{db_name}`")
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
private
|
200
|
-
|
201
|
-
def collation
|
202
|
-
@collation ||= config['collation'] || ENV['COLLATION'] || 'utf8_unicode_ci'
|
203
|
-
end
|
204
|
-
|
205
|
-
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
data/spec/rcov.opts
DELETED
data/spec/setup_spec.rb
DELETED
data/spec/spec.opts
DELETED
data/tasks/ci.rake
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
task :ci => [ 'metrics:all' ]
|
data/tasks/clean.rake
DELETED
data/tasks/metrics.rake
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'metric_fu'
|
3
|
-
rescue LoadError
|
4
|
-
namespace :metrics do
|
5
|
-
task :all do
|
6
|
-
abort 'metric_fu is not available. In order to run metrics:all, you must: gem install metric_fu'
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
begin
|
12
|
-
require 'reek/adapters/rake_task'
|
13
|
-
|
14
|
-
Reek::RakeTask.new do |t|
|
15
|
-
t.fail_on_error = true
|
16
|
-
t.verbose = false
|
17
|
-
t.source_files = 'lib/**/*.rb'
|
18
|
-
end
|
19
|
-
rescue LoadError
|
20
|
-
task :reek do
|
21
|
-
abort 'Reek is not available. In order to run reek, you must: gem install reek'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
begin
|
26
|
-
require 'roodi'
|
27
|
-
require 'rake/tasklib'
|
28
|
-
require 'roodi_task'
|
29
|
-
|
30
|
-
RoodiTask.new do |t|
|
31
|
-
t.verbose = false
|
32
|
-
end
|
33
|
-
rescue LoadError
|
34
|
-
task :roodi do
|
35
|
-
abort 'Roodi is not available. In order to run roodi, you must: gem install roodi'
|
36
|
-
end
|
37
|
-
end
|