sequel-rails 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +13 -0
  4. data/.travis.yml +15 -43
  5. data/Gemfile +10 -10
  6. data/History.md +8 -0
  7. data/README.md +36 -0
  8. data/Rakefile +70 -2
  9. data/ci/rails-3.2.gemfile +15 -12
  10. data/ci/rails-4.0.gemfile +12 -12
  11. data/config.ru +1 -1
  12. data/lib/generators/sequel/migration/migration_generator.rb +10 -13
  13. data/lib/generators/sequel/model/model_generator.rb +11 -9
  14. data/lib/generators/sequel/observer/observer_generator.rb +6 -7
  15. data/lib/generators/sequel/session_migration/session_migration_generator.rb +30 -0
  16. data/lib/generators/sequel/session_migration/templates/migration.rb.erb +10 -0
  17. data/lib/generators/sequel.rb +9 -13
  18. data/lib/sequel-rails.rb +1 -1
  19. data/lib/sequel_rails/configuration.rb +29 -35
  20. data/lib/sequel_rails/migrations.rb +4 -4
  21. data/lib/sequel_rails/railtie.rb +16 -20
  22. data/lib/sequel_rails/railties/controller_runtime.rb +2 -8
  23. data/lib/sequel_rails/railties/database.rake +42 -46
  24. data/lib/sequel_rails/railties/i18n_support.rb +0 -2
  25. data/lib/sequel_rails/railties/legacy_model_config.rb +1 -1
  26. data/lib/sequel_rails/railties/log_subscriber.rb +5 -9
  27. data/lib/sequel_rails/sequel/database/active_support_notification.rb +4 -6
  28. data/lib/sequel_rails/sequel/plugins/rails_extensions.rb +2 -3
  29. data/lib/sequel_rails/session_store.rb +6 -42
  30. data/lib/sequel_rails/shellwords.rb +3 -3
  31. data/lib/sequel_rails/storage/abstract.rb +14 -16
  32. data/lib/sequel_rails/storage/jdbc.rb +8 -10
  33. data/lib/sequel_rails/storage/mysql.rb +13 -15
  34. data/lib/sequel_rails/storage/postgres.rb +42 -45
  35. data/lib/sequel_rails/storage/sqlite.rb +0 -1
  36. data/lib/sequel_rails/storage.rb +10 -10
  37. data/lib/sequel_rails/version.rb +1 -1
  38. data/lib/sequel_rails.rb +3 -3
  39. data/rubocop-todo.yml +24 -0
  40. data/sequel-rails.gemspec +21 -19
  41. data/spec/internal/Rakefile +2 -2
  42. data/spec/internal/config/initializers/session.rb +1 -1
  43. data/spec/internal/db/schema.rb.init +6 -0
  44. data/spec/lib/generators/sequel/migration_spec.rb +77 -77
  45. data/spec/lib/generators/sequel/session_migration_spec.rb +41 -0
  46. data/spec/lib/sequel_rails/configuration_spec.rb +161 -161
  47. data/spec/lib/sequel_rails/jdbc_spec.rb +4 -4
  48. data/spec/lib/sequel_rails/migrations_spec.rb +29 -29
  49. data/spec/lib/sequel_rails/railtie_spec.rb +31 -29
  50. data/spec/lib/sequel_rails/railties/database_rake_spec.rb +16 -15
  51. data/spec/lib/sequel_rails/railties/log_subscriber_spec.rb +6 -6
  52. data/spec/lib/sequel_rails/storage/mysql_spec.rb +31 -31
  53. data/spec/lib/sequel_rails/storage/postgres_spec.rb +67 -67
  54. data/spec/lib/sequel_rails/storage/sqlite_spec.rb +40 -40
  55. data/spec/lib/sequel_rails/storage_spec.rb +77 -89
  56. data/spec/spec_helper.rb +16 -10
  57. metadata +61 -28
  58. data/tasks/spec.rake +0 -81
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f76a96adfae8ea0e88a9309033960f3257abc59
4
- data.tar.gz: ee00b69625771c517e4b0c9d595420fac941b62b
3
+ metadata.gz: 247dcfdfa34d2e6efd0e2f8c8c6bb8335e5fb345
4
+ data.tar.gz: 96e82e9fd1043aecda045915458cdde8fb94ad36
5
5
  SHA512:
6
- metadata.gz: 1d988bf8488b10141f59786d78902694cb3f3bc44eaeffcdb09afc885f343b731b7d1faf36f070daa38d0628900e21687726c5f4b477aaf023a21d1ae9b85ec9
7
- data.tar.gz: 96fc1e85b462e0d74ba7389f33c7aafe1ed94bd0d9fbbf4eeeb997ce6bb26ec22b25c94c6e99f6f50d19bd36dd77d8ac2bfeb28b680e943ece1ff8d76fdd4b7c
6
+ metadata.gz: 2e267ef1a1b2d2ba8f73895e8fd663dd0826479d4dac9da11ec0737e4f1863b3f17c961dfd823f65910edab0d8f997e3254e758cd332940cf3fa0bf3503f141e
7
+ data.tar.gz: 9d4b2d24a2f383d7a1c57b05989881125b03612825cd5f5b914df840330fdef13cb9d950972426ed2fafdda0e5e8a2af161335c4e939f69b831ecb8ece5a97cd
data/.gitignore CHANGED
@@ -28,5 +28,6 @@ vendor
28
28
  .rvmrc
29
29
  *.gem
30
30
  Gemfile.lock
31
+ *.gemfile.lock
31
32
 
32
33
  spec/internal/db/database.sqlite3
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ Includes:
3
+ - Gemfile
4
+ - config.ru
5
+ - Rakefile
6
+ - '*.rake'
7
+ - '*.gemfile'
8
+ - '*.gemspec'
9
+
10
+ HashSyntax:
11
+ EnforcedStyle: hash_rockets
12
+
13
+ inherit_from: rubocop-todo.yml
data/.travis.yml CHANGED
@@ -1,66 +1,38 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - ree
4
+ - 1.8.7
3
5
  - 1.9.3
4
6
  - 2.0.0
5
7
  - jruby-18mode
6
8
  - jruby-19mode
9
+ - jruby-20mode
7
10
  env:
8
- - "TEST_ADAPTER=postgresql TEST_OWNER=postgres TEST_USERNAME=postgres SEQUEL='~> 3.28'"
9
- - "TEST_ADAPTER=mysql TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 3.28'"
10
- - "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 3.28'"
11
- - "TEST_ADAPTER=sqlite3 TEST_DATABASE='db/database.sqlite3' SEQUEL='~> 3.28'"
12
- - "TEST_ADAPTER=postgresql TEST_OWNER=postgres TEST_USERNAME=postgres SEQUEL='~> 4.0.0'"
13
- - "TEST_ADAPTER=mysql TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 4.0.0'"
14
- - "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 4.0.0'"
15
- - "TEST_ADAPTER=sqlite3 TEST_DATABASE='db/database.sqlite3' SEQUEL='~> 4.0.0'"
11
+ - SEQUEL='~> 3.0'
12
+ - SEQUEL='~> 4.0'
16
13
  gemfile:
17
14
  - ci/rails-3.2.gemfile
18
15
  - ci/rails-4.0.gemfile
19
16
  matrix:
20
17
  exclude:
21
- - rvm: jruby-18mode
22
- env: "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 3.28'"
23
- gemfile: ci/rails-3.2.gemfile
24
- - rvm: jruby-18mode
25
- env: "TEST_ADAPTER=mysql TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 3.28'"
26
- gemfile: ci/rails-4.0.gemfile
27
- - rvm: jruby-18mode
28
- env: "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 3.28'"
29
- gemfile: ci/rails-4.0.gemfile
30
- - rvm: jruby-18mode
31
- env: "TEST_ADAPTER=postgresql TEST_OWNER=postgres TEST_USERNAME=postgres SEQUEL='~> 3.28'"
18
+ - rvm: ree
32
19
  gemfile: ci/rails-4.0.gemfile
33
- - rvm: jruby-18mode
34
- env: "TEST_ADAPTER=sqlite3 TEST_DATABASE='db/database.sqlite3' SEQUEL='~> 3.28'"
35
- gemfile: ci/rails-4.0.gemfile
36
- - rvm: jruby-19mode
37
- env: "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 3.28'"
38
- gemfile: ci/rails-3.2.gemfile
39
- - rvm: jruby-19mode
40
- env: "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 3.28'"
20
+ env: SEQUEL='~> 3.0'
21
+ - rvm: ree
41
22
  gemfile: ci/rails-4.0.gemfile
42
- - rvm: jruby-18mode
43
- env: "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 4.0.0'"
44
- gemfile: ci/rails-3.2.gemfile
45
- - rvm: jruby-18mode
46
- env: "TEST_ADAPTER=mysql TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 4.0.0'"
23
+ env: SEQUEL='~> 4.0'
24
+ - rvm: 1.8.7
47
25
  gemfile: ci/rails-4.0.gemfile
48
- - rvm: jruby-18mode
49
- env: "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 4.0.0'"
26
+ env: SEQUEL='~> 3.0'
27
+ - rvm: 1.8.7
50
28
  gemfile: ci/rails-4.0.gemfile
29
+ env: SEQUEL='~> 4.0'
51
30
  - rvm: jruby-18mode
52
- env: "TEST_ADAPTER=postgresql TEST_OWNER=postgres TEST_USERNAME=postgres SEQUEL='~> 4.0.0'"
53
31
  gemfile: ci/rails-4.0.gemfile
32
+ env: SEQUEL='~> 3.0'
54
33
  - rvm: jruby-18mode
55
- env: "TEST_ADAPTER=sqlite3 TEST_DATABASE='db/database.sqlite3' SEQUEL='~> 4.0.0'"
56
- gemfile: ci/rails-4.0.gemfile
57
- - rvm: jruby-19mode
58
- env: "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 4.0.0'"
59
- gemfile: ci/rails-3.2.gemfile
60
- - rvm: jruby-19mode
61
- env: "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8 SEQUEL='~> 4.0.0'"
62
34
  gemfile: ci/rails-4.0.gemfile
63
- script: "rake spec"
35
+ env: SEQUEL='~> 4.0'
64
36
  notifications:
65
37
  email:
66
38
  - jonathan.tron@metrilio.com
data/Gemfile CHANGED
@@ -1,21 +1,21 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem "fakefs", :require => "fakefs/safe"
6
- gem "pry"
5
+ gem 'fakefs', :require => 'fakefs/safe'
6
+ gem 'pry'
7
7
 
8
8
  # MRI/Rubinius Adapter Dependencies
9
9
  platform :ruby do
10
- gem "pg"
11
- gem "mysql"
12
- gem "mysql2"
13
- gem "sqlite3"
10
+ gem 'pg'
11
+ gem 'mysql'
12
+ gem 'mysql2'
13
+ gem 'sqlite3'
14
14
  end
15
15
 
16
16
  # JRuby Adapter Dependencies
17
17
  platform :jruby do
18
- gem "jdbc-sqlite3"
19
- gem "jdbc-mysql"
20
- gem "jdbc-postgres"
18
+ gem 'jdbc-sqlite3'
19
+ gem 'jdbc-mysql'
20
+ gem 'jdbc-postgres'
21
21
  end
data/History.md CHANGED
@@ -1,3 +1,11 @@
1
+ 0.8.0 (2013-11-10)
2
+ ==================
3
+
4
+ * Simplify and improve TravisCI config (Tamir Duberstein) [#51](https://github.com/TalentBox/sequel-rails/issues/51)
5
+ * Add Rubocop and fix syntax violations (Tamir Duberstein) [#51](https://github.com/TalentBox/sequel-rails/issues/51)
6
+ * Update RSpec and use the new 'expect' syntax (Tamir Duberstein) [#51](https://github.com/TalentBox/sequel-rails/issues/51)
7
+ * Add session_migration generator and cleanup old code [#56](https://github.com/TalentBox/sequel-rails/issues/56)
8
+
1
9
  0.7.0 (2013-10-11)
2
10
  ==================
3
11
 
data/README.md CHANGED
@@ -96,6 +96,12 @@ Features provided by `sequel-rails`
96
96
  rails generate observer User
97
97
  ```
98
98
 
99
+ Session:
100
+
101
+ ```ruby
102
+ rails generate session_migration
103
+ ```
104
+
99
105
  3. Rake tasks similar to `ActiveRecord`, see
100
106
  [Available sequel specific rake tasks](#available-sequel-specific-rake-tasks)
101
107
 
@@ -118,6 +124,9 @@ Features provided by `sequel-rails`
118
124
  7. Add a hook in `ActionController::Base` so that the sum of SQL queries time
119
125
  for the current action is reported as `DB` for the controller's line in logs.
120
126
 
127
+ 8. Provide a `SequelRails::SessionStore` similar to the `ActiveRecord` one, which stores
128
+ sessions in database backed by a `Sequel` model.
129
+
121
130
  Configuration
122
131
  =============
123
132
  You can configure some options with the usual rails mechanism, in
@@ -212,6 +221,32 @@ loaded. Loading plugins into `Sequel::Model` after subclasses are already
212
221
  created is not supported by Sequel. You can also load extensions in
213
222
  `after_connect` or perform any custom actions that you need.
214
223
 
224
+ Using the `SequelRails::SessionStore` to store session in database
225
+ ==================================================================
226
+
227
+ If you want to store your session in the database you can use the provided
228
+ session store backed by a `Sequel` model. Edit your
229
+ `config/initializers/session.rb` file and replace the existing code with:
230
+
231
+ ```ruby
232
+ YourAppName::Application.config.session_store SequelRails::SessionStore
233
+ ```
234
+
235
+ You can then generate a migration for the session table using the provided
236
+ generator:
237
+
238
+ ```bash
239
+ rails generate session_migration
240
+ rake db:migrate
241
+ ```
242
+
243
+ Optionally if you want to use your own `Sequel` model to handle the session,
244
+ you can do so in your `config/initializers/session.rb`:
245
+
246
+ ```ruby
247
+ SequelRails::SessionStore.session_class = MyCustomSessionModelClass
248
+ ```
249
+
215
250
  Available sequel specific rake tasks
216
251
  ====================================
217
252
 
@@ -295,6 +330,7 @@ Improvements has been made by those awesome contributors:
295
330
  * Robert Payne (robertjpayne)
296
331
  * Kevin Menard (nirvdrum)
297
332
  * Chris Heisterkamp (cheister)
333
+ * Tamir Duberstein (tamird)
298
334
 
299
335
  Credits
300
336
  =======
data/Rakefile CHANGED
@@ -6,6 +6,74 @@ end
6
6
 
7
7
  Bundler::GemHelper.install_tasks
8
8
 
9
- require "sequel_rails"
9
+ require 'sequel_rails'
10
10
 
11
- FileList['tasks/**/*.rake'].each { |task| import task }
11
+ begin
12
+ require 'rspec/core/rake_task'
13
+
14
+ desc 'Run RSpec code example (default to only PostgreSQL)'
15
+ RSpec::Core::RakeTask.new
16
+
17
+ namespace :spec do
18
+ def clean_env
19
+ %w(
20
+ TEST_ADAPTER
21
+ TEST_DATABASE
22
+ TEST_OWNER
23
+ TEST_USERNAME
24
+ TEST_PASSWORD
25
+ TEST_ENCODING
26
+ ).each do |name|
27
+ ENV[name] = nil
28
+ end
29
+ end
30
+
31
+ configs = {
32
+ 'postgresql' => { 'TEST_ENCODING' => 'unicode' },
33
+ 'mysql' => { 'TEST_ENCODING' => 'utf8', 'TEST_USERNAME' => 'root' },
34
+ 'sqlite3' => { 'TEST_DATABASE' => 'db/database.sqlite3' },
35
+ }
36
+
37
+ configs.merge!('mysql2' => configs.fetch('mysql')) unless SequelRails.jruby?
38
+
39
+ configs.each do |adapter, config|
40
+ desc "Run specs for #{adapter} adapter"
41
+ task adapter do
42
+ clean_env
43
+ Rake::Task['spec'].reenable
44
+ ENV['TEST_ADAPTER'] = adapter
45
+ config.each do |key, value|
46
+ ENV[key] = value
47
+ end
48
+ Rake::Task['spec'].invoke
49
+ end
50
+ end
51
+
52
+ desc 'Run specs for all adapters'
53
+ task :all do
54
+ configs.keys.map { |adapter| Rake::Task["spec:#{adapter}"].invoke }.all?
55
+ end
56
+ end
57
+
58
+ begin
59
+ require 'rubocop/rake_task'
60
+
61
+ Rubocop::RakeTask.new do |task|
62
+ task.patterns = ['-R']
63
+ end
64
+ rescue LoadError
65
+ task :rubocop do
66
+ abort 'rubocop is not available. In order to run rubocop, you must: bundle install'
67
+ end
68
+ end
69
+
70
+ task :default do
71
+ Rake::Task['spec:all'].invoke
72
+ Rake::Task['rubocop'].invoke if defined?(Rubocop)
73
+ end
74
+
75
+ rescue LoadError
76
+ task :spec do
77
+ abort 'rspec is not available. In order to run spec, you must: bundle install'
78
+ end
79
+ end
data/ci/rails-3.2.gemfile CHANGED
@@ -1,24 +1,27 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "railties", "~> 3.2.13"
3
+ gem 'railties', '~> 3.2.13'
4
4
 
5
- gemspec :path => "../"
5
+ gemspec :path => '../'
6
6
 
7
- gem "sequel", "#{ENV["SEQUEL"]}"
7
+ gem 'sequel', "#{ENV["SEQUEL"]}"
8
8
 
9
- gem "fakefs", :require => "fakefs/safe"
9
+ gem 'fakefs', :require => 'fakefs/safe'
10
+
11
+ # activesupport has an undeclared dependency on tzinfo prior to 4.0.0
12
+ gem 'tzinfo'
10
13
 
11
14
  # MRI/Rubinius Adapter Dependencies
12
15
  platform :ruby do
13
- gem "pg"
14
- gem "mysql"
15
- gem "mysql2"
16
- gem "sqlite3"
16
+ gem 'pg'
17
+ gem 'mysql'
18
+ gem 'mysql2'
19
+ gem 'sqlite3'
17
20
  end
18
21
 
19
22
  # JRuby Adapter Dependencies
20
23
  platform :jruby do
21
- gem "jdbc-sqlite3"
22
- gem "jdbc-mysql"
23
- gem "jdbc-postgres"
24
+ gem 'jdbc-sqlite3'
25
+ gem 'jdbc-mysql'
26
+ gem 'jdbc-postgres'
24
27
  end
data/ci/rails-4.0.gemfile CHANGED
@@ -1,24 +1,24 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "railties", "~> 4.0.0"
3
+ gem 'railties', '~> 4.0.0'
4
4
 
5
- gemspec :path => "../"
5
+ gemspec :path => '../'
6
6
 
7
- gem "sequel", "#{ENV["SEQUEL"]}"
7
+ gem 'sequel', "#{ENV["SEQUEL"]}"
8
8
 
9
- gem "fakefs", :require => "fakefs/safe"
9
+ gem 'fakefs', :require => 'fakefs/safe'
10
10
 
11
11
  # MRI/Rubinius Adapter Dependencies
12
12
  platform :ruby do
13
- gem "pg"
14
- gem "mysql"
15
- gem "mysql2"
16
- gem "sqlite3"
13
+ gem 'pg'
14
+ gem 'mysql'
15
+ gem 'mysql2'
16
+ gem 'sqlite3'
17
17
  end
18
18
 
19
19
  # JRuby Adapter Dependencies
20
20
  platform :jruby do
21
- gem "jdbc-sqlite3"
22
- gem "jdbc-mysql"
23
- gem "jdbc-postgres"
21
+ gem 'jdbc-sqlite3'
22
+ gem 'jdbc-mysql'
23
+ gem 'jdbc-postgres'
24
24
  end
data/config.ru CHANGED
@@ -3,5 +3,5 @@ require 'bundler'
3
3
 
4
4
  Bundler.require :default, :development
5
5
 
6
- Combustion.initialize! "sequel_rails"
6
+ Combustion.initialize! 'sequel_rails'
7
7
  run Combustion::Application
@@ -1,21 +1,20 @@
1
- require "generators/sequel"
1
+ require 'generators/sequel'
2
2
 
3
3
  module Sequel
4
4
  class IllegalMigrationNameError < StandardError
5
5
  def initialize(name)
6
- super("Illegal name for migration file: #{name}\n\t(only lower case letters, numbers, and '_' allowed)")
6
+ super("Illegal name for migration file: #{name} (only lower case letters, numbers, and '_' allowed)")
7
7
  end
8
8
  end
9
9
 
10
10
  module Generators
11
11
  class MigrationGenerator < Base #:nodoc:
12
-
13
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
12
+ argument :attributes, :type => :array, :default => [], :banner => 'field:type field:type'
14
13
 
15
14
  def create_migration_file
16
15
  set_local_assigns!
17
16
  validate_file_name!
18
- migration_template "migration.rb.erb", "db/migrate/#{file_name}.rb"
17
+ migration_template 'migration.rb.erb', "db/migrate/#{file_name}.rb"
19
18
  end
20
19
 
21
20
  attr_reader :migration_action, :table_action, :column_action, :use_change
@@ -25,18 +24,18 @@ module Sequel
25
24
  def set_local_assigns!
26
25
  if file_name =~ /^(add|drop|remove)_.*_(?:to|from)_(.*)/
27
26
  @table_action = 'alter'
28
- @table_name = $2.pluralize
29
- @column_action = $1 == 'add' ? 'add' : 'drop'
27
+ @table_name = Regexp.last_match[2].pluralize
28
+ @column_action = Regexp.last_match[1] == 'add' ? 'add' : 'drop'
30
29
  @use_change = @column_action == 'add' ? true : false
31
30
  elsif file_name =~ /^(create|drop)_(.*)$/
32
- @table_action = $1
33
- @table_name = $2.pluralize
31
+ @table_action = Regexp.last_match[1]
32
+ @table_name = Regexp.last_match[2].pluralize
34
33
  @column_action = 'add'
35
34
  @use_change = @table_action == 'create' ? true : false
36
35
  else
37
36
  @table_action = 'alter'
38
37
  if file_name =~ /^(alter)_(.*)/
39
- @table_name = $2.pluralize
38
+ @table_name = Regexp.last_match[2].pluralize
40
39
  else
41
40
  @table_name = file_name.pluralize
42
41
  end
@@ -46,9 +45,7 @@ module Sequel
46
45
  end
47
46
 
48
47
  def validate_file_name!
49
- unless file_name =~ /^[_a-z0-9]+$/
50
- raise IllegalMigrationNameError.new(file_name)
51
- end
48
+ fail IllegalMigrationNameError file_name unless file_name =~ /^[_a-z0-9]+$/
52
49
  end
53
50
  end
54
51
  end
@@ -1,29 +1,31 @@
1
- require "generators/sequel"
1
+ require 'generators/sequel'
2
2
 
3
3
  module Sequel
4
4
  module Generators
5
-
6
5
  class ModelGenerator < Base
7
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
6
+ argument :attributes, :type => :array, :default => [], :banner => 'field:type field:type'
8
7
 
9
8
  check_class_collision
10
9
 
11
10
  class_option :migration, :type => :boolean
12
11
  class_option :timestamps, :type => :boolean
13
- class_option :parent, :type => :string, :desc => "The parent class for the generated model"
12
+ class_option :parent, :type => :string, :desc => 'The parent class for the generated model'
14
13
 
15
14
  def create_migration_file
16
- return unless options[:migration]
17
- migration_template "migration.rb.erb", "db/migrate/create_#{table_name}.rb"
15
+ migration_template(
16
+ 'migration.rb.erb',
17
+ File.join('db', 'migrate', "create_#{table_name}.rb")
18
+ ) if options[:migration]
18
19
  end
19
20
 
20
21
  def create_model_file
21
- template 'model.rb.erb', File.join('app/models', class_path, "#{file_name}.rb")
22
+ template(
23
+ 'model.rb.erb',
24
+ File.join('app', 'models', class_path, "#{file_name}.rb")
25
+ )
22
26
  end
23
27
 
24
28
  hook_for :test_framework
25
-
26
29
  end
27
-
28
30
  end
29
31
  end
@@ -1,19 +1,18 @@
1
- require "generators/sequel"
1
+ require 'generators/sequel'
2
2
 
3
3
  module Sequel
4
4
  module Generators
5
-
6
5
  class ObserverGenerator < Base
7
-
8
- check_class_collision :suffix => "Observer"
6
+ check_class_collision :suffix => 'Observer'
9
7
 
10
8
  def create_observer_file
11
- template 'observer.rb.erb', File.join('app/models', class_path, "#{file_name}_observer.rb")
9
+ template(
10
+ 'observer.rb.erb',
11
+ File.join('app', 'models', class_path, "#{file_name}_observer.rb")
12
+ )
12
13
  end
13
14
 
14
15
  hook_for :test_framework
15
-
16
16
  end
17
-
18
17
  end
19
18
  end
@@ -0,0 +1,30 @@
1
+ require 'generators/sequel'
2
+
3
+ module Sequel
4
+ class IllegalMigrationNameError < StandardError
5
+ def initialize(name)
6
+ super("Illegal name for migration file: #{name} (only lower case letters, numbers, and '_' allowed)")
7
+ end
8
+ end
9
+
10
+ module Generators
11
+ class SessionMigrationGenerator < Base #:nodoc:
12
+ argument :name, :type => :string, :default => 'add_sessions_table'
13
+
14
+ def create_migration_file
15
+ validate_file_name!
16
+ migration_template 'migration.rb.erb', "db/migrate/#{file_name}.rb"
17
+ end
18
+
19
+ protected
20
+
21
+ def session_table_name
22
+ SequelRails::SessionStore.session_class.table_name
23
+ end
24
+
25
+ def validate_file_name!
26
+ fail IllegalMigrationNameError file_name unless file_name =~ /^[_a-z0-9]+$/
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table :<%= session_table_name %> do
4
+ primary_key :id
5
+ String :session_id, :null => false, :unique => true, :index => true
6
+ String :data, :text => true, :null => false
7
+ DateTime :updated_at, :null => true, :index => true
8
+ end
9
+ end
10
+ end
@@ -1,16 +1,14 @@
1
- require "rails/generators/named_base"
2
- require "rails/generators/migration"
3
- require "rails/generators/active_model"
1
+ require 'rails/generators/named_base'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/active_model'
4
4
 
5
5
  module Sequel
6
6
  module Generators
7
-
8
7
  class Base < ::Rails::Generators::NamedBase #:nodoc:
9
-
10
8
  include ::Rails::Generators::Migration
11
9
 
12
10
  def self.base_name
13
- @_sequel_base_name ||= "sequel"
11
+ @_sequel_base_name ||= 'sequel'
14
12
  end
15
13
 
16
14
  def self.source_root
@@ -32,9 +30,8 @@ module Sequel
32
30
  #
33
31
  def self.next_migration_number(dirname) #:nodoc:
34
32
  next_migration_number = current_migration_number(dirname) + 1
35
- [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
33
+ [Time.now.utc.strftime('%Y%m%d%H%M%S'), sprintf('%.14d', next_migration_number)].max
36
34
  end
37
-
38
35
  end
39
36
 
40
37
  class ActiveModel < ::Rails::Generators::ActiveModel #:nodoc:
@@ -42,11 +39,11 @@ module Sequel
42
39
  "#{klass}.all"
43
40
  end
44
41
 
45
- def self.find(klass, params=nil)
42
+ def self.find(klass, params = nil)
46
43
  "#{klass}.find!(#{params})"
47
44
  end
48
45
 
49
- def self.build(klass, params=nil)
46
+ def self.build(klass, params = nil)
50
47
  if params
51
48
  "#{klass}.new(#{params})"
52
49
  else
@@ -58,7 +55,7 @@ module Sequel
58
55
  "#{name}.save"
59
56
  end
60
57
 
61
- def update_attributes(params=nil)
58
+ def update_attributes(params = nil)
62
59
  "#{name}.update(#{params})"
63
60
  end
64
61
 
@@ -70,7 +67,6 @@ module Sequel
70
67
  "#{name}.destroy"
71
68
  end
72
69
  end
73
-
74
70
  end
75
71
  end
76
72
 
@@ -79,7 +75,7 @@ module Rails
79
75
  class GeneratedAttribute #:nodoc:
80
76
  def type_class
81
77
  return 'DateTime' if type.to_s == 'datetime'
82
- return type.to_s.camelcase
78
+ type.to_s.camelcase
83
79
  end
84
80
  end
85
81
  end
data/lib/sequel-rails.rb CHANGED
@@ -1 +1 @@
1
- require "sequel_rails"
1
+ require 'sequel_rails'