sequel-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.document +5 -0
  2. data/.gitignore +28 -0
  3. data/Gemfile +21 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +86 -0
  6. data/Rakefile +33 -0
  7. data/VERSION +1 -0
  8. data/autotest/discover.rb +1 -0
  9. data/lib/generators/sequel.rb +82 -0
  10. data/lib/generators/sequel/migration/migration_generator.rb +30 -0
  11. data/lib/generators/sequel/migration/templates/migration.rb +16 -0
  12. data/lib/generators/sequel/model/model_generator.rb +23 -0
  13. data/lib/generators/sequel/model/templates/model.rb +3 -0
  14. data/lib/generators/sequel/observer/observer_generator.rb +19 -0
  15. data/lib/generators/sequel/observer/templates/observer.rb +7 -0
  16. data/lib/sequel-rails.rb +1 -0
  17. data/lib/sequel-rails/configuration.rb +54 -0
  18. data/lib/sequel-rails/migrations.rb +30 -0
  19. data/lib/sequel-rails/railtie.rb +111 -0
  20. data/lib/sequel-rails/railties/benchmarking_mixin.rb +23 -0
  21. data/lib/sequel-rails/railties/controller_runtime.rb +45 -0
  22. data/lib/sequel-rails/railties/database.rake +109 -0
  23. data/lib/sequel-rails/railties/i18n_support.rb +12 -0
  24. data/lib/sequel-rails/railties/log_subscriber.rb +31 -0
  25. data/lib/sequel-rails/session_store.rb +82 -0
  26. data/lib/sequel-rails/setup.rb +18 -0
  27. data/lib/sequel-rails/storage.rb +165 -0
  28. data/sequel-rails.gemspec +91 -0
  29. data/spec/rcov.opts +6 -0
  30. data/spec/setup_spec.rb +7 -0
  31. data/spec/spec.opts +4 -0
  32. data/spec/spec_helper.rb +21 -0
  33. data/tasks/ci.rake +1 -0
  34. data/tasks/clean.rake +6 -0
  35. data/tasks/metrics.rake +37 -0
  36. data/tasks/spec.rake +38 -0
  37. data/tasks/yard.rake +9 -0
  38. data/tasks/yardstick.rake +20 -0
  39. metadata +164 -0
@@ -0,0 +1,18 @@
1
+ require 'active_support/core_ext/hash/except'
2
+
3
+ require 'sequel/extensions/migration'
4
+
5
+ require 'sequel-rails/configuration'
6
+ require 'sequel-rails/railties/benchmarking_mixin'
7
+
8
+ module Rails
9
+ module Sequel
10
+
11
+ def self.setup(environment)
12
+ puts "[sequel] Setting up the #{environment.inspect} environment:"
13
+
14
+ ::Sequel.connect({:logger => configuration.logger}.merge(::Rails::Sequel.configuration.environments[environment.to_s]))
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,165 @@
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
+ klass = lookup_class(config['adapter'])
29
+ if klass.equal?(self)
30
+ super(config)
31
+ else
32
+ klass.new(config)
33
+ end
34
+ end
35
+
36
+ class << self
37
+ private
38
+
39
+ def with_local_repositories
40
+ Rails::Sequel.configuration.environments.each_value do |config|
41
+ if config['host'].blank? || %w[ 127.0.0.1 localhost ].include?(config['host'])
42
+ yield(config)
43
+ else
44
+ puts "This task only modifies local databases. #{config['database']} is on a remote host."
45
+ end
46
+ end
47
+ end
48
+
49
+ def lookup_class(adapter)
50
+ klass_name = adapter.camelize.to_sym
51
+
52
+ unless Storage.const_defined?(klass_name)
53
+ raise "Adapter #{adapter} not supported (#{klass_name.inspect})"
54
+ end
55
+
56
+ const_get(klass_name)
57
+ end
58
+
59
+ end
60
+
61
+ def initialize(config)
62
+ @config = config
63
+ end
64
+
65
+ def create
66
+ _create
67
+ puts "[sequel] Created database '#{database}'"
68
+ end
69
+
70
+ def drop
71
+ _drop
72
+ puts "[sequel] Dropped database '#{database}'"
73
+ end
74
+
75
+ def database
76
+ @database ||= config['database'] || config['path']
77
+ end
78
+
79
+ def username
80
+ @username ||= config['username'] || ''
81
+ end
82
+
83
+ def password
84
+ @password ||= config['password'] || ''
85
+ end
86
+
87
+ def charset
88
+ @charset ||= config['charset'] || ENV['CHARSET'] || 'utf8'
89
+ end
90
+
91
+ class Sqlite < Storage
92
+ def _create
93
+ return if in_memory?
94
+ ::Sequel.connect(config.merge('database' => path))
95
+ end
96
+
97
+ def _drop
98
+ return if in_memory?
99
+ path.unlink if path.file?
100
+ end
101
+
102
+ private
103
+
104
+ def in_memory?
105
+ database == ':memory:'
106
+ end
107
+
108
+ def path
109
+ @path ||= Pathname(File.expand_path(database, Rails.root))
110
+ end
111
+
112
+ end
113
+
114
+ class Mysql < Storage
115
+ def _create
116
+ execute("CREATE DATABASE `#{database}` DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}")
117
+ end
118
+
119
+ def _drop
120
+ execute("DROP DATABASE IF EXISTS `#{database}`")
121
+ end
122
+
123
+ private
124
+
125
+ def execute(statement)
126
+ system(
127
+ 'mysql',
128
+ (username.blank? ? '' : "--user=#{username}"),
129
+ (password.blank? ? '' : "--password=#{password}"),
130
+ '-e',
131
+ statement
132
+ )
133
+ end
134
+
135
+ def collation
136
+ @collation ||= config['collation'] || ENV['COLLATION'] || 'utf8_unicode_ci'
137
+ end
138
+
139
+ end
140
+
141
+ class Postgres < Storage
142
+ def _create
143
+ system(
144
+ 'createdb',
145
+ '-E',
146
+ charset,
147
+ '-U',
148
+ username,
149
+ database
150
+ )
151
+ end
152
+
153
+ def _drop
154
+ system(
155
+ 'dropdb',
156
+ '-U',
157
+ username,
158
+ database
159
+ )
160
+ end
161
+
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,91 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sequel-rails}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brasten Sager (brasten)"]
12
+ s.date = %q{2010-05-18}
13
+ s.description = %q{Integrate Sequel with Rails 3}
14
+ s.email = %q{brasten@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "Gemfile",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "autotest/discover.rb",
28
+ "lib/generators/sequel.rb",
29
+ "lib/generators/sequel/migration/migration_generator.rb",
30
+ "lib/generators/sequel/migration/templates/migration.rb",
31
+ "lib/generators/sequel/model/model_generator.rb",
32
+ "lib/generators/sequel/model/templates/model.rb",
33
+ "lib/generators/sequel/observer/observer_generator.rb",
34
+ "lib/generators/sequel/observer/templates/observer.rb",
35
+ "lib/sequel-rails.rb",
36
+ "lib/sequel-rails/configuration.rb",
37
+ "lib/sequel-rails/migrations.rb",
38
+ "lib/sequel-rails/railtie.rb",
39
+ "lib/sequel-rails/railties/benchmarking_mixin.rb",
40
+ "lib/sequel-rails/railties/controller_runtime.rb",
41
+ "lib/sequel-rails/railties/database.rake",
42
+ "lib/sequel-rails/railties/i18n_support.rb",
43
+ "lib/sequel-rails/railties/log_subscriber.rb",
44
+ "lib/sequel-rails/session_store.rb",
45
+ "lib/sequel-rails/setup.rb",
46
+ "lib/sequel-rails/storage.rb",
47
+ "sequel-rails.gemspec",
48
+ "spec/rcov.opts",
49
+ "spec/setup_spec.rb",
50
+ "spec/spec.opts",
51
+ "spec/spec_helper.rb",
52
+ "tasks/ci.rake",
53
+ "tasks/clean.rake",
54
+ "tasks/metrics.rake",
55
+ "tasks/spec.rake",
56
+ "tasks/yard.rake",
57
+ "tasks/yardstick.rake"
58
+ ]
59
+ s.homepage = %q{http://github.com/brasten/sequel-rails}
60
+ s.rdoc_options = ["--charset=UTF-8"]
61
+ s.require_paths = ["lib"]
62
+ s.rubygems_version = %q{1.3.6.1}
63
+ s.summary = %q{Use Sequel with Rails 3}
64
+ s.test_files = [
65
+ "spec/setup_spec.rb",
66
+ "spec/spec_helper.rb"
67
+ ]
68
+
69
+ if s.respond_to? :specification_version then
70
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
71
+ s.specification_version = 3
72
+
73
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
74
+ s.add_runtime_dependency(%q<sequel>, ["~> 3.10"])
75
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0.beta3"])
76
+ s.add_runtime_dependency(%q<actionpack>, ["~> 3.0.0.beta3"])
77
+ s.add_runtime_dependency(%q<railties>, ["~> 3.0.0.beta3"])
78
+ else
79
+ s.add_dependency(%q<sequel>, ["~> 3.10"])
80
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0.beta3"])
81
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0.beta3"])
82
+ s.add_dependency(%q<railties>, ["~> 3.0.0.beta3"])
83
+ end
84
+ else
85
+ s.add_dependency(%q<sequel>, ["~> 3.10"])
86
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0.beta3"])
87
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0.beta3"])
88
+ s.add_dependency(%q<railties>, ["~> 3.0.0.beta3"])
89
+ end
90
+ end
91
+
@@ -0,0 +1,6 @@
1
+ --exclude-only "spec\/,^\/"
2
+ --sort coverage
3
+ --callsites
4
+ --xrefs
5
+ --profile
6
+ --text-summary
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Rails::Sequel::Setup" do
4
+ it "fails" do
5
+ # fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ --color
2
+ --loadby random
3
+ --format profile
4
+ --backtrace
@@ -0,0 +1,21 @@
1
+ begin
2
+ # Just in case the bundle was locked
3
+ # This shouldn't happen in a dev environment but lets be safe
4
+ require File.expand_path('../../.bundle/environment', __FILE__)
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'bundler'
8
+ Bundler.setup
9
+ end
10
+ Bundler.require(:default, :test)
11
+
12
+ $LOAD_PATH.unshift(File.expand_path('../', __FILE__))
13
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
14
+
15
+ require 'sequel-rails'
16
+
17
+ require 'spec'
18
+ require 'spec/autorun'
19
+
20
+ Spec::Runner.configure do |config|
21
+ end
@@ -0,0 +1 @@
1
+ task :ci => [ 'metrics:all' ]
@@ -0,0 +1,6 @@
1
+ require 'rake/clean'
2
+
3
+ File.foreach('.gitignore') do |line|
4
+ line.strip!
5
+ CLOBBER << line unless line.empty? || line[0, 1] == '#'
6
+ end
@@ -0,0 +1,37 @@
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
@@ -0,0 +1,38 @@
1
+ spec_defaults = lambda do |spec|
2
+ spec.pattern = 'spec/**/*_spec.rb'
3
+ spec.libs << 'lib' << 'spec'
4
+ spec.spec_opts << '--options' << 'spec/spec.opts'
5
+ end
6
+
7
+ begin
8
+ require 'spec/rake/spectask'
9
+
10
+ Spec::Rake::SpecTask.new(:spec, &spec_defaults)
11
+ rescue LoadError
12
+ task :spec do
13
+ abort 'rspec is not available. In order to run spec, you must: gem install rspec'
14
+ end
15
+ end
16
+
17
+ begin
18
+ require 'rcov'
19
+ require 'spec/rake/verify_rcov'
20
+
21
+ Spec::Rake::SpecTask.new(:rcov) do |rcov|
22
+ spec_defaults.call(rcov)
23
+ rcov.rcov = true
24
+ rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
25
+ end
26
+
27
+ RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
28
+ rcov.threshold = 100
29
+ end
30
+ rescue LoadError
31
+ %w[ rcov verify_rcov ].each do |name|
32
+ task name do
33
+ abort "rcov is not available. In order to run #{name}, you must: gem install rcov"
34
+ end
35
+ end
36
+ end
37
+
38
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'yard'
3
+
4
+ YARD::Rake::YardocTask.new
5
+ rescue LoadError
6
+ task :yard do
7
+ abort 'YARD is not available. In order to run yard, you must: gem install yard'
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'pathname'
3
+ require 'yardstick'
4
+ require 'yardstick/rake/measurement'
5
+ require 'yardstick/rake/verify'
6
+
7
+ # yardstick_measure task
8
+ Yardstick::Rake::Measurement.new
9
+
10
+ # verify_measurements task
11
+ Yardstick::Rake::Verify.new do |verify|
12
+ verify.threshold = 100
13
+ end
14
+ rescue LoadError
15
+ %w[ yardstick_measure verify_measurements ].each do |name|
16
+ task name.to_s do
17
+ abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Brasten Sager (brasten)
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-18 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sequel
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 10
31
+ version: "3.10"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activesupport
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 3
44
+ - 0
45
+ - 0
46
+ - beta3
47
+ version: 3.0.0.beta3
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: actionpack
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 3
60
+ - 0
61
+ - 0
62
+ - beta3
63
+ version: 3.0.0.beta3
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: railties
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 3
76
+ - 0
77
+ - 0
78
+ - beta3
79
+ version: 3.0.0.beta3
80
+ type: :runtime
81
+ version_requirements: *id004
82
+ description: Integrate Sequel with Rails 3
83
+ email: brasten@gmail.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE
90
+ - README.rdoc
91
+ files:
92
+ - .document
93
+ - .gitignore
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.rdoc
97
+ - Rakefile
98
+ - VERSION
99
+ - autotest/discover.rb
100
+ - lib/generators/sequel.rb
101
+ - lib/generators/sequel/migration/migration_generator.rb
102
+ - lib/generators/sequel/migration/templates/migration.rb
103
+ - lib/generators/sequel/model/model_generator.rb
104
+ - lib/generators/sequel/model/templates/model.rb
105
+ - lib/generators/sequel/observer/observer_generator.rb
106
+ - lib/generators/sequel/observer/templates/observer.rb
107
+ - lib/sequel-rails.rb
108
+ - lib/sequel-rails/configuration.rb
109
+ - lib/sequel-rails/migrations.rb
110
+ - lib/sequel-rails/railtie.rb
111
+ - lib/sequel-rails/railties/benchmarking_mixin.rb
112
+ - lib/sequel-rails/railties/controller_runtime.rb
113
+ - lib/sequel-rails/railties/database.rake
114
+ - lib/sequel-rails/railties/i18n_support.rb
115
+ - lib/sequel-rails/railties/log_subscriber.rb
116
+ - lib/sequel-rails/session_store.rb
117
+ - lib/sequel-rails/setup.rb
118
+ - lib/sequel-rails/storage.rb
119
+ - sequel-rails.gemspec
120
+ - spec/rcov.opts
121
+ - spec/setup_spec.rb
122
+ - spec/spec.opts
123
+ - spec/spec_helper.rb
124
+ - tasks/ci.rake
125
+ - tasks/clean.rake
126
+ - tasks/metrics.rake
127
+ - tasks/spec.rake
128
+ - tasks/yard.rake
129
+ - tasks/yardstick.rake
130
+ has_rdoc: true
131
+ homepage: http://github.com/brasten/sequel-rails
132
+ licenses: []
133
+
134
+ post_install_message:
135
+ rdoc_options:
136
+ - --charset=UTF-8
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ requirements: []
156
+
157
+ rubyforge_project:
158
+ rubygems_version: 1.3.6.1
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: Use Sequel with Rails 3
162
+ test_files:
163
+ - spec/setup_spec.rb
164
+ - spec/spec_helper.rb