acts_as_sourceable 2.1.6 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/acts_as_sourceable/acts_as_sourceable.rb +17 -34
- metadata +24 -6
- checksums.yaml +0 -7
@@ -30,10 +30,10 @@ module ActsAsSourceable
|
|
30
30
|
scope :sourced, lambda { where(options[:cache_column] => true) }
|
31
31
|
scope :unsourced, lambda { where(options[:cache_column] => false) }
|
32
32
|
elsif options[:through]
|
33
|
-
scope :sourced, lambda { joins(options[:through]).group("#{table_name}.#{primary_key}") }
|
33
|
+
scope :sourced, lambda { from(unscoped.joins(options[:through]).group("#{table_name}.#{primary_key}"), table_name) }
|
34
34
|
scope :unsourced, lambda { joins("LEFT OUTER JOIN (#{sourced.to_sql}) sourced ON sourced.id = #{table_name}.id").where("sourced.id IS NULL") }
|
35
35
|
else
|
36
|
-
scope :sourced, lambda { joins(:sourceable_registry_entries).group("#{table_name}.#{primary_key}") }
|
36
|
+
scope :sourced, lambda { from(unscoped.joins(:sourceable_registry_entries).group("#{table_name}.#{primary_key}"), table_name) }
|
37
37
|
scope :unsourced, lambda { joins("LEFT OUTER JOIN (#{ActsAsSourceable::RegistryEntry.select('sourceable_id AS id').where(:sourceable_type => self).to_sql}) sourced ON sourced.id = #{table_name}.id").where("sourced.id IS NULL") }
|
38
38
|
end
|
39
39
|
|
@@ -51,53 +51,36 @@ module ActsAsSourceable
|
|
51
51
|
else
|
52
52
|
scope :orphaned, lambda { unsourced }
|
53
53
|
end
|
54
|
-
|
55
|
-
# ACTIVE RELATION SETUP
|
56
|
-
ActiveRecord::Relation.send(:include, ActsAsSourceable::ActiveRelationMethods)
|
57
|
-
|
58
|
-
# Delegate the relation methods to the relation so we can call Klass.unsourced (do this in the metaclass because all these methods are class level)
|
59
|
-
class << self
|
60
|
-
delegate :add_sources, :add_source, :remove_source, :remove_sources, :unsource, :to => :scoped
|
61
|
-
end
|
62
54
|
end
|
63
55
|
end
|
64
|
-
|
65
|
-
module
|
56
|
+
|
57
|
+
module ClassMethods
|
58
|
+
def acts_like_sourceable?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
66
62
|
def remove_sources(*sources)
|
67
|
-
|
63
|
+
find_each{|record| record.remove_sources(*sources) }
|
68
64
|
end
|
69
65
|
alias_method :remove_source, :remove_sources
|
70
66
|
|
71
67
|
def add_sources(*sources)
|
72
|
-
|
68
|
+
find_each{|record| record.add_sources(*sources) }
|
73
69
|
end
|
74
70
|
alias_method :add_source, :add_sources
|
75
|
-
|
71
|
+
|
76
72
|
def unsource
|
77
73
|
# OPTIMIZATION: it's faster to only set the cache column to false if it is true instead of setting all to false indiscriminately
|
78
|
-
|
79
|
-
|
74
|
+
where(acts_as_sourceable_options[:cache_column] => true).update_all(acts_as_sourceable_options[:cache_column] => false) if acts_as_sourceable_options[:cache_column]
|
75
|
+
ActsAsSourceable::RegistryEntry.where(:sourceable_type => self.name, :sourceable_id => self.all).delete_all
|
80
76
|
end
|
81
77
|
end
|
82
78
|
|
83
|
-
module GroupScopeExtensions
|
84
|
-
# Extension for scopes where we're grouping but want to be able to call count
|
85
|
-
def count
|
86
|
-
connection.select_value("SELECT count(1) FROM (#{to_sql}) AS count_all").to_i
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
module ClassMethods
|
91
|
-
def acts_like_sourceable?
|
92
|
-
true
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
79
|
module InstanceMethods
|
97
80
|
def acts_like_sourceable?
|
98
81
|
true
|
99
82
|
end
|
100
|
-
|
83
|
+
|
101
84
|
def sourced?
|
102
85
|
if acts_as_sourceable_options[:cache_column]
|
103
86
|
self[acts_as_sourceable_options[:cache_column]]
|
@@ -133,13 +116,13 @@ module ActsAsSourceable
|
|
133
116
|
update_sourceable_cache_column(false) if self.sourceable_registry_entries.empty?
|
134
117
|
end
|
135
118
|
alias_method :remove_source, :remove_sources
|
136
|
-
|
119
|
+
|
137
120
|
private
|
138
121
|
|
139
122
|
def source_scope(source)
|
140
123
|
ActsAsSourceable::RegistryEntry.where(:sourceable_type => self.class.name, :sourceable_id => self.id, :source_type => source.class, :source_id => source.id)
|
141
124
|
end
|
142
|
-
|
125
|
+
|
143
126
|
def update_sourceable_cache_column(value = nil)
|
144
127
|
return unless acts_as_sourceable_options[:cache_column] # Update via sql because we don't need callbacks and validations called
|
145
128
|
|
@@ -182,4 +165,4 @@ module ActsAsSourceable
|
|
182
165
|
end
|
183
166
|
end
|
184
167
|
end
|
185
|
-
end
|
168
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_sourceable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Nicholas Jakobsen
|
@@ -9,8 +10,24 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
13
|
+
date: 2013-09-04 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '4.0'
|
14
31
|
description: Allows the RRN to perform garbage collection on categories that are no
|
15
32
|
longer referenced.
|
16
33
|
email: technical@rrnpilot.org
|
@@ -24,25 +41,26 @@ files:
|
|
24
41
|
- README.md
|
25
42
|
homepage: http://github.com/rrn/acts_as_sourceable
|
26
43
|
licenses: []
|
27
|
-
metadata: {}
|
28
44
|
post_install_message:
|
29
45
|
rdoc_options: []
|
30
46
|
require_paths:
|
31
47
|
- lib
|
32
48
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
33
50
|
requirements:
|
34
51
|
- - '>='
|
35
52
|
- !ruby/object:Gem::Version
|
36
53
|
version: '0'
|
37
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
38
56
|
requirements:
|
39
57
|
- - '>='
|
40
58
|
- !ruby/object:Gem::Version
|
41
59
|
version: '0'
|
42
60
|
requirements: []
|
43
61
|
rubyforge_project:
|
44
|
-
rubygems_version:
|
62
|
+
rubygems_version: 1.8.25
|
45
63
|
signing_key:
|
46
|
-
specification_version:
|
64
|
+
specification_version: 3
|
47
65
|
summary: perform garbage collection on categories that are no longer referenced
|
48
66
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: cbea8083a7e55b7564806fdb3b45949ba6f3ecf0
|
4
|
-
data.tar.gz: 769945cd32379edd5fb48cde928313261dd55fe8
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: e0fff5cc8519cda5dbd5b9a1735edfc27b223a344680a3374538847988043561bfe59520f055f9f4a390926f027b000f03ae0d93e516661b55f67e8d4775b20a
|
7
|
-
data.tar.gz: 4be367a71ea15eb1ec0a1636ce2ff04baf1c1384bdce5645613c63530b482a31c5d22c65c61039935ab08873a3c878496598c31fc2f3e83b73324711c2f1fa41
|