thoughtbot-pacecar 1.1.4 → 1.1.5
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/lib/pacecar/associations.rb +39 -0
- metadata +2 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Pacecar
|
|
2
|
+
module Associations
|
|
3
|
+
def self.included(base)
|
|
4
|
+
base.extend ClassMethods
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module ClassMethods
|
|
8
|
+
|
|
9
|
+
def has_recent_records(*names)
|
|
10
|
+
names.each do |name|
|
|
11
|
+
named_scope "recent_#{name}_since".to_sym, lambda { |since|
|
|
12
|
+
{
|
|
13
|
+
:conditions => [conditions_for_name(name), { :since_time => since }]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
unless names.first == names.last
|
|
18
|
+
named_scope "recent_#{names.join('_or_')}_since".to_sym, lambda { |since|
|
|
19
|
+
{
|
|
20
|
+
:conditions => [names.collect { |name| conditions_for_name(name) }.join(' or '), { :since_time => since }]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
named_scope "recent_#{names.join('_and_')}_since".to_sym, lambda { |since|
|
|
24
|
+
{
|
|
25
|
+
:conditions => [names.collect { |name| conditions_for_name(name) }.join(' and '), { :since_time => since }]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
protected
|
|
32
|
+
|
|
33
|
+
def conditions_for_name(name)
|
|
34
|
+
"((select count(*) from \"#{name}\" where \"#{name}\".#{reflections[name].primary_key_name} = #{quoted_table_name}.id and \"#{name}\".created_at > :since_time) > 0)"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: thoughtbot-pacecar
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Jankowski
|
|
@@ -25,6 +25,7 @@ files:
|
|
|
25
25
|
- init.rb
|
|
26
26
|
- lib
|
|
27
27
|
- lib/pacecar
|
|
28
|
+
- lib/pacecar/associations.rb
|
|
28
29
|
- lib/pacecar/boolean.rb
|
|
29
30
|
- lib/pacecar/datetime.rb
|
|
30
31
|
- lib/pacecar/duration.rb
|