sequel-rails-cartodb 0.1.7

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 +15 -0
  4. data/Gemfile +21 -0
  5. data/LICENSE +20 -0
  6. data/README.rdoc +86 -0
  7. data/Rakefile +33 -0
  8. data/VERSION +1 -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 +1 -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 +27 -0
  29. data/lib/sequel-rails/storage.rb +251 -0
  30. data/sequel-rails.gemspec +93 -0
  31. data/spec/rcov.opts +6 -0
  32. data/spec/setup_spec.rb +7 -0
  33. data/spec/spec.opts +4 -0
  34. data/spec/spec_helper.rb +21 -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 +38 -0
  39. data/tasks/yard.rake +9 -0
  40. data/tasks/yardstick.rake +20 -0
  41. metadata +160 -0
@@ -0,0 +1,27 @@
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.connection(environment = nil)
13
+ environment ||= Rails.env
14
+ @@connections[environment] ||= setup(environment)
15
+ end
16
+
17
+ def self.setup(environment = nil)
18
+ environment ||= Rails.env
19
+ puts "[sequel] Setting up the #{environment.inspect} environment:"
20
+
21
+ @@connections ||= {}
22
+ @@connections[environment] ||= ::Sequel.connect({:logger => configuration.logger}.merge(::Rails::Sequel.configuration.environment_for(environment.to_s)))
23
+ @@connections[environment]
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,251 @@
1
+ module Rails
2
+ module Sequel
3
+ @@connections = {}
4
+
5
+ # Get or setup a connection for a given environment
6
+ def self.connection(environment=nil)
7
+ environment ||= Rails.env
8
+ @@connections[environment] ||= setup(environment)
9
+ end
10
+
11
+ def self.setup(environment=nil)
12
+ environment ||= Rails.env
13
+ puts "[sequel] Setting up the #{environment.inspect} environment:"
14
+ @@connections[environment] ||= ::Sequel.connect({:logger => configuration.logger}.merge(::Rails::Sequel.configuration.environment_for(environment.to_s)))
15
+ @@connections[environment]
16
+ end
17
+
18
+
19
+ def self.storage
20
+ Storage
21
+ end
22
+
23
+ class Storage
24
+ attr_reader :config
25
+
26
+ def self.create_all
27
+ with_local_repositories { |config| create_environment(config) }
28
+ end
29
+
30
+ def self.drop_all
31
+ with_local_repositories { |config| drop_environment(config) }
32
+ end
33
+
34
+ def self.create_environment(config)
35
+ new(config).create
36
+ end
37
+
38
+ def self.drop_environment(config)
39
+ new(config).drop
40
+ end
41
+
42
+ def self.new(config)
43
+ config = Rails::Sequel.configuration.environments[config.to_s] unless config.kind_of?(Hash)
44
+
45
+ klass = lookup_class(config['adapter'])
46
+ if klass.equal?(self)
47
+ super(config)
48
+ else
49
+ klass.new(config)
50
+ end
51
+ end
52
+
53
+ class << self
54
+ private
55
+
56
+ def with_local_repositories
57
+ Rails::Sequel.configuration.environments.each_value do |config|
58
+ if config['host'].blank? || %w[ 127.0.0.1 localhost ].include?(config['host'])
59
+ yield(config)
60
+ else
61
+ puts "This task only modifies local databases. #{config['database']} is on a remote host."
62
+ end
63
+ end
64
+ end
65
+
66
+ def lookup_class(adapter)
67
+ klass_name = adapter.camelize.to_sym
68
+
69
+ unless Storage.const_defined?(klass_name)
70
+ raise "Adapter #{adapter} not supported (#{klass_name.inspect})"
71
+ end
72
+
73
+ const_get(klass_name)
74
+ end
75
+
76
+ end
77
+
78
+ def initialize(config)
79
+ @config = config
80
+ end
81
+
82
+ def create
83
+ if _create
84
+ puts "[sequel] Created database '#{database}'"
85
+ else
86
+ puts "[sequel] FAILED to create database '#{database}'"
87
+ end
88
+ end
89
+
90
+ def drop
91
+ ::Sequel::Model.db.disconnect
92
+ if _drop
93
+ puts "[sequel] Dropped database '#{database}'"
94
+ else
95
+ puts "[sequel] FAILED to drop database '#{database}'"
96
+ end
97
+ end
98
+
99
+ def database
100
+ @database ||= config['database'] || config['path']
101
+ end
102
+
103
+ def username
104
+ @username ||= config['username'] || config['user'] || ''
105
+ end
106
+
107
+ def password
108
+ @password ||= config['password'] || ''
109
+ end
110
+
111
+ def host
112
+ @host ||= config['host'] || ''
113
+ end
114
+
115
+ def port
116
+ @port ||= config['port'] || ''
117
+ end
118
+
119
+ def owner
120
+ @owner ||= config['owner'] || ''
121
+ end
122
+
123
+
124
+ def charset
125
+ @charset ||= config['charset'] || ENV['CHARSET'] || 'utf8'
126
+ end
127
+
128
+ class Sqlite < Storage
129
+ def _create
130
+ return if in_memory?
131
+ ::Sequel.connect(config.merge('database' => path))
132
+ end
133
+
134
+ def _drop
135
+ return if in_memory?
136
+ path.unlink if path.file?
137
+ end
138
+
139
+ private
140
+
141
+ def in_memory?
142
+ database == ':memory:'
143
+ end
144
+
145
+ def path
146
+ @path ||= Pathname(File.expand_path(database, Rails.root))
147
+ end
148
+
149
+ end
150
+
151
+ class Mysql < Storage
152
+ def _create
153
+ execute("CREATE DATABASE IF NOT EXISTS `#{database}` DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}")
154
+ end
155
+
156
+ def _drop
157
+ execute("DROP DATABASE IF EXISTS `#{database}`")
158
+ end
159
+
160
+ private
161
+
162
+ def execute(statement)
163
+ system(
164
+ 'mysql',
165
+ (username.blank? ? '' : "--user=#{username}"),
166
+ (password.blank? ? '' : "--password=#{password}"),
167
+ '-e',
168
+ statement
169
+ )
170
+ end
171
+
172
+ def collation
173
+ @collation ||= config['collation'] || ENV['COLLATION'] || 'utf8_unicode_ci'
174
+ end
175
+
176
+ end
177
+
178
+ class Postgres < Storage
179
+ def _create
180
+ ENV["PGPASSWORD"] = password unless password.blank?
181
+ commands = "createdb --encoding=#{charset} "
182
+ commands << "--username=#{username} " unless username.blank?
183
+ commands << "--owner=#{owner} " unless owner.blank?
184
+ commands << "--port=#{port} " unless port.blank?
185
+ commands << "--host=#{host} " unless host.blank?
186
+ commands << database
187
+ res = system(commands)
188
+ ENV["PGPASSWORD"] = nil
189
+ res
190
+ end
191
+
192
+ def _drop
193
+ ENV["PGPASSWORD"] = password unless password.blank?
194
+ commands = "dropdb "
195
+ commands << "--username=#{username} " unless username.blank?
196
+ commands << "--owner=#{owner} " unless owner.blank?
197
+ commands << "--port=#{port} " unless port.blank?
198
+ commands << "--host=#{host} " unless host.blank?
199
+ commands << database
200
+ res = system(commands)
201
+ ENV["PGPASSWORD"] = nil
202
+ res
203
+ end
204
+ end
205
+
206
+ class Jdbc < Storage
207
+
208
+ def _is_mysql?
209
+ database.match(/^jdbc:mysql/)
210
+ end
211
+
212
+ def _root_url
213
+ database.scan /^jdbc:mysql:\/\/\w*:?\d*/
214
+ end
215
+
216
+ def db_name
217
+ database.scan(/^jdbc:mysql:\/\/\w+:?\d*\/(\w+)/).flatten.first
218
+ end
219
+
220
+ def _params
221
+ database.scan /\?.*$/
222
+ end
223
+
224
+ def _create
225
+ if _is_mysql?
226
+ ::Sequel.connect("#{_root_url}#{_params}") do |db|
227
+ db.execute("CREATE DATABASE IF NOT EXISTS `#{db_name}` DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}")
228
+ end
229
+ end
230
+ end
231
+
232
+ def _drop
233
+ if _is_mysql?
234
+ ::Sequel.connect("#{_root_url}#{_params}") do |db|
235
+ db.execute("DROP DATABASE IF EXISTS `#{db_name}`")
236
+ end
237
+ end
238
+ end
239
+
240
+ private
241
+
242
+ def collation
243
+ @collation ||= config['collation'] || ENV['COLLATION'] || 'utf8_unicode_ci'
244
+ end
245
+
246
+
247
+ end
248
+
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,93 @@
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-cartodb}
8
+ s.version = "0.1.7"
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-08-11}
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
+ "CHANGELOG",
23
+ "Gemfile",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "autotest/discover.rb",
29
+ "lib/generators/sequel.rb",
30
+ "lib/generators/sequel/migration/migration_generator.rb",
31
+ "lib/generators/sequel/migration/templates/migration.rb",
32
+ "lib/generators/sequel/model/model_generator.rb",
33
+ "lib/generators/sequel/model/templates/model.rb",
34
+ "lib/generators/sequel/observer/observer_generator.rb",
35
+ "lib/generators/sequel/observer/templates/observer.rb",
36
+ "lib/sequel-rails.rb",
37
+ "lib/sequel-rails/configuration.rb",
38
+ "lib/sequel-rails/migrations.rb",
39
+ "lib/sequel-rails/railtie.rb",
40
+ "lib/sequel-rails/railties/benchmarking_mixin.rb",
41
+ "lib/sequel-rails/railties/controller_runtime.rb",
42
+ "lib/sequel-rails/railties/database.rake",
43
+ "lib/sequel-rails/railties/i18n_support.rb",
44
+ "lib/sequel-rails/railties/log_subscriber.rb",
45
+ "lib/sequel-rails/runtime.rb",
46
+ "lib/sequel-rails/session_store.rb",
47
+ "lib/sequel-rails/setup.rb",
48
+ "lib/sequel-rails/storage.rb",
49
+ "sequel-rails.gemspec",
50
+ "spec/rcov.opts",
51
+ "spec/setup_spec.rb",
52
+ "spec/spec.opts",
53
+ "spec/spec_helper.rb",
54
+ "tasks/ci.rake",
55
+ "tasks/clean.rake",
56
+ "tasks/metrics.rake",
57
+ "tasks/spec.rake",
58
+ "tasks/yard.rake",
59
+ "tasks/yardstick.rake"
60
+ ]
61
+ s.homepage = %q{http://github.com/brasten/sequel-rails}
62
+ s.rdoc_options = ["--charset=UTF-8"]
63
+ s.require_paths = ["lib"]
64
+ s.rubygems_version = %q{1.3.6}
65
+ s.summary = %q{Use Sequel with Rails 3}
66
+ s.test_files = [
67
+ "spec/setup_spec.rb",
68
+ "spec/spec_helper.rb"
69
+ ]
70
+
71
+ if s.respond_to? :specification_version then
72
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
73
+ s.specification_version = 3
74
+
75
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
76
+ s.add_runtime_dependency(%q<sequel>, ["~> 3.13"])
77
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0.rc"])
78
+ s.add_runtime_dependency(%q<actionpack>, ["~> 3.0.0.rc"])
79
+ s.add_runtime_dependency(%q<railties>, ["~> 3.0.0.rc"])
80
+ else
81
+ s.add_dependency(%q<sequel>, ["~> 3.13"])
82
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0.rc"])
83
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0.rc"])
84
+ s.add_dependency(%q<railties>, ["~> 3.0.0.rc"])
85
+ end
86
+ else
87
+ s.add_dependency(%q<sequel>, ["~> 3.13"])
88
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0.rc"])
89
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0.rc"])
90
+ s.add_dependency(%q<railties>, ["~> 3.0.0.rc"])
91
+ end
92
+ end
93
+
@@ -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