sequel_rails3 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
+ pkg
20
+ nbproject
21
+
22
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010-2010 Corin Langosch
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
data/README.rdoc ADDED
@@ -0,0 +1,55 @@
1
+ =About
2
+
3
+ This gem provides the railtie that allows sequel to hook into rails 3.x and thus behave like a rails framework component. Just like activerecord does in rails, sequel_rails3 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 inspired by sequel-rails and activerecord of rails.
6
+ ==Install
7
+
8
+ Simply install it as any other gem:
9
+
10
+ gem install sequel_rails3
11
+
12
+ Or when using bundler, add it got your Gemfile:
13
+
14
+ gem sequel_rails3
15
+
16
+ ==Quick Start
17
+
18
+ In every rails project edit config/application.rb file as this.
19
+
20
+ Comment out (or remove) this line:
21
+
22
+ require 'rails/all'
23
+
24
+ Insert these lines:
25
+
26
+ require "action_controller/railtie"
27
+ require "action_mailer/railtie"
28
+ require "sequel_rails3/railtie"
29
+
30
+ ==Features
31
+
32
+ * Clean implementation with new codebase
33
+ * Full replacement for ActiveRecord
34
+ * Working, colored logging of queries
35
+ * Support for JDBC/DO (especially usefull when using jruby)
36
+
37
+ ==Todo
38
+
39
+ * Source documentation (rdoc)
40
+ * Support migrations and rake tasks
41
+ * Tests
42
+
43
+ ==Contributing
44
+
45
+ If you'd like to contribute a feature or bugfix: Thanks! To make sure your
46
+ fix/feature has a high chance of being included, please read the following
47
+ guidelines:
48
+
49
+ 1. Fork the project.
50
+ 2. Make your feature addition or bug fix.
51
+ 3. Add tests for it. This is important so we don’t break anything in a future version unintentionally.
52
+ 4. Commit, do not mess with rakefile, version, or history. (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)
53
+ 5. Send me a pull request. Bonus points for topic branches.
54
+
55
+
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = 'sequel_rails3'
8
+ gem.authors = ['Corin Langosch']
9
+ gem.date = Date.today.to_s
10
+ gem.email = 'info@netskin.com'
11
+ gem.homepage = 'http://github.com/gucki/sequel_rails3'
12
+ gem.summary = 'Use sequel as a replacement for activerecord with rails 3'
13
+ gem.description = 'Sequel plugin which provides geo distance-based filters and distance calculation functionality for model.'
14
+ gem.add_dependency "rails", ">= 3.0.0"
15
+ gem.add_dependency "sequel", ">= 3.0.0"
16
+ gem.add_development_dependency "rspec", ">= 1.2.9"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+ task :default => :spec
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "sequel_rails3 #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,48 @@
1
+ module SequelRails3
2
+ class Configuration < Hash
3
+ def initialize(app)
4
+ super
5
+
6
+ config = app.config.database_configuration
7
+ unless config && config[Rails.env]
8
+ raise ArgumentError, "no database configured for environment #{Rails.env}"
9
+ end
10
+
11
+ replace(config[Rails.env])
12
+ end
13
+
14
+ def normalize!
15
+ each_pair do |k, v|
16
+ k = k.to_sym
17
+ case k
18
+ when :uri
19
+ self[:url] = delete(:uri)
20
+ when :adapter
21
+ v = v.to_sym
22
+ case v
23
+ when :sqlite3
24
+ self[k] = :sqlite
25
+ when :postgresql
26
+ self[k] = :postgres
27
+ end
28
+ end
29
+ end
30
+
31
+ # always use jdbc when running jruby
32
+ if defined?(JRUBY_VERSION)
33
+ self[:adapter] = "jdbc:#{self[:adapter]}"
34
+ end
35
+
36
+ # some adapters only support an url
37
+ if self[:adapter] =~ "^(jdbc|do):"
38
+ port = self[:port] ? ":#{self[:port]}" : ""
39
+ params = {}
40
+ each_pair do |k, v|
41
+ next if [].include?(:adapter, :host, :port, :database)
42
+ params[k] = v
43
+ end
44
+ self[:url] = "%s://%s%s/%s?%s" % [self[:adapter], self[:host], port, self[:database], params]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,69 @@
1
+ # see activerecord/lib/active_record/log_subscriber.rb
2
+ module SequelRails3
3
+ class Logger
4
+ cattr_accessor :logger
5
+ cattr_accessor :odd_or_even
6
+ cattr_accessor :helper
7
+
8
+ self.logger = nil
9
+ self.odd_or_even = false
10
+ self.helper = ActiveSupport::LogSubscriber.new
11
+
12
+ def self.runtime=(value)
13
+ Thread.current["sequel_sql_runtime"] = value
14
+ end
15
+
16
+ def self.runtime
17
+ Thread.current["sequel_sql_runtime"] ||= 0
18
+ end
19
+
20
+ def self.reset_runtime
21
+ rt, self.runtime = runtime, 0
22
+ rt
23
+ end
24
+
25
+ def self.debug(sql, duration)
26
+ self.runtime += duration
27
+ return unless logger && logger.debug?
28
+
29
+ name = '(%.1fms)' % [duration*1000]
30
+ sql = sql.squeeze(' ')
31
+
32
+ if odd?
33
+ name = helper.send(:color, name, ActiveSupport::LogSubscriber::CYAN, true)
34
+ sql = helper.send(:color, sql, nil, true)
35
+ else
36
+ name = helper.send(:color, name, ActiveSupport::LogSubscriber::MAGENTA, true)
37
+ end
38
+
39
+ logger.debug " #{name} #{sql}"
40
+ end
41
+
42
+ def self.error(message)
43
+ return unless logger
44
+
45
+ logger.error(message)
46
+ end
47
+
48
+ def self.odd?
49
+ self.odd_or_even = !odd_or_even
50
+ end
51
+ end
52
+ end
53
+
54
+ module Sequel
55
+ class Database
56
+ def log_yield(sql, args = nil)
57
+ sql = "#{sql}; #{args.inspect}" if args
58
+ start = Time.now
59
+ begin
60
+ yield
61
+ rescue => e
62
+ SequelRails3::Logger.error("#{e.class}: #{e.message.strip}: #{sql}")
63
+ raise
64
+ ensure
65
+ SequelRails3::Logger.debug(sql, Time.now-start) unless e
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,34 @@
1
+ require 'sequel'
2
+ require 'rails'
3
+ require 'sequel_rails3/configuration'
4
+ require 'sequel_rails3/logger'
5
+
6
+ module SequelRails3
7
+ class Railtie < Rails::Railtie
8
+ cattr_accessor :db
9
+ cattr_accessor :config
10
+
11
+ initializer 'sequel_rails3.init', :before => :load_environment_config do |app|
12
+ self.config = Configuration.new(app)
13
+ self.config.normalize!
14
+
15
+ Sequel::Model.raise_on_save_failure = false
16
+ Sequel::Model.raise_on_typecast_failure = false
17
+
18
+ Sequel::Model.plugin :active_model
19
+
20
+ self.db = Sequel.connect(config)
21
+ end
22
+
23
+ initializer 'sequel_rails3.logging', :after => :initialize_logger do |app|
24
+ SequelRails3::Logger.logger = Rails.logger
25
+ end
26
+
27
+ initializer 'sequel_rails3.log_runtime' do |app|
28
+ require 'sequel_rails3/railties/controller_runtime'
29
+ ActiveSupport.on_load(:action_controller) do
30
+ include SequelRails3::Railties::ControllerRuntime
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ # see activerecord/lib/active_record/railties/controller_runtime.rb
2
+ require 'active_support/core_ext/module/attr_internal'
3
+
4
+ module SequelRails3
5
+ module Railties
6
+ module ControllerRuntime
7
+ extend ActiveSupport::Concern
8
+
9
+ protected
10
+
11
+ attr_internal :db_runtime
12
+
13
+ def cleanup_view_runtime
14
+ db_rt_before_render = SequelRails3::Logger.reset_runtime
15
+ runtime = super
16
+ db_rt_after_render = SequelRails3::Logger.reset_runtime
17
+ self.db_runtime = db_rt_before_render + db_rt_after_render
18
+ runtime - db_rt_after_render
19
+ end
20
+
21
+ def append_info_to_payload(payload)
22
+ super
23
+ payload[:db_runtime] = db_runtime
24
+ end
25
+
26
+ module ClassMethods
27
+ def log_process_action(payload)
28
+ messages, db_runtime = super, payload[:db_runtime]
29
+ messages << ("Sequel: %.1fms" % [db_runtime.to_f*1000]) if db_runtime
30
+ messages
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ require 'sequel_rails3/railtie'
@@ -0,0 +1,65 @@
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_rails3}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Corin Langosch"]
12
+ s.date = %q{2010-09-30}
13
+ s.description = %q{Sequel plugin which provides geo distance-based filters and distance calculation functionality for model.}
14
+ s.email = %q{info@netskin.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/sequel_rails3.rb",
27
+ "lib/sequel_rails3/configuration.rb",
28
+ "lib/sequel_rails3/logger.rb",
29
+ "lib/sequel_rails3/railtie.rb",
30
+ "lib/sequel_rails3/railties/controller_runtime.rb",
31
+ "sequel_rails3.gemspec",
32
+ "spec/sequel_rails3_spec.rb",
33
+ "spec/spec.opts",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/gucki/sequel_rails3}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.7}
40
+ s.summary = %q{Use sequel as a replacement for activerecord with rails 3}
41
+ s.test_files = [
42
+ "spec/spec_helper.rb",
43
+ "spec/sequel_rails3_spec.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
52
+ s.add_runtime_dependency(%q<sequel>, [">= 3.0.0"])
53
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
54
+ else
55
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
56
+ s.add_dependency(%q<sequel>, [">= 3.0.0"])
57
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
61
+ s.add_dependency(%q<sequel>, [">= 3.0.0"])
62
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
63
+ end
64
+ end
65
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "SequelRails3" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'sequel_rails3'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel_rails3
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Corin Langosch
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-30 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
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
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: sequel
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 3
45
+ - 0
46
+ - 0
47
+ version: 3.0.0
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 1
60
+ - 2
61
+ - 9
62
+ version: 1.2.9
63
+ type: :development
64
+ version_requirements: *id003
65
+ description: Sequel plugin which provides geo distance-based filters and distance calculation functionality for model.
66
+ email: info@netskin.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - LICENSE
73
+ - README.rdoc
74
+ files:
75
+ - .document
76
+ - .gitignore
77
+ - LICENSE
78
+ - README.rdoc
79
+ - Rakefile
80
+ - VERSION
81
+ - lib/sequel_rails3.rb
82
+ - lib/sequel_rails3/configuration.rb
83
+ - lib/sequel_rails3/logger.rb
84
+ - lib/sequel_rails3/railtie.rb
85
+ - lib/sequel_rails3/railties/controller_runtime.rb
86
+ - sequel_rails3.gemspec
87
+ - spec/sequel_rails3_spec.rb
88
+ - spec/spec.opts
89
+ - spec/spec_helper.rb
90
+ has_rdoc: true
91
+ homepage: http://github.com/gucki/sequel_rails3
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --charset=UTF-8
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project:
118
+ rubygems_version: 1.3.7
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Use sequel as a replacement for activerecord with rails 3
122
+ test_files:
123
+ - spec/spec_helper.rb
124
+ - spec/sequel_rails3_spec.rb