ancestry 3.0.0 → 3.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10ddb8d5c0746b6c319e51a71a665257612bd6a1
4
- data.tar.gz: 5da3981850ca1133b3c4318ba1934b492011c235
3
+ metadata.gz: 4a0ecc6b1fa22b8bd28b9c30ea33044711e58502
4
+ data.tar.gz: 61a4f311e5b2b459d31f3579f3768b3e662e9cd5
5
5
  SHA512:
6
- metadata.gz: 44241ad80d6e7e8392c53a25f2396c101f9bf99dc22c1fd10b49b672af1e38f199a74afc8a5f638ccdb469ee821ae953b95160ed64caaabeb52dbc735addff81
7
- data.tar.gz: e49f276175f2265d9af857eb64c72431d34b78ab49e977d2e0b4985095991b86f8da434926787ceaeccbd2a55719cfc4b2c308770ece7fb9cba47e32f11a66e6
6
+ metadata.gz: 61f60265258f9c8c2a9637c21239c1b32f3117b98a4f7bcdf7752d11e306f29e5c7ecd6bc4b364c1b39bb8ed44a8e7fa94b3b276bc9fb6bfa9c1152f2a1ba4f2
7
+ data.tar.gz: 75d97ae0017b5906e44e141f97915de6055a33c0f3862db4f5e7b058cbd8482f4e1b90803658873b1cdbc4cf0aab1c7d8d81ff2111aa56e361a5de5a9d8700fd
data/README.md CHANGED
@@ -109,6 +109,7 @@ record:
109
109
  path Scopes model on path records of the record
110
110
  children Scopes the model on children of the record
111
111
  child_ids Returns a list of child ids
112
+ has_parent? Returns true if the record has a parent, false otherwise
112
113
  has_children? Returns true if the record has any children, false otherwise
113
114
  is_childless? Returns true is the record has no children, false otherwise
114
115
  siblings Scopes the model on siblings of the record, the record itself is included*
@@ -14,7 +14,12 @@ Gem::Specification.new do |s|
14
14
  arrangement of (sub)tree into hashes and different strategies for dealing with
15
15
  orphaned records.
16
16
  EOF
17
-
17
+ s.metadata = {
18
+ "homepage_uri" => "https://github.com/stefankroes/ancestry",
19
+ "changelog_uri" => "https://github.com/stefankroes/ancestry/blob/master/CHANGELOG.md",
20
+ "source_code_uri" => "https://github.com/stefankroes/ancestry/",
21
+ "bug_tracker_uri" => "https://github.com/stefankroes/ancestry/issues",
22
+ }
18
23
  s.version = Ancestry::VERSION
19
24
 
20
25
  s.authors = ['Stefan Kroes', 'Keenan Brock']
@@ -99,9 +99,9 @@ module Ancestry
99
99
  parents = {}
100
100
  exceptions = [] if options[:report] == :list
101
101
 
102
- self.ancestry_base_class.unscoped do
102
+ unscoped_where do |scope|
103
103
  # For each node ...
104
- self.ancestry_base_class.find_each do |node|
104
+ scope.find_each do |node|
105
105
  begin
106
106
  # ... check validity of ancestry column
107
107
  if !node.valid? and !node.errors[node.class.ancestry_column].blank?
@@ -137,9 +137,9 @@ module Ancestry
137
137
  parents = {}
138
138
  # Wrap the whole thing in a transaction ...
139
139
  self.ancestry_base_class.transaction do
140
- self.ancestry_base_class.unscoped do
140
+ unscoped_where do |scope|
141
141
  # For each node ...
142
- self.ancestry_base_class.find_each do |node|
142
+ scope.find_each do |node|
143
143
  # ... set its ancestry to nil if invalid
144
144
  if !node.valid? and !node.errors[node.class.ancestry_column].blank?
145
145
  node.without_ancestry_callbacks do
@@ -158,7 +158,7 @@ module Ancestry
158
158
  end
159
159
 
160
160
  # For each node ...
161
- self.ancestry_base_class.find_each do |node|
161
+ scope.find_each do |node|
162
162
  # ... rebuild ancestry from parents array
163
163
  ancestry, parent = nil, parents[node.id]
164
164
  until parent.nil?
@@ -174,8 +174,8 @@ module Ancestry
174
174
 
175
175
  # Build ancestry from parent id's for migration purposes
176
176
  def build_ancestry_from_parent_ids! parent_id = nil, ancestry = nil
177
- self.ancestry_base_class.unscoped do
178
- self.ancestry_base_class.where(:parent_id => parent_id).find_each do |node|
177
+ unscoped_where do |scope|
178
+ scope.where(:parent_id => parent_id).find_each do |node|
179
179
  node.without_ancestry_callbacks do
180
180
  node.update_attribute ancestry_column, ancestry
181
181
  end
@@ -189,12 +189,22 @@ module Ancestry
189
189
  raise Ancestry::AncestryException.new("Cannot rebuild depth cache for model without depth caching.") unless respond_to? :depth_cache_column
190
190
 
191
191
  self.ancestry_base_class.transaction do
192
- self.ancestry_base_class.unscoped do
193
- self.ancestry_base_class.find_each do |node|
192
+ unscoped_where do |scope|
193
+ scope.find_each do |node|
194
194
  node.update_attribute depth_cache_column, node.depth
195
195
  end
196
196
  end
197
197
  end
198
198
  end
199
+
200
+ def unscoped_where
201
+ if ActiveRecord::VERSION::MAJOR < 4
202
+ self.ancestry_base_class.unscoped do
203
+ yield self.ancestry_base_class
204
+ end
205
+ else
206
+ yield self.ancestry_base_class.unscope(:where)
207
+ end
208
+ end
199
209
  end
200
210
  end
@@ -40,7 +40,6 @@ module Ancestry
40
40
  # Named scopes
41
41
  scope :roots, lambda { where(root_conditions) }
42
42
  scope :ancestors_of, lambda { |object| where(ancestor_conditions(object)) }
43
- scope :path_of, lambda { |object| where(path_conditions(object)) }
44
43
  scope :children_of, lambda { |object| where(child_conditions(object)) }
45
44
  scope :descendants_of, lambda { |object| where(descendant_conditions(object)) }
46
45
  scope :subtree_of, lambda { |object| where(subtree_conditions(object)) }
@@ -87,6 +87,7 @@ module Ancestry
87
87
  # ancestor_ids.present?
88
88
  read_attribute(self.ancestry_base_class.ancestry_column).present?
89
89
  end
90
+ alias :has_parent? :ancestors?
90
91
 
91
92
  def ancestry_changed?
92
93
  changed.include?(self.ancestry_base_class.ancestry_column.to_s)
@@ -306,19 +307,27 @@ module Ancestry
306
307
  end
307
308
 
308
309
  def unscoped_descendants
309
- self.ancestry_base_class.unscoped do
310
- self.ancestry_base_class.where descendant_conditions
310
+ unscoped_where do |scope|
311
+ scope.where descendant_conditions
311
312
  end
312
313
  end
313
314
 
314
315
  def unscoped_current_and_previous_ancestors
315
- self.ancestry_base_class.unscoped do
316
- self.ancestry_base_class.where id: (ancestor_ids + ancestor_ids_was).uniq
316
+ unscoped_where do |scope|
317
+ scope.where id: (ancestor_ids + ancestor_ids_was).uniq
317
318
  end
318
319
  end
319
320
 
320
321
  def unscoped_find id
321
- self.ancestry_base_class.unscoped { self.ancestry_base_class.find(id) }
322
+ unscoped_where do |scope|
323
+ scope.find id
324
+ end
325
+ end
326
+
327
+ def unscoped_where
328
+ self.ancestry_base_class.unscoped_where do |scope|
329
+ yield scope
330
+ end
322
331
  end
323
332
  end
324
333
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ancestry
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kroes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-20 00:00:00.000000000 Z
12
+ date: 2017-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -122,7 +122,11 @@ files:
122
122
  homepage: http://github.com/stefankroes/ancestry
123
123
  licenses:
124
124
  - MIT
125
- metadata: {}
125
+ metadata:
126
+ homepage_uri: https://github.com/stefankroes/ancestry
127
+ changelog_uri: https://github.com/stefankroes/ancestry/blob/master/CHANGELOG.md
128
+ source_code_uri: https://github.com/stefankroes/ancestry/
129
+ bug_tracker_uri: https://github.com/stefankroes/ancestry/issues
126
130
  post_install_message:
127
131
  rdoc_options: []
128
132
  require_paths: