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,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,15 @@
1
+ == 0.1.4
2
+ * Merged in changes to rake tasks and timestamp migrations
3
+
4
+ == 0.1.3
5
+ * update sequel dependency, configuration change
6
+
7
+ == 0.1.2
8
+ * fixed log_subscriber bug that 0.1.1 was -supposed- to fix.
9
+ * fixed controller_runtime bug
10
+
11
+ == 0.1.1
12
+ * bug fixes, no additional functionality
13
+
14
+ == 0.1.0
15
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rake', '~> 0.8.7'
4
+ gem 'jeweler', '~> 1.4'
5
+ gem 'yard', '~> 0.5'
6
+
7
+ git 'git://github.com/rails/rails.git' do
8
+
9
+ gem 'activesupport', '~> 3.0.0.beta3', :require => 'active_support'
10
+ gem 'actionpack', '~> 3.0.0.beta3', :require => 'action_pack'
11
+ gem 'railties', '~> 3.0.0.beta3', :require => 'rails'
12
+
13
+ end
14
+
15
+ gem 'sequel', '~> 3.11.0'
16
+
17
+ group :test do
18
+ gem 'rspec'
19
+ gem 'autotest'
20
+ gem 'rcov'
21
+ end
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,33 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+
6
+ require 'jeweler'
7
+
8
+ Jeweler::Tasks.new do |gem|
9
+
10
+ gem.name = 'sequel-rails'
11
+ gem.summary = 'Use Sequel with Rails 3'
12
+ gem.description = 'Integrate Sequel with Rails 3'
13
+ gem.email = 'brasten@gmail.com'
14
+ gem.homepage = 'http://github.com/brasten/sequel-rails'
15
+ gem.authors = [ 'Brasten Sager (brasten)' ]
16
+
17
+ gem.add_dependency 'sequel', '~> 3.13'
18
+
19
+ gem.add_dependency 'activesupport', '~> 3.0.0.rc'
20
+ gem.add_dependency 'actionpack', '~> 3.0.0.rc'
21
+ gem.add_dependency 'railties', '~> 3.0.0.rc'
22
+
23
+ # gem.add_development_dependency 'yard', '~> 0.5'
24
+
25
+ end
26
+
27
+ Jeweler::GemcutterTasks.new
28
+
29
+ FileList['tasks/**/*.rake'].each { |task| import task }
30
+
31
+ rescue LoadError
32
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
33
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.5
@@ -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
@@ -0,0 +1,3 @@
1
+ class <%= class_name %><%= options[:parent] ? " < #{options[:parent].classify}" : " < Sequel::Model" %>
2
+
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'generators/sequel'
2
+
3
+ module Sequel
4
+ module Generators
5
+
6
+ class ObserverGenerator < Base
7
+
8
+ check_class_collision :suffix => "Observer"
9
+
10
+ def create_observer_file
11
+ template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
12
+ end
13
+
14
+ hook_for :test_framework
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ class <%= class_name %>Observer
2
+
3
+ include Sequel::Observer
4
+
5
+ observe <%= class_name %>
6
+
7
+ end
@@ -0,0 +1 @@
1
+ require 'sequel-rails/railtie'
@@ -0,0 +1,63 @@
1
+ require 'active_support/core_ext/hash/except'
2
+ require 'active_support/core_ext/class/attribute_accessors'
3
+
4
+ module Rails
5
+ module Sequel
6
+
7
+ mattr_accessor :configuration
8
+
9
+ class Configuration
10
+
11
+ def self.for(root, database_yml_hash)
12
+ Rails::Sequel.configuration ||= new(root, database_yml_hash)
13
+ end
14
+
15
+ attr_reader :root, :raw
16
+ attr_accessor :logger
17
+ attr_accessor :migration_dir
18
+
19
+ def environment_for(name)
20
+ environments[name.to_s] || environments[name.to_sym]
21
+ end
22
+
23
+ def environments
24
+ @environments ||= @raw.inject({}) do |normalized, environment|
25
+ name, config = environment.first, environment.last
26
+ normalized[name] = normalize_repository_config(config)
27
+ normalized
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def initialize(root, database_yml_hash)
34
+ @root, @raw = root, database_yml_hash
35
+ end
36
+
37
+ def normalize_repository_config(hash)
38
+ config = {}
39
+ hash.each do |key, value|
40
+ config[key.to_s] =
41
+ if key.to_s == 'port'
42
+ value.to_i
43
+ elsif key.to_s == 'adapter' && value == 'sqlite3'
44
+ 'sqlite'
45
+ elsif key.to_s == 'database' && (hash['adapter'] == 'sqlite3' ||
46
+ hash['adapter'] == 'sqlite' ||
47
+ hash[:adapter] == 'sqlite3' ||
48
+ hash[:adapter] == 'sqlite')
49
+ value == ':memory:' ? value : File.expand_path((hash['database'] || hash[:database]), root)
50
+ elsif key.to_s == 'adapter' && value == 'postgresql'
51
+ 'postgres'
52
+ else
53
+ value
54
+ end
55
+ end
56
+
57
+ config
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end