activerecord-postgresql-cursors 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 125737544b68c64f3db4d3a32e91f56e3ea4d201
4
+ data.tar.gz: dccba67b44a0d8ae5ea61e85478644a1ec40310e
5
+ SHA512:
6
+ metadata.gz: c0e18fe5f6c5ade1fa0b300179a4663ebff1f606ba86b43a85875d85851c67a8409a14fc5592cb5fc625da2b97032350146710620afdfa0d2c84ccd3290b3724
7
+ data.tar.gz: 031328e69972374543752345efbb7c4c55bb8feb5f5aab4c9cd028fc809d4da6f180ff3844c991685562c2152ea58dfdf9f9c03cf700f227f274bcde2c5f189f
@@ -0,0 +1,24 @@
1
+ .*.swp
2
+ .*.swo
3
+ *.tmp
4
+ *.kpf
5
+ *.komodoproject
6
+ *~
7
+ .DS_Store
8
+ *tmp*
9
+ pkg/
10
+ doc/
11
+ coverage/
12
+ *.orig
13
+ *.patch
14
+ .vimrc_local
15
+ debug.log
16
+ *.gem
17
+ *.rbc
18
+ .bundle
19
+ .config
20
+ .yardoc
21
+ Gemfile.lock
22
+ Gemfile.local
23
+ Guardfile.local
24
+ test/local_database.yml
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ if RUBY_PLATFORM == "java"
6
+ gem "activerecord-jdbcpostgresql-adapter"
7
+ else
8
+ gem "pg"
9
+ end
10
+
11
+ gem "rdoc", "~> 3.12"
12
+ gem "rake", "~> 10.0"
13
+ gem "minitest"
14
+ gem "minitest-reporters"
15
+ gem "guard-minitest"
16
+ gem "simplecov"
17
+
18
+ if RbConfig::CONFIG['host_os'] =~ /^darwin/
19
+ gem "rb-fsevent"
20
+ gem "growl"
21
+ end
22
+
23
+ if File.exists?('Gemfile.local')
24
+ instance_eval File.read('Gemfile.local')
25
+ end
26
+
@@ -0,0 +1,17 @@
1
+
2
+ guard 'minitest', :test_folders => 'test', :test_file_patterns => '*_tests.rb' do
3
+ watch(%r|^test/(.+)_tests\.rb|)
4
+
5
+ watch(%r|^lib/(.*)([^/]+)\.rb|) do |m|
6
+ "test/cursor_tests.rb"
7
+ end
8
+
9
+ watch(%r|^test/test_helper\.rb|) do
10
+ "test"
11
+ end
12
+ end
13
+
14
+ if File.exists?('Guardfile.local')
15
+ instance_eval File.read('Guardfile.local')
16
+ end
17
+
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 2167961 Ontario Inc., Zoocasa <code@zoocasa.com>
1
+ Copyright (c) 2012 2167961 Ontario Inc., Zoocasa <code@zoocasa.com>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/Rakefile CHANGED
@@ -5,35 +5,21 @@ require 'rubygems'
5
5
  require 'rubygems/package_task'
6
6
  require 'rake/testtask'
7
7
  require 'rdoc/task'
8
+ require 'bundler/gem_tasks'
8
9
 
9
- $:.push 'lib'
10
+ $:.push File.expand_path(File.dirname(__FILE__), 'lib')
10
11
 
11
- version = File.read('VERSION') rescue ''
12
-
13
- begin
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- gem.name = "activerecord-postgresql-cursors"
17
- gem.summary = "Provides some support for PostgreSQL cursors in ActiveRecord."
18
- gem.description = gem.summary
19
- gem.email = "code@zoocasa.com"
20
- gem.homepage = "http://github.com/zoocasa/activerecord-postgresql-cursors"
21
- gem.authors = [ "J Smith" ]
22
- end
23
- Jeweler::GemcutterTasks.new
24
- rescue LoadError
25
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
26
- end
12
+ version = ActiveRecord::PostgreSQLCursors::VERSION
27
13
 
28
14
  desc 'Test PostgreSQL extensions'
29
15
  Rake::TestTask.new(:test) do |t|
30
- t.pattern = 'test/**/*_test.rb'
31
- t.verbose = false
16
+ t.test_files = FileList['test/**/*_tests.rb']
17
+ t.verbose = !!ENV['VERBOSE_TESTS']
18
+ t.warning = !!ENV['WARNINGS']
32
19
  end
33
20
 
34
21
  desc 'Build docs'
35
22
  Rake::RDocTask.new do |t|
36
- require 'rdoc'
37
23
  t.title = "ActiveRecord PostgreSQL Cursors #{version}"
38
24
  t.main = 'README.rdoc'
39
25
  t.rdoc_dir = 'doc'
@@ -1,45 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
3
+ require File.expand_path('../lib/active_record/postgresql_cursors/version', __FILE__)
4
+
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{activerecord-postgresql-cursors}
8
- s.version = "0.0.2"
6
+ s.name = "activerecord-postgresql-cursors"
7
+ s.version = ActiveRecord::PostgreSQLCursors::VERSION
9
8
 
10
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{J Smith}]
12
- s.date = %q{2011-09-28}
13
- s.description = %q{Provides some support for PostgreSQL cursors in ActiveRecord.}
14
- s.email = %q{code@zoocasa.com}
10
+ s.authors = ["J Smith"]
11
+ s.description = "Provides some support for PostgreSQL cursors in ActiveRecord."
12
+ s.summary = s.description
13
+ s.email = "code@zoocasa.com"
15
14
  s.extra_rdoc_files = [
16
15
  "README.rdoc"
17
16
  ]
18
- s.files = [
19
- "MIT-LICENSE",
20
- "README.rdoc",
21
- "Rakefile",
22
- "VERSION",
23
- "activerecord-postgresql-cursors.gemspec",
24
- "init.rb",
25
- "lib/activerecord-postgresql-cursors.rb",
26
- "lib/postgresql_cursors_2.rb",
27
- "lib/postgresql_cursors_3.rb",
28
- "test/cursor_test.rb",
29
- "test/test_helper.rb"
30
- ]
31
- s.homepage = %q{http://github.com/zoocasa/activerecord-postgresql-cursors}
32
- s.require_paths = [%q{lib}]
33
- s.rubygems_version = %q{1.8.8}
34
- s.summary = %q{Provides some support for PostgreSQL cursors in ActiveRecord.}
35
-
36
- if s.respond_to? :specification_version then
37
- s.specification_version = 3
17
+ s.files = `git ls-files`.split($\)
18
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.homepage = "http://github.com/zoocasa/activerecord-postgresql-cursors"
21
+ s.require_paths = ["lib"]
38
22
 
39
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
- else
41
- end
42
- else
43
- end
23
+ s.add_dependency("activerecord", [">= 2.3"])
44
24
  end
45
25
 
@@ -1,14 +1,4 @@
1
1
 
2
- if ActiveRecord::VERSION::STRING >= '3.1'
3
- class ActiveRecord::Associations::JoinDependency
4
- include ActiveRecord::PostgreSQLCursors::JoinDependency
5
- end
6
- else
7
- class ActiveRecord::Associations::ClassMethods::JoinDependency
8
- include ActiveRecord::PostgreSQLCursors::JoinDependency
9
- end
10
- end
11
-
12
2
  module ActiveRecord
13
3
  module CursorExtensions
14
4
  extend ActiveSupport::Concern
@@ -51,7 +41,12 @@ module ActiveRecord
51
41
  raise CursorsNotSupported, "#{connection.class} doesn't support cursors"
52
42
  end
53
43
 
54
- relation = apply_finder_options(options)
44
+ relation = if ActiveRecord::VERSION::MAJOR >= 4
45
+ apply_finder_options(options, silence_deprecation = true)
46
+ else
47
+ apply_finder_options(options)
48
+ end
49
+
55
50
  including = (relation.eager_load_values + relation.includes_values).uniq
56
51
 
57
52
  if including.present?
@@ -71,11 +66,20 @@ module ActiveRecord
71
66
  end
72
67
 
73
68
  class PostgreSQLCursor
74
- def initialize_with_rails_3(model, cursor_name, relation, join_dependency = nil)
69
+ def initialize_with_rails(model, cursor_name, relation, join_dependency = nil)
75
70
  @relation = relation
76
- initialize_without_rails_3(model, cursor_name, relation.to_sql, join_dependency)
71
+
72
+ query = if ActiveRecord::VERSION::MAJOR >= 4
73
+ model.connection.unprepared_statement do
74
+ relation.to_sql
75
+ end
76
+ else
77
+ relation.to_sql
78
+ end
79
+
80
+ initialize_without_rails(model, cursor_name, query, join_dependency)
77
81
  end
78
- alias_method_chain :initialize, :rails_3
82
+ alias_method_chain :initialize, :rails
79
83
  end
80
84
  end
81
85
 
@@ -85,6 +89,10 @@ end
85
89
 
86
90
  class ActiveRecord::Base
87
91
  class << self
88
- delegate :cursor, :to => :scoped
92
+ if ActiveRecord::VERSION::MAJOR >= 4
93
+ delegate :cursor, :to => :all
94
+ else
95
+ delegate :cursor, :to => :scoped
96
+ end
89
97
  end
90
98
  end
@@ -1,8 +1,4 @@
1
1
 
2
- class ActiveRecord::Associations::ClassMethods::JoinDependency
3
- include ActiveRecord::PostgreSQLCursors::JoinDependency
4
- end
5
-
6
2
  module ActiveRecord
7
3
  class Base
8
4
  class << self
@@ -0,0 +1,7 @@
1
+
2
+ module ActiveRecord
3
+ module PostgreSQLCursors
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+
@@ -28,8 +28,6 @@ module ActiveRecord
28
28
  class PostgreSQLCursor
29
29
  include Enumerable
30
30
 
31
- attr_accessor :cursor_name
32
-
33
31
  def initialize(model, cursor_name, query, join_dependency = nil)
34
32
  @model = model
35
33
  @cursor_name = if cursor_name
@@ -100,8 +98,18 @@ module ActiveRecord
100
98
  end
101
99
  end
102
100
 
101
+ if ActiveRecord::VERSION::STRING >= '3.1'
102
+ class ActiveRecord::Associations::JoinDependency
103
+ include ActiveRecord::PostgreSQLCursors::JoinDependency
104
+ end
105
+ else
106
+ class ActiveRecord::Associations::ClassMethods::JoinDependency
107
+ include ActiveRecord::PostgreSQLCursors::JoinDependency
108
+ end
109
+ end
110
+
103
111
  if ActiveRecord::VERSION::MAJOR >= 3
104
- require File.join(File.dirname(__FILE__), 'postgresql_cursors_3')
112
+ require File.join(File.dirname(__FILE__), *%w{ active_record postgresql_cursors cursors })
105
113
  else
106
- require File.join(File.dirname(__FILE__), 'postgresql_cursors_2')
114
+ require File.join(File.dirname(__FILE__), *%w{ active_record postgresql_cursors cursors_2 })
107
115
  end
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class PostgreSQLCursorTests < Test::Unit::TestCase
5
+ class PostgreSQLCursorTests < MiniTest::Unit::TestCase
6
6
  include PostgreSQLCursorTestHelper
7
7
 
8
8
  def test_find_cursor
@@ -0,0 +1,17 @@
1
+ ---
2
+ # To modify the test database parameters, create a new file called
3
+ # local_database.yml and go nuts with settings. The "jdbc" settings
4
+ # are merged into the "arunit" settings as JDBC works over a TCP
5
+ # socket and those sorts of connections generally require some user
6
+ # credentials.
7
+
8
+ arunit:
9
+ adapter: "postgresql"
10
+ database: "postgresql_cursors_unit_tests"
11
+ min_messages: "warning"
12
+ schema_search_path: "public"
13
+
14
+ jdbc:
15
+ host: "localhost"
16
+ adapter: "jdbcpostgresql"
17
+
@@ -1,31 +1,56 @@
1
1
 
2
- ACTIVERECORD_GEM_VERSION = ENV['ACTIVERECORD_GEM_VERSION'] || '~> 3.0.3'
2
+ if RUBY_VERSION >= '1.9'
3
+ require 'simplecov'
3
4
 
4
- require 'rubygems'
5
- gem 'activerecord', ACTIVERECORD_GEM_VERSION
5
+ SimpleCov.command_name('Unit Tests')
6
+ SimpleCov.start do
7
+ add_filter '/test/'
8
+ end
9
+ end
6
10
 
11
+ require 'rubygems'
7
12
  require 'active_support'
8
13
  require 'active_support/core_ext/module/aliasing'
9
14
  require 'active_record'
10
- require 'test/unit'
11
15
  require 'logger'
16
+ require 'minitest/autorun'
17
+
18
+ if RUBY_VERSION >= '1.9'
19
+ require 'minitest/reporters'
20
+ end
21
+
12
22
  require File.join(File.dirname(__FILE__), *%w{ .. lib activerecord-postgresql-cursors })
13
23
 
14
- ActiveRecord::Base.logger = Logger.new("debug.log")
24
+ ActiveRecord::Base.logger = Logger.new("debug.log") if ENV['ENABLE_LOGGER']
15
25
  ActiveRecord::Base.configurations = {
16
- 'arunit' => {
17
- :adapter => 'postgresql',
18
- :database => 'postgresql_cursors_unit_tests',
19
- :min_messages => 'warning',
20
- :schema_search_path => 'public'
21
- }
26
+ 'arunit' => {}
22
27
  }
23
28
 
29
+ %w{
30
+ database.yml
31
+ local_database.yml
32
+ }.each do |file|
33
+ file = File.join('test', file)
34
+
35
+ next unless File.exists?(file)
36
+
37
+ configuration = YAML.load(File.read(file))
38
+
39
+ if configuration['arunit']
40
+ ActiveRecord::Base.configurations['arunit'].merge!(configuration['arunit'])
41
+ end
42
+
43
+ if defined?(JRUBY_VERSION) && configuration['jdbc']
44
+ ActiveRecord::Base.configurations['arunit'].merge!(configuration['jdbc'])
45
+ end
46
+ end
47
+
24
48
  ActiveRecord::Base.establish_connection 'arunit'
25
49
  ARBC = ActiveRecord::Base.connection
26
50
 
51
+ puts "Ruby version #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
27
52
  puts "Testing against ActiveRecord #{Gem.loaded_specs['activerecord'].version.to_s}"
28
- if postgresql_version = ARBC.query('SELECT version()').flatten.to_s
53
+ if postgresql_version = ARBC.select_rows('SELECT version()').flatten.to_s
29
54
  puts "PostgreSQL info from version(): #{postgresql_version}"
30
55
  end
31
56
 
@@ -69,3 +94,8 @@ module PostgreSQLCursorTestHelper
69
94
  end
70
95
  end
71
96
  end
97
+
98
+ if RUBY_VERSION >= '1.9'
99
+ MiniTest::Reporters.use!(MiniTest::Reporters::SpecReporter.new)
100
+ end
101
+
metadata CHANGED
@@ -1,75 +1,74 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgresql-cursors
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - J Smith
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-09-28 00:00:00 Z
19
- dependencies: []
20
-
11
+ date: 2013-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
21
27
  description: Provides some support for PostgreSQL cursors in ActiveRecord.
22
28
  email: code@zoocasa.com
23
29
  executables: []
24
-
25
30
  extensions: []
26
-
27
- extra_rdoc_files:
31
+ extra_rdoc_files:
28
32
  - README.rdoc
29
- files:
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Guardfile
30
37
  - MIT-LICENSE
31
38
  - README.rdoc
32
39
  - Rakefile
33
- - VERSION
34
40
  - activerecord-postgresql-cursors.gemspec
35
- - init.rb
41
+ - lib/active_record/postgresql_cursors/cursors.rb
42
+ - lib/active_record/postgresql_cursors/cursors_2.rb
43
+ - lib/active_record/postgresql_cursors/version.rb
36
44
  - lib/activerecord-postgresql-cursors.rb
37
- - lib/postgresql_cursors_2.rb
38
- - lib/postgresql_cursors_3.rb
39
- - test/cursor_test.rb
45
+ - test/cursor_tests.rb
46
+ - test/database.yml
40
47
  - test/test_helper.rb
41
48
  homepage: http://github.com/zoocasa/activerecord-postgresql-cursors
42
49
  licenses: []
43
-
50
+ metadata: {}
44
51
  post_install_message:
45
52
  rdoc_options: []
46
-
47
- require_paths:
53
+ require_paths:
48
54
  - lib
49
- required_ruby_version: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- hash: 3
55
- segments:
56
- - 0
57
- version: "0"
58
- required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- hash: 3
64
- segments:
65
- - 0
66
- version: "0"
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
67
65
  requirements: []
68
-
69
66
  rubyforge_project:
70
- rubygems_version: 1.8.8
67
+ rubygems_version: 2.0.3
71
68
  signing_key:
72
- specification_version: 3
69
+ specification_version: 4
73
70
  summary: Provides some support for PostgreSQL cursors in ActiveRecord.
74
- test_files: []
75
-
71
+ test_files:
72
+ - test/cursor_tests.rb
73
+ - test/database.yml
74
+ - test/test_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.2
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
-
2
- require File.join(File.dirname(__FILE__), 'lib', 'postgresql_cursors')