cohort_scope 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/cohort_scope.rb +26 -13
- metadata +4 -3
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gem.description = %Q{Provides big_cohort, which widens by finding the constraint that eliminates the most records and removing it. Also provides strict_cohort, which widens by eliminating constraints in order.}
|
10
10
|
gem.email = "seamus@abshere.net"
|
11
11
|
gem.homepage = "http://github.com/seamusabshere/cohort_scope"
|
12
|
-
gem.authors = ["Seamus Abshere", "Andy Rossmeissl"]
|
12
|
+
gem.authors = ["Seamus Abshere", "Andy Rossmeissl", "Derek Kastner"]
|
13
13
|
gem.add_dependency "activesupport", ">=3.0.0.beta2"
|
14
14
|
gem.add_dependency "activerecord", ">=3.0.0.beta2"
|
15
15
|
gem.add_development_dependency "shoulda", ">= 2.10.3"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/cohort_scope.rb
CHANGED
@@ -1,28 +1,41 @@
|
|
1
|
-
require 'active_support'
|
2
1
|
require 'active_record'
|
3
|
-
require 'active_support
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/version'
|
4
|
+
%w{
|
5
|
+
active_support/core_ext/module/delegation
|
6
|
+
}.each do |active_support_3_requirement|
|
7
|
+
require active_support_3_requirement
|
8
|
+
end if ActiveSupport::VERSION::MAJOR == 3
|
4
9
|
|
5
10
|
module ActiveRecord
|
11
|
+
class Base
|
12
|
+
def massive_unscoped
|
13
|
+
@massive_unscoped ||= MassiveRelation.new(self, arel_table)
|
14
|
+
finder_needs_type_condition? ? @massive_unscoped.where(type_condition) : @massive_unscoped
|
15
|
+
end
|
16
|
+
end
|
6
17
|
module NamedScope
|
7
18
|
module ClassMethods
|
8
|
-
#
|
19
|
+
# Work with a MassiveRelation, which, when inspected, does not generate a huge string.
|
9
20
|
def massive_scoped(options = {}, &block)
|
10
21
|
if options.present?
|
11
|
-
|
22
|
+
scoped = current_scoped_methods ? massive_unscoped.merge(current_scoped_methods) : unscoped.clone
|
23
|
+
relation = scoped.apply_finder_options(options)
|
24
|
+
block_given? ? relation.extending(Module.new(&block)) : relation
|
12
25
|
else
|
13
26
|
raise "MassiveScopes should be created with options"
|
14
27
|
end
|
15
28
|
end
|
16
29
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
30
|
+
end
|
31
|
+
class MassiveRelation < Relation
|
32
|
+
# Don't try to output a massive string.
|
33
|
+
def inspect
|
34
|
+
"<Massive relation: #{count} members>"
|
35
|
+
end
|
36
|
+
# Don't try to put everything into json.
|
37
|
+
def to_json(*args)
|
38
|
+
{ :members => count }.to_json
|
26
39
|
end
|
27
40
|
end
|
28
41
|
end
|
metadata
CHANGED
@@ -5,17 +5,18 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Seamus Abshere
|
13
13
|
- Andy Rossmeissl
|
14
|
+
- Derek Kastner
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-04-
|
19
|
+
date: 2010-04-26 00:00:00 -04:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|