talentbox-sequel-rails 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.document +5 -0
  2. data/.gitignore +29 -0
  3. data/CHANGELOG +21 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +114 -0
  6. data/LICENSE +20 -0
  7. data/README.rdoc +86 -0
  8. data/Rakefile +9 -0
  9. data/autotest/discover.rb +1 -0
  10. data/lib/generators/sequel.rb +83 -0
  11. data/lib/generators/sequel/migration/migration_generator.rb +30 -0
  12. data/lib/generators/sequel/migration/templates/migration.rb +16 -0
  13. data/lib/generators/sequel/model/model_generator.rb +23 -0
  14. data/lib/generators/sequel/model/templates/model.rb +3 -0
  15. data/lib/generators/sequel/observer/observer_generator.rb +19 -0
  16. data/lib/generators/sequel/observer/templates/observer.rb +7 -0
  17. data/lib/sequel-rails.rb +7 -0
  18. data/lib/sequel-rails/configuration.rb +63 -0
  19. data/lib/sequel-rails/migrations.rb +30 -0
  20. data/lib/sequel-rails/railtie.rb +90 -0
  21. data/lib/sequel-rails/railties/benchmarking_mixin.rb +23 -0
  22. data/lib/sequel-rails/railties/controller_runtime.rb +43 -0
  23. data/lib/sequel-rails/railties/database.rake +167 -0
  24. data/lib/sequel-rails/railties/i18n_support.rb +12 -0
  25. data/lib/sequel-rails/railties/log_subscriber.rb +31 -0
  26. data/lib/sequel-rails/runtime.rb +14 -0
  27. data/lib/sequel-rails/session_store.rb +82 -0
  28. data/lib/sequel-rails/setup.rb +17 -0
  29. data/lib/sequel-rails/storage.rb +221 -0
  30. data/lib/sequel-rails/version.rb +5 -0
  31. data/sequel-rails.gemspec +29 -0
  32. data/spec/rcov.opts +6 -0
  33. data/spec/spec.opts +4 -0
  34. data/spec/spec_helper.rb +7 -0
  35. data/tasks/ci.rake +1 -0
  36. data/tasks/clean.rake +6 -0
  37. data/tasks/metrics.rake +37 -0
  38. data/tasks/spec.rake +30 -0
  39. data/tasks/yard.rake +9 -0
  40. data/tasks/yardstick.rake +20 -0
  41. metadata +177 -0
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,29 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ doc
20
+ pkg
21
+ tmp
22
+ log
23
+ .yardoc
24
+
25
+ ## PROJECT::SPECIFIC
26
+ vendor
27
+ .bundle
28
+ .rvmrc
29
+ *.gem
@@ -0,0 +1,21 @@
1
+ == 0.2.0
2
+ * Fix deprecation warning for config.generators
3
+ * Update dependency to Rails 3.1.1
4
+ * Update dependency to Sequel 3.28.0
5
+ * Update dependency to RSpec 2.7.0
6
+
7
+ == 0.1.4
8
+ * Merged in changes to rake tasks and timestamp migrations
9
+
10
+ == 0.1.3
11
+ * update sequel dependency, configuration change
12
+
13
+ == 0.1.2
14
+ * fixed log_subscriber bug that 0.1.1 was -supposed- to fix.
15
+ * fixed controller_runtime bug
16
+
17
+ == 0.1.1
18
+ * bug fixes, no additional functionality
19
+
20
+ == 0.1.0
21
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,114 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ talentbox-sequel-rails (0.2.0)
5
+ rails (~> 3.1.1)
6
+ sequel (~> 3.28.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ ZenTest (4.6.2)
12
+ actionmailer (3.1.1)
13
+ actionpack (= 3.1.1)
14
+ mail (~> 2.3.0)
15
+ actionpack (3.1.1)
16
+ activemodel (= 3.1.1)
17
+ activesupport (= 3.1.1)
18
+ builder (~> 3.0.0)
19
+ erubis (~> 2.7.0)
20
+ i18n (~> 0.6)
21
+ rack (~> 1.3.2)
22
+ rack-cache (~> 1.1)
23
+ rack-mount (~> 0.8.2)
24
+ rack-test (~> 0.6.1)
25
+ sprockets (~> 2.0.2)
26
+ activemodel (3.1.1)
27
+ activesupport (= 3.1.1)
28
+ builder (~> 3.0.0)
29
+ i18n (~> 0.6)
30
+ activerecord (3.1.1)
31
+ activemodel (= 3.1.1)
32
+ activesupport (= 3.1.1)
33
+ arel (~> 2.2.1)
34
+ tzinfo (~> 0.3.29)
35
+ activeresource (3.1.1)
36
+ activemodel (= 3.1.1)
37
+ activesupport (= 3.1.1)
38
+ activesupport (3.1.1)
39
+ multi_json (~> 1.0)
40
+ arel (2.2.1)
41
+ autotest (4.4.6)
42
+ ZenTest (>= 4.4.1)
43
+ builder (3.0.0)
44
+ diff-lcs (1.1.3)
45
+ erubis (2.7.0)
46
+ hike (1.2.1)
47
+ i18n (0.6.0)
48
+ json (1.6.1)
49
+ mail (2.3.0)
50
+ i18n (>= 0.4.0)
51
+ mime-types (~> 1.16)
52
+ treetop (~> 1.4.8)
53
+ mime-types (1.17.2)
54
+ multi_json (1.0.3)
55
+ polyglot (0.3.2)
56
+ rack (1.3.5)
57
+ rack-cache (1.1)
58
+ rack (>= 0.4)
59
+ rack-mount (0.8.3)
60
+ rack (>= 1.0.0)
61
+ rack-ssl (1.3.2)
62
+ rack
63
+ rack-test (0.6.1)
64
+ rack (>= 1.0)
65
+ rails (3.1.1)
66
+ actionmailer (= 3.1.1)
67
+ actionpack (= 3.1.1)
68
+ activerecord (= 3.1.1)
69
+ activeresource (= 3.1.1)
70
+ activesupport (= 3.1.1)
71
+ bundler (~> 1.0)
72
+ railties (= 3.1.1)
73
+ railties (3.1.1)
74
+ actionpack (= 3.1.1)
75
+ activesupport (= 3.1.1)
76
+ rack-ssl (~> 1.3.2)
77
+ rake (>= 0.8.7)
78
+ rdoc (~> 3.4)
79
+ thor (~> 0.14.6)
80
+ rake (0.8.7)
81
+ rcov (0.9.11)
82
+ rdoc (3.11)
83
+ json (~> 1.4)
84
+ rspec (2.7.0)
85
+ rspec-core (~> 2.7.0)
86
+ rspec-expectations (~> 2.7.0)
87
+ rspec-mocks (~> 2.7.0)
88
+ rspec-core (2.7.1)
89
+ rspec-expectations (2.7.0)
90
+ diff-lcs (~> 1.1.2)
91
+ rspec-mocks (2.7.0)
92
+ sequel (3.28.0)
93
+ sprockets (2.0.3)
94
+ hike (~> 1.2)
95
+ rack (~> 1.0)
96
+ tilt (~> 1.1, != 1.3.0)
97
+ thor (0.14.6)
98
+ tilt (1.3.3)
99
+ treetop (1.4.10)
100
+ polyglot
101
+ polyglot (>= 0.3.1)
102
+ tzinfo (0.3.30)
103
+ yard (0.7.3)
104
+
105
+ PLATFORMS
106
+ ruby
107
+
108
+ DEPENDENCIES
109
+ autotest (~> 4.4.6)
110
+ rake (~> 0.8.7)
111
+ rcov (~> 0.9.11)
112
+ rspec (~> 2.7.0)
113
+ talentbox-sequel-rails!
114
+ yard (~> 0.5)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2010 The sequel-rails team
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ = sequel-rails
2
+
3
+ This gem provides the railtie that allows {sequel}[http://github.com/jeremyevans/sequel] to hook into {rails3}[http://github.com/rails/rails] and thus behave like a rails framework component. Just like activerecord does in rails, {sequel-rails}[http://github.com/brasten/sequel-rails] uses the railtie API to hook into rails. The two are actually hooked into rails almost identically.
4
+
5
+ The code for this gem was initially taken from the excellent {dm-rails}[http://github.com/datamapper/dm-rails] project.
6
+
7
+ == Using sequel-rails
8
+
9
+ Using sequel with rails3 requires a couple minor changes.
10
+
11
+ First, add the following to your Gemfile:
12
+
13
+ gem 'sequel-rails'
14
+
15
+ ... be sure to run "bundle install" if needed!
16
+
17
+ Secondly, you'll need to require "sequel-rails/railtie" in your config/application.rb file, and not require activerecord. The top of your config/application.rb will probably look something like:
18
+
19
+ # require 'rails/all'
20
+
21
+ # Instead of 'rails/all', require these:
22
+ require "action_controller/railtie"
23
+ require "sequel-rails/railtie"
24
+ require "action_mailer/railtie"
25
+
26
+
27
+ After those changes, you should be good to go!
28
+
29
+
30
+ == Available sequel specific rake tasks
31
+
32
+ To get a list of all available rake tasks in your rails3 app, issue the usual
33
+
34
+ vendor/bin/rake -T
35
+
36
+ Once you do that, you will see the following rake tasks among others. These are the ones that sequel-rails added for us.
37
+
38
+ ...
39
+ vendor/bin/rake db:create # Create the database(s) defined in config/database.yml for the current Rails.env - also creates the test database(s) if Rails.env.development?
40
+ vendor/bin/rake db:create:all # Create all the local databases defined in config/database.yml
41
+ vendor/bin/rake db:drop # Drops the database(s) for the current Rails.env - also drops the test database(s) if Rails.env.development?
42
+ vendor/bin/rake db:drop:all # Drop all the local databases defined in config/database.yml
43
+ vendor/bin/rake db:migrate # Migrate the database to the latest version
44
+ vendor/bin/rake db:migrate:down[version] # Migrate down using migrations
45
+ vendor/bin/rake db:migrate:up[version] # Migrate up using migrations
46
+ vendor/bin/rake db:seed # Load the seed data from db/seeds.rb
47
+ vendor/bin/rake db:sessions:clear # Clear the sessions table for SequelStore
48
+ vendor/bin/rake db:sessions:create # Creates the sessions table for SequelStore
49
+ vendor/bin/rake db:setup # Create the database, load the schema, and initialize with the seed data
50
+ ...
51
+
52
+
53
+ == Current Issues
54
+
55
+ * There are bound to be a lot, but I'm not yet sure what they are
56
+
57
+ == TODO (not necessarily in that order)
58
+
59
+ * SPECS
60
+ * README changes
61
+ * Publish SQL issued by sequel to rails subscribers
62
+
63
+ == Credits
64
+
65
+ The {dm-rails}[http://github.com/datamapper/dm-rails] team wrote most of this code, I just sequel-ized it.
66
+
67
+
68
+
69
+ == Note on Patches/Pull Requests
70
+
71
+ * Fork the project.
72
+ * Make your feature addition or bug fix.
73
+ * Add tests for it. This is important so I don't break it in a
74
+ future version unintentionally.
75
+ * Commit, do not mess with rakefile, version, or history.
76
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
77
+ * Send me a pull request. Bonus points for topic branches.
78
+
79
+
80
+ == The sequel-rails team
81
+
82
+ * Brasten Sager (brasten)
83
+
84
+ == Copyright
85
+
86
+ Copyright (c) 2010 The sequel-rails team. See {LICENSE}[http://github.com/brasten/sequel-rails/blob/master/LICENSE] for details.
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ FileList['tasks/**/*.rake'].each { |task| import task }
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec" }
@@ -0,0 +1,83 @@
1
+ require 'rails/generators/named_base'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/active_model'
4
+
5
+ module Sequel
6
+ module Generators
7
+
8
+ class Base < ::Rails::Generators::NamedBase #:nodoc:
9
+
10
+ include ::Rails::Generators::Migration
11
+
12
+ def self.source_root
13
+ @_sequel_source_root ||=
14
+ File.expand_path("../#{base_name}/#{generator_name}/templates", __FILE__)
15
+ end
16
+
17
+ protected
18
+
19
+ # Sequel does not care if migrations have the same name as long as
20
+ # they have different ids.
21
+ #
22
+ def migration_exists?(dirname, file_name) #:nodoc:
23
+ false
24
+ end
25
+
26
+ # Implement the required interface for Rails::Generators::Migration.
27
+ #
28
+ def self.next_migration_number(dirname) #:nodoc:
29
+ next_migration_number = current_migration_number(dirname) + 1
30
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
31
+ end
32
+
33
+ end
34
+
35
+ class ActiveModel < ::Rails::Generators::ActiveModel #:nodoc:
36
+ def self.all(klass)
37
+ "#{klass}.all"
38
+ end
39
+
40
+ def self.find(klass, params=nil)
41
+ "#{klass}.get(#{params})"
42
+ end
43
+
44
+ def self.build(klass, params=nil)
45
+ if params
46
+ "#{klass}.new(#{params})"
47
+ else
48
+ "#{klass}.new"
49
+ end
50
+ end
51
+
52
+ def save
53
+ "#{name}.save"
54
+ end
55
+
56
+ def update_attributes(params=nil)
57
+ "#{name}.update(#{params})"
58
+ end
59
+
60
+ def errors
61
+ "#{name}.errors"
62
+ end
63
+
64
+ def destroy
65
+ "#{name}.destroy"
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ module Rails
73
+
74
+ module Generators
75
+ class GeneratedAttribute #:nodoc:
76
+ def type_class
77
+ return 'DateTime' if type.to_s == 'datetime'
78
+ return type.to_s.camelcase
79
+ end
80
+ end
81
+ end
82
+
83
+ end
@@ -0,0 +1,30 @@
1
+ require 'generators/sequel'
2
+
3
+ module Sequel
4
+ module Generators
5
+
6
+ class MigrationGenerator < Base
7
+
8
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
9
+ class_option :id, :type => :numeric, :desc => "The id to be used in this migration"
10
+
11
+ def create_migration_file
12
+ set_local_assigns!
13
+ migration_template "migration.rb", "db/migrate/#{file_name}.rb"
14
+ end
15
+
16
+ protected
17
+
18
+ attr_reader :migration_action
19
+
20
+ def set_local_assigns!
21
+ if file_name =~ /^(add|remove|drop)_.*_(?:to|from)_(.*)/
22
+ @migration_action = $1 == 'add' ? 'add' : 'drop'
23
+ @table_name = $2.pluralize
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ class <%= migration_file_name.camelize %>Migration < Sequel::Migration
2
+
3
+ def up
4
+ create_table :<%= table_name %> do
5
+ primary_key :id
6
+ <% attributes.each do |attribute| -%>
7
+ <%= attribute.type_class %> :<%= attribute.name %>
8
+ <% end -%>
9
+ end
10
+ end
11
+
12
+ def down
13
+ drop_table :<%= table_name %>
14
+ end
15
+
16
+ end
@@ -0,0 +1,23 @@
1
+ require 'generators/sequel'
2
+
3
+ module Sequel
4
+ module Generators
5
+
6
+ class ModelGenerator < Base
7
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
8
+
9
+ check_class_collision
10
+
11
+ class_option :timestamps, :type => :boolean
12
+ class_option :parent, :type => :string, :desc => "The parent class for the generated model"
13
+
14
+ def create_model_file
15
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
16
+ end
17
+
18
+ hook_for :test_framework
19
+
20
+ end
21
+
22
+ end
23
+ end