benhoskings-ambitious-activerecord 0.1.3.2 → 0.1.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{ambitious-activerecord}
7
- s.version = "0.1.3.2"
7
+ s.version = "0.1.3.3"
8
8
 
9
9
  s.specification_version = 2 if s.respond_to? :specification_version=
10
10
 
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.description = %q{An ambitious adapter for ActiveRecord}
15
15
  s.email = %q{chris@ozmm.org, ben@hoskings.net}
16
16
  s.extra_rdoc_files = ["lib/ambition/adapters/active_record/base.rb", "lib/ambition/adapters/active_record/query.rb", "lib/ambition/adapters/active_record/select.rb", "lib/ambition/adapters/active_record/slice.rb", "lib/ambition/adapters/active_record/sort.rb", "lib/ambition/adapters/active_record/statements.rb", "lib/ambition/adapters/active_record.rb"]
17
- s.files = ["lib/ambition/adapters/active_record/base.rb", "lib/ambition/adapters/active_record/query.rb", "lib/ambition/adapters/active_record/select.rb", "lib/ambition/adapters/active_record/slice.rb", "lib/ambition/adapters/active_record/sort.rb", "lib/ambition/adapters/active_record/statements.rb", "lib/ambition/adapters/active_record.rb", "test/benchmark.rb", "test/chaining_test.rb", "test/count_test.rb", "test/enumerable_test.rb", "test/helper.rb", "test/join_test.rb", "test/profiler.rb", "test/ruby_test.rb", "test/select_test.rb", "test/slice_test.rb", "test/sort_test.rb", "test/source_test.rb", "test/types_test.rb", "Manifest", "ambitious-activerecord.gemspec"]
17
+ s.files = ["lib/ambition/adapters/active_record/base.rb", "lib/ambition/adapters/active_record/query.rb", "lib/ambition/adapters/active_record/select.rb", "lib/ambition/adapters/active_record/slice.rb", "lib/ambition/adapters/active_record/sort.rb", "lib/ambition/adapters/active_record/statements.rb", "lib/ambition/adapters/active_record/context.rb", "lib/ambition/adapters/active_record.rb", "test/benchmark.rb", "test/chaining_test.rb", "test/count_test.rb", "test/enumerable_test.rb", "test/helper.rb", "test/join_test.rb", "test/profiler.rb", "test/ruby_test.rb", "test/select_test.rb", "test/slice_test.rb", "test/sort_test.rb", "test/source_test.rb", "test/types_test.rb", "Manifest", "ambitious-activerecord.gemspec"]
18
18
  s.has_rdoc = true
19
19
  s.homepage = %q{http://ambition.rubyforge.org/}
20
20
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ambitious-activerecord", "--main", "README"]
@@ -0,0 +1,43 @@
1
+ module Ambition
2
+ class Context
3
+
4
+ def find *args
5
+ with_context_scope(to_hash) { owner.find *args }
6
+ end
7
+ def find_with_deleted *args
8
+ with_context_scope(to_hash) { owner.find_with_deleted *args }
9
+ end
10
+
11
+ def count *args
12
+ with_context_scope(to_hash) { owner.count *args }
13
+ end
14
+ alias_method :size, :count
15
+
16
+ def count_with_deleted *args
17
+ with_context_scope(to_hash) { owner.count_with_deleted *args }
18
+ end
19
+
20
+
21
+ protected
22
+
23
+ def with_context_scope find_conditions, &block
24
+ owner.send :with_scope, :find => find_conditions do
25
+ yield
26
+ end
27
+ end
28
+
29
+ def within outer_scope, join_association
30
+ context = ambition_context
31
+
32
+ unless outer_scope.nil?
33
+ raise "#{owner} doesn't have a #{join_association.inspect} association. Make sure it's spelt and pluralized correctly and speficied as a symbol." unless context.owner.reflections.has_key?(join_association)
34
+
35
+ (context.stash[:joins] ||= []).push(join_association).concat(outer_scope.stash[:joins] || []).uniq!
36
+ context.clauses[:select].concat(outer_scope.clauses[:select]).uniq!
37
+ end
38
+
39
+ context
40
+ end
41
+
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benhoskings-ambitious-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.2
4
+ version: 0.1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -54,6 +54,7 @@ files:
54
54
  - lib/ambition/adapters/active_record/slice.rb
55
55
  - lib/ambition/adapters/active_record/sort.rb
56
56
  - lib/ambition/adapters/active_record/statements.rb
57
+ - lib/ambition/adapters/active_record/context.rb
57
58
  - lib/ambition/adapters/active_record.rb
58
59
  - test/benchmark.rb
59
60
  - test/chaining_test.rb