meta_where 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
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
+
21
+ ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ gem 'arel', :git => 'git://github.com/rails/arel.git', :tag => 'v2.0.8.beta.20110131120940'
5
+ git 'git://github.com/rails/rails.git', :branch => '3-0-stable' do
6
+ gem 'activesupport'
7
+ gem 'activerecord'
8
+ end
data/Rakefile CHANGED
@@ -1,76 +1,11 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "meta_where"
8
- gem.summary = %Q{ActiveRecord 3 query syntax on steroids.}
9
- gem.description = %Q{
10
- MetaWhere offers the ability to call any Arel predicate methods
11
- (with a few convenient aliases) on your Model's attributes instead
12
- of the ones normally offered by ActiveRecord's hash parameters. It also
13
- adds convenient syntax for order clauses, smarter mapping of nested hash
14
- conditions, and a debug_sql method to see the real SQL your code is
15
- generating without running it against the database. If you like the new
16
- AR 3.0 query interface, you'll love it with MetaWhere.
17
- }
18
- gem.email = "ernie@metautonomo.us"
19
- gem.homepage = "http://metautonomo.us/projects/metawhere/"
20
- gem.authors = ["Ernie Miller"]
21
- gem.add_development_dependency "shoulda"
22
- gem.add_dependency "activerecord", "~> 3.0.4"
23
- gem.add_dependency "activesupport", "~> 3.0.4"
24
- gem.add_dependency "arel", "~> 2.0.8"
25
- gem.post_install_message = <<END
26
-
27
- *** Thanks for installing MetaWhere! ***
28
- Be sure to check out http://metautonomo.us/projects/metawhere/ for a
29
- walkthrough of MetaWhere's features, and click the donate button if
30
- you're feeling especially appreciative. It'd help me justify this
31
- "open source" stuff to my lovely wife. :)
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+ require 'rake/testtask'
32
4
 
33
- END
34
- end
35
- Jeweler::GemcutterTasks.new
36
- rescue LoadError
37
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
38
- end
5
+ Bundler::GemHelper.install_tasks
39
6
 
40
- require 'rake/testtask'
41
7
  Rake::TestTask.new(:test) do |test|
42
- test.libs << 'lib' << 'test'
43
- test.libs << 'vendor/rails/activerecord/lib'
44
- test.libs << 'vendor/rails/activesupport/lib'
45
- test.libs << 'vendor/arel/lib'
46
- test.pattern = 'test/**/test_*.rb'
47
- test.verbose = true
8
+ test.libs << 'test'
48
9
  end
49
10
 
50
- begin
51
- require 'rcov/rcovtask'
52
- Rcov::RcovTask.new do |test|
53
- test.libs << 'test'
54
- test.pattern = 'test/**/test_*.rb'
55
- test.verbose = true
56
- end
57
- rescue LoadError
58
- task :rcov do
59
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
60
- end
61
- end
62
-
63
- # Don't check dependencies since we're testing with vendored libraries
64
- # task :test => :check_dependencies
65
-
66
- task :default => :test
67
-
68
- require 'rake/rdoctask'
69
- Rake::RDocTask.new do |rdoc|
70
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
71
-
72
- rdoc.rdoc_dir = 'rdoc'
73
- rdoc.title = "meta_where #{version}"
74
- rdoc.rdoc_files.include('README*')
75
- rdoc.rdoc_files.include('lib/**/*.rb')
76
- end
11
+ task :default => :test
@@ -44,10 +44,8 @@ require 'core_ext/hash'
44
44
  require 'meta_where/visitors/attribute'
45
45
  require 'meta_where/visitors/predicate'
46
46
  require 'meta_where/association_reflection'
47
- require 'meta_where/belongs_to_polymorphic_association'
48
47
  require 'meta_where/relation'
49
48
  require 'meta_where/join_dependency'
50
49
  ActiveRecord::Relation.send(:include, MetaWhere::Relation)
51
50
  ActiveRecord::Reflection::AssociationReflection.send(:include, MetaWhere::AssociationReflection)
52
- ActiveRecord::Associations::ClassMethods::JoinDependency.send(:include, MetaWhere::JoinDependency)
53
- ActiveRecord::Associations::BelongsToPolymorphicAssociation.send(:include, MetaWhere::BelongsToPolymorphicAssociation)
51
+ ActiveRecord::Associations::ClassMethods::JoinDependency.send(:include, MetaWhere::JoinDependency)
@@ -92,7 +92,7 @@ module MetaWhere
92
92
  ]
93
93
 
94
94
  if options[:conditions]
95
- @join << interpolate_sql(sanitize_sql(options[:conditions], aliased_table_name))
95
+ @join << process_conditions(options[:conditions], aliased_table_name)
96
96
  end
97
97
 
98
98
  @join
@@ -237,13 +237,11 @@ module MetaWhere
237
237
  def collapse_wheres(arel, wheres)
238
238
  binaries = wheres.grep(Arel::Nodes::Binary)
239
239
 
240
- groups = binaries.group_by do |binary|
241
- [binary.class, binary.left]
242
- end
240
+ groups = binaries.group_by {|b| [b.class, b.left]}
243
241
 
244
242
  groups.each do |_, bins|
245
243
  test = bins.inject(bins.shift) do |memo, expr|
246
- memo.or(expr)
244
+ memo.and(expr)
247
245
  end
248
246
  arel = arel.where(test)
249
247
  end
@@ -0,0 +1,3 @@
1
+ module MetaWhere
2
+ VERSION = "1.0.4"
3
+ end
@@ -1,15 +1,15 @@
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 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "meta_where/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{meta_where}
8
- s.version = "1.0.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ernie Miller"]
12
- s.date = %q{2011-02-10}
6
+ s.name = "meta_where"
7
+ s.version = MetaWhere::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ernie Miller"]
10
+ s.email = ["ernie@metautonomo.us"]
11
+ s.homepage = "http://metautonomo.us/projects/metawhere"
12
+ s.summary = %q{ActiveRecord 3 query syntax on steroids.}
13
13
  s.description = %q{
14
14
  MetaWhere offers the ability to call any Arel predicate methods
15
15
  (with a few convenient aliases) on your Model's attributes instead
@@ -19,62 +19,6 @@ Gem::Specification.new do |s|
19
19
  generating without running it against the database. If you like the new
20
20
  AR 3.0 query interface, you'll love it with MetaWhere.
21
21
  }
22
- s.email = %q{ernie@metautonomo.us}
23
- s.extra_rdoc_files = [
24
- "LICENSE",
25
- "README.rdoc"
26
- ]
27
- s.files = [
28
- ".document",
29
- ".gitmodules",
30
- "CHANGELOG",
31
- "LICENSE",
32
- "README.rdoc",
33
- "Rakefile",
34
- "VERSION",
35
- "lib/core_ext/hash.rb",
36
- "lib/core_ext/symbol.rb",
37
- "lib/core_ext/symbol_operators.rb",
38
- "lib/meta_where.rb",
39
- "lib/meta_where/association_reflection.rb",
40
- "lib/meta_where/belongs_to_polymorphic_association.rb",
41
- "lib/meta_where/column.rb",
42
- "lib/meta_where/compound.rb",
43
- "lib/meta_where/condition.rb",
44
- "lib/meta_where/condition_operators.rb",
45
- "lib/meta_where/function.rb",
46
- "lib/meta_where/join_dependency.rb",
47
- "lib/meta_where/join_type.rb",
48
- "lib/meta_where/not.rb",
49
- "lib/meta_where/relation.rb",
50
- "lib/meta_where/utility.rb",
51
- "lib/meta_where/visitors/attribute.rb",
52
- "lib/meta_where/visitors/predicate.rb",
53
- "lib/meta_where/visitors/visitor.rb",
54
- "meta_where.gemspec",
55
- "test/fixtures/companies.yml",
56
- "test/fixtures/company.rb",
57
- "test/fixtures/data_type.rb",
58
- "test/fixtures/data_types.yml",
59
- "test/fixtures/developer.rb",
60
- "test/fixtures/developers.yml",
61
- "test/fixtures/developers_projects.yml",
62
- "test/fixtures/fixed_bid_project.rb",
63
- "test/fixtures/invalid_company.rb",
64
- "test/fixtures/invalid_developer.rb",
65
- "test/fixtures/note.rb",
66
- "test/fixtures/notes.yml",
67
- "test/fixtures/people.yml",
68
- "test/fixtures/person.rb",
69
- "test/fixtures/project.rb",
70
- "test/fixtures/projects.yml",
71
- "test/fixtures/schema.rb",
72
- "test/fixtures/time_and_materials_project.rb",
73
- "test/helper.rb",
74
- "test/test_base.rb",
75
- "test/test_relations.rb"
76
- ]
77
- s.homepage = %q{http://metautonomo.us/projects/metawhere/}
78
22
  s.post_install_message = %q{
79
23
  *** Thanks for installing MetaWhere! ***
80
24
  Be sure to check out http://metautonomo.us/projects/metawhere/ for a
@@ -83,45 +27,22 @@ you're feeling especially appreciative. It'd help me justify this
83
27
  "open source" stuff to my lovely wife. :)
84
28
 
85
29
  }
86
- s.require_paths = ["lib"]
87
- s.rubygems_version = %q{1.5.0}
88
- s.summary = %q{ActiveRecord 3 query syntax on steroids.}
89
- s.test_files = [
90
- "test/fixtures/company.rb",
91
- "test/fixtures/data_type.rb",
92
- "test/fixtures/developer.rb",
93
- "test/fixtures/fixed_bid_project.rb",
94
- "test/fixtures/invalid_company.rb",
95
- "test/fixtures/invalid_developer.rb",
96
- "test/fixtures/note.rb",
97
- "test/fixtures/person.rb",
98
- "test/fixtures/project.rb",
99
- "test/fixtures/schema.rb",
100
- "test/fixtures/time_and_materials_project.rb",
101
- "test/helper.rb",
102
- "test/test_base.rb",
103
- "test/test_relations.rb"
30
+
31
+ s.extra_rdoc_files = [
32
+ "LICENSE",
33
+ "README.rdoc"
104
34
  ]
105
35
 
106
- if s.respond_to? :specification_version then
107
- s.specification_version = 3
36
+ s.rubyforge_project = "meta_where"
108
37
 
109
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
110
- s.add_development_dependency(%q<shoulda>, [">= 0"])
111
- s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.4"])
112
- s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.4"])
113
- s.add_runtime_dependency(%q<arel>, ["~> 2.0.8"])
114
- else
115
- s.add_dependency(%q<shoulda>, [">= 0"])
116
- s.add_dependency(%q<activerecord>, ["~> 3.0.4"])
117
- s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
118
- s.add_dependency(%q<arel>, ["~> 2.0.8"])
119
- end
120
- else
121
- s.add_dependency(%q<shoulda>, [">= 0"])
122
- s.add_dependency(%q<activerecord>, ["~> 3.0.4"])
123
- s.add_dependency(%q<activesupport>, ["~> 3.0.4"])
124
- s.add_dependency(%q<arel>, ["~> 2.0.8"])
125
- end
126
- end
38
+ s.add_dependency 'activerecord', '~> 3.0.0'
39
+ s.add_dependency 'activesupport', '~> 3.0.0'
40
+ s.add_dependency 'arel', '~> 2.0.7'
41
+ s.add_development_dependency 'shoulda'
42
+ s.add_development_dependency 'sqlite3', '~> 1.3.3'
127
43
 
44
+ s.files = `git ls-files`.split("\n")
45
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
46
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
47
+ s.require_paths = ["lib"]
48
+ end
@@ -1,4 +1,6 @@
1
- require 'rubygems'
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.setup
2
4
  require 'test/unit'
3
5
  require 'shoulda'
4
6
  require 'active_record'
@@ -27,8 +29,5 @@ end
27
29
 
28
30
  Fixtures.create_fixtures(FIXTURES_PATH, ActiveRecord::Base.connection.tables)
29
31
 
30
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
31
- $LOAD_PATH.unshift(File.dirname(__FILE__))
32
-
33
32
  class Test::Unit::TestCase
34
33
  end
@@ -338,10 +338,10 @@ class TestRelations < Test::Unit::TestCase
338
338
  assert_same_elements Developer.all, query.all
339
339
  end
340
340
 
341
- should "merge multiple conditions on the same column and predicate with ORs" do
342
- assert_match /"developers"."name" = 'blah' OR "developers"."name" = 'blah2'/,
341
+ should "merge multiple conditions on the same column and predicate with ANDs" do
342
+ assert_match /"developers"."name" = 'blah' AND "developers"."name" = 'blah2'/,
343
343
  @r.where(:name => 'blah').where(:name => 'blah2').to_sql
344
- assert_match /"developers"."name" LIKE '%blah%' OR "developers"."name" LIKE '%blah2%'/,
344
+ assert_match /"developers"."name" LIKE '%blah%' AND "developers"."name" LIKE '%blah2%'/,
345
345
  @r.where(:name.matches => '%blah%').where(:name.matches => '%blah2%').to_sql
346
346
  end
347
347
 
@@ -356,7 +356,7 @@ class TestRelations < Test::Unit::TestCase
356
356
  end
357
357
 
358
358
  should "eager load companies" do
359
- assert_equal true, @r.all.first.instance_variables.include?(:@company)
359
+ assert_equal true, @r.all.first.company.loaded?
360
360
  end
361
361
  end
362
362
 
@@ -366,7 +366,7 @@ class TestRelations < Test::Unit::TestCase
366
366
  end
367
367
 
368
368
  should "eager load companies" do
369
- assert_equal true, @r.all.first.instance_variables.include?(:@company)
369
+ assert_equal true, @r.all.first.company.loaded?
370
370
  end
371
371
  end
372
372
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: meta_where
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.3
5
+ version: 1.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ernie Miller
@@ -10,55 +10,67 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-10 00:00:00 -05:00
13
+ date: 2011-02-28 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: shoulda
17
+ name: activerecord
18
18
  prerelease: false
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
- - - ">="
22
+ - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: "0"
25
- type: :development
24
+ version: 3.0.0
25
+ type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: activerecord
28
+ name: activesupport
29
29
  prerelease: false
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: 3.0.4
35
+ version: 3.0.0
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: activesupport
39
+ name: arel
40
40
  prerelease: false
41
41
  requirement: &id003 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: 3.0.4
46
+ version: 2.0.7
47
47
  type: :runtime
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
50
- name: arel
50
+ name: shoulda
51
51
  prerelease: false
52
52
  requirement: &id004 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
- - - ~>
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: 2.0.8
58
- type: :runtime
57
+ version: "0"
58
+ type: :development
59
59
  version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: sqlite3
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.3
69
+ type: :development
70
+ version_requirements: *id005
60
71
  description: "\n MetaWhere offers the ability to call any Arel predicate methods\n (with a few convenient aliases) on your Model's attributes instead\n of the ones normally offered by ActiveRecord's hash parameters. It also\n adds convenient syntax for order clauses, smarter mapping of nested hash\n conditions, and a debug_sql method to see the real SQL your code is\n generating without running it against the database. If you like the new\n AR 3.0 query interface, you'll love it with MetaWhere.\n "
61
- email: ernie@metautonomo.us
72
+ email:
73
+ - ernie@metautonomo.us
62
74
  executables: []
63
75
 
64
76
  extensions: []
@@ -68,18 +80,17 @@ extra_rdoc_files:
68
80
  - README.rdoc
69
81
  files:
70
82
  - .document
71
- - .gitmodules
83
+ - .gitignore
72
84
  - CHANGELOG
85
+ - Gemfile
73
86
  - LICENSE
74
87
  - README.rdoc
75
88
  - Rakefile
76
- - VERSION
77
89
  - lib/core_ext/hash.rb
78
90
  - lib/core_ext/symbol.rb
79
91
  - lib/core_ext/symbol_operators.rb
80
92
  - lib/meta_where.rb
81
93
  - lib/meta_where/association_reflection.rb
82
- - lib/meta_where/belongs_to_polymorphic_association.rb
83
94
  - lib/meta_where/column.rb
84
95
  - lib/meta_where/compound.rb
85
96
  - lib/meta_where/condition.rb
@@ -90,6 +101,7 @@ files:
90
101
  - lib/meta_where/not.rb
91
102
  - lib/meta_where/relation.rb
92
103
  - lib/meta_where/utility.rb
104
+ - lib/meta_where/version.rb
93
105
  - lib/meta_where/visitors/attribute.rb
94
106
  - lib/meta_where/visitors/predicate.rb
95
107
  - lib/meta_where/visitors/visitor.rb
@@ -116,7 +128,7 @@ files:
116
128
  - test/test_base.rb
117
129
  - test/test_relations.rb
118
130
  has_rdoc: true
119
- homepage: http://metautonomo.us/projects/metawhere/
131
+ homepage: http://metautonomo.us/projects/metawhere
120
132
  licenses: []
121
133
 
122
134
  post_install_message: "\n\
@@ -143,21 +155,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
155
  version: "0"
144
156
  requirements: []
145
157
 
146
- rubyforge_project:
147
- rubygems_version: 1.5.0
158
+ rubyforge_project: meta_where
159
+ rubygems_version: 1.5.3
148
160
  signing_key:
149
161
  specification_version: 3
150
162
  summary: ActiveRecord 3 query syntax on steroids.
151
163
  test_files:
164
+ - test/fixtures/companies.yml
152
165
  - test/fixtures/company.rb
153
166
  - test/fixtures/data_type.rb
167
+ - test/fixtures/data_types.yml
154
168
  - test/fixtures/developer.rb
169
+ - test/fixtures/developers.yml
170
+ - test/fixtures/developers_projects.yml
155
171
  - test/fixtures/fixed_bid_project.rb
156
172
  - test/fixtures/invalid_company.rb
157
173
  - test/fixtures/invalid_developer.rb
158
174
  - test/fixtures/note.rb
175
+ - test/fixtures/notes.yml
176
+ - test/fixtures/people.yml
159
177
  - test/fixtures/person.rb
160
178
  - test/fixtures/project.rb
179
+ - test/fixtures/projects.yml
161
180
  - test/fixtures/schema.rb
162
181
  - test/fixtures/time_and_materials_project.rb
163
182
  - test/helper.rb
@@ -1,6 +0,0 @@
1
- [submodule "vendor/arel"]
2
- path = vendor/arel
3
- url = git://github.com/rails/arel.git
4
- [submodule "vendor/rails"]
5
- path = vendor/rails
6
- url = git://github.com/rails/rails.git
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.3
@@ -1,16 +0,0 @@
1
- module MetaWhere
2
- module BelongsToPolymorphicAssociation
3
- def self.included(base)
4
- base.class_eval do
5
- alias_method_chain :conditions, :metawhere
6
- alias :sql_conditions :conditions_with_metawhere
7
- end
8
- end
9
-
10
- # How does this even work in core? Oh, nevermind, it doesn't. Patch submitted. :)
11
- def conditions_with_metawhere
12
- @conditions ||= interpolate_sql(association_class.send(:sanitize_sql, @reflection.options[:conditions])) if @reflection.options[:conditions]
13
- end
14
-
15
- end
16
- end