acts_as_sourceable 2.2.3 → 2.2.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.
- checksums.yaml +7 -0
- data/lib/acts_as_sourceable/acts_as_sourceable.rb +15 -2
- metadata +11 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b39a604c011e7ad62a4d071d63093c283aed6ab1
|
4
|
+
data.tar.gz: 43a9703b587064fc173ef5024343797270fe81db
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5e7688ce6b8a3adaee332625f49f10cbdce63a1a25722b4545480b9859f7e2e337a5cf24b3b2d166a73b8c131d23c95be277fdf95084d64cee18912d487a5ef
|
7
|
+
data.tar.gz: a3b5be49c223e0f105c6af9fa09ff8c60e717c491622b7d1f32d6e00d68d05d79eedb8070497add11c9086a0b18a7621883c77bea6ad2dd009cd4cfe6b5cd0a5
|
@@ -47,6 +47,7 @@ module ActsAsSourceable
|
|
47
47
|
# Create a scope that returns record that is not used by the associations in options[:used_by]
|
48
48
|
if options[:used_by]
|
49
49
|
scope :unused, lambda { where(Array(options[:used_by]).collect {|usage_association| "#{table_name}.id NOT IN (" + select("#{table_name}.id").joins(usage_association).group("#{table_name}.id").to_sql + ")"}.join(' AND ')) }
|
50
|
+
scope :used, lambda { where(Array(options[:used_by]).collect {|usage_association| "#{table_name}.id IN (" + select("#{table_name}.id").joins(usage_association).group("#{table_name}.id").to_sql + ")"}.join(' OR ')) }
|
50
51
|
scope :orphaned, lambda { unsourced.unused }
|
51
52
|
else
|
52
53
|
scope :orphaned, lambda { unsourced }
|
@@ -93,6 +94,18 @@ module ActsAsSourceable
|
|
93
94
|
!sourced?
|
94
95
|
end
|
95
96
|
|
97
|
+
def used?
|
98
|
+
acts_as_sourceable_options[:used_by].any?{|association| send(association).present? }
|
99
|
+
end
|
100
|
+
|
101
|
+
def unused?
|
102
|
+
!used?
|
103
|
+
end
|
104
|
+
|
105
|
+
def usages
|
106
|
+
Hash[acts_as_sourceable_options[:used_by].collect{|association| [association, send(association)] }]
|
107
|
+
end
|
108
|
+
|
96
109
|
# Add the given holding_institutions, collections, and items
|
97
110
|
def add_sources(*sources)
|
98
111
|
raise "Cannot set sources of a #{self.class.name}. They are sourced through #{acts_as_sourceable_options[:through]}" if acts_as_sourceable_options[:through]
|
@@ -138,7 +151,7 @@ module ActsAsSourceable
|
|
138
151
|
# Removes registry entries that no longer belong to a sourceable, item, collection, or holding institution
|
139
152
|
def self.garbage_collect
|
140
153
|
# Remove all registry entries where the sourceable is gone
|
141
|
-
ActsAsSourceable::RegistryEntry.pluck(:sourceable_type).
|
154
|
+
ActsAsSourceable::RegistryEntry.uniq.pluck(:sourceable_type).each do |sourceable_type|
|
142
155
|
sourceable_table_name = sourceable_type.constantize.table_name
|
143
156
|
sourceable_id_sql = ActsAsSourceable::RegistryEntry
|
144
157
|
.select("#{ActsAsSourceable::RegistryEntry.table_name}.id")
|
@@ -150,7 +163,7 @@ module ActsAsSourceable
|
|
150
163
|
end
|
151
164
|
|
152
165
|
# Remove all registry entries where the source is gone
|
153
|
-
ActsAsSourceable::RegistryEntry.pluck(:source_type).
|
166
|
+
ActsAsSourceable::RegistryEntry.uniq.pluck(:source_type).each do |source_type|
|
154
167
|
source_class = source_type.constantize
|
155
168
|
source_table_name = source_class.table_name
|
156
169
|
source_id_sql = ActsAsSourceable::RegistryEntry
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_sourceable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.2.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nicholas Jakobsen
|
@@ -10,22 +9,20 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2013-
|
12
|
+
date: 2013-10-26 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rails
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- - ~>
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: '4.0'
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- - ~>
|
25
|
+
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '4.0'
|
31
28
|
description: Allows the RRN to perform garbage collection on categories that are no
|
@@ -35,32 +32,31 @@ executables: []
|
|
35
32
|
extensions: []
|
36
33
|
extra_rdoc_files: []
|
37
34
|
files:
|
35
|
+
- README.md
|
36
|
+
- lib/acts_as_sourceable.rb
|
38
37
|
- lib/acts_as_sourceable/acts_as_sourceable.rb
|
39
38
|
- lib/acts_as_sourceable/registry_entry.rb
|
40
|
-
- lib/acts_as_sourceable.rb
|
41
|
-
- README.md
|
42
39
|
homepage: http://github.com/rrn/acts_as_sourceable
|
43
40
|
licenses: []
|
41
|
+
metadata: {}
|
44
42
|
post_install_message:
|
45
43
|
rdoc_options: []
|
46
44
|
require_paths:
|
47
45
|
- lib
|
48
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
47
|
requirements:
|
51
|
-
- -
|
48
|
+
- - ">="
|
52
49
|
- !ruby/object:Gem::Version
|
53
50
|
version: '0'
|
54
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
52
|
requirements:
|
57
|
-
- -
|
53
|
+
- - ">="
|
58
54
|
- !ruby/object:Gem::Version
|
59
55
|
version: '0'
|
60
56
|
requirements: []
|
61
57
|
rubyforge_project:
|
62
|
-
rubygems_version:
|
58
|
+
rubygems_version: 2.2.2
|
63
59
|
signing_key:
|
64
|
-
specification_version:
|
60
|
+
specification_version: 4
|
65
61
|
summary: perform garbage collection on categories that are no longer referenced
|
66
62
|
test_files: []
|