closure_tree 4.2.3 → 4.2.4
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 +8 -8
- data/README.md +1 -257
- data/lib/closure_tree/model.rb +8 -4
- data/lib/closure_tree/version.rb +1 -1
- data/spec/label_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmE3ZGYxNDE5MjE5Y2FkMjMxNjY5YjVmMTZkYmM4MTY5ZGQ0NTUxZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGMyNmRiZGY1N2RiNGZiYTk1NzgzYzg4N2U2MDIxZWFlNjNmNjMxZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzE2ZTUxMDY0YzAxMDY1ZTFjMzlkM2ZjZDcwNDJhMjg3YWRiODU2NWYxMjgz
|
10
|
+
YjJkNzIxNzA2MjQwYTliMjEyNTVmYjZkMDExNGZlMzM3MjVjYjY0NGZjZDNi
|
11
|
+
ODA4MzQ4OTFkYmE1YWYzODQ4ZDY2YmRhMjIyZWJhZDQ4NjU1MDA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZThkMTI0YTU0OTJlNjEzMjdlMjU2Mjc5M2I5NGI2M2UxODQwMjc0NDUzMTEw
|
14
|
+
NWZmNDM1Yjk3YmI4M2I5OGIzYWQ2Zjg0YzE0NWIxYjMyNTY3ZjBjOTdmZDBh
|
15
|
+
OTYyMGEzZjFjYTAyZjBlZWY3NDMyNDNhMDllODY2ZjNhZWVkYjk=
|
data/README.md
CHANGED
@@ -490,263 +490,7 @@ Parallelism is not tested with Rails 3.0.x nor 3.1.x due to this
|
|
490
490
|
|
491
491
|
## Change log
|
492
492
|
|
493
|
-
|
494
|
-
|
495
|
-
* Fixed ```attr_accessible?``` error introduced in 4.2.2 ([issue 66](https://github.com/mceachen/closure_tree/issues/66)).
|
496
|
-
* Switched to use new WithAdvisoryLock::DatabaseAdapterSupport (in v0.0.9) to add Postgis support
|
497
|
-
|
498
|
-
### 4.2.2
|
499
|
-
|
500
|
-
* Support attr_accessible and strong_attributes even if you're on Rails 4
|
501
|
-
|
502
|
-
### 4.2.1
|
503
|
-
|
504
|
-
* Deleting from NumericDeterministicOrdering doesn't create sort order gaps anymore.
|
505
|
-
|
506
|
-
### 4.2.0
|
507
|
-
|
508
|
-
* Added ```with_ancestor(*ancestors)```. Thanks for the idea, [Matt](https://github.com/mgornick)!
|
509
|
-
* Applied [Leonel Galan](https://github.com/leonelgalan)'s fix for Strong Attribute support
|
510
|
-
* ```find_or_create_by``` now uses passed-in attributes as both selection and creation criteria.
|
511
|
-
Thanks for the help, [Judd Blair](https://github.com/juddblair)!
|
512
|
-
**Please note that this changes prior behavior—test your code with this new version!**
|
513
|
-
* ```ct_advisory_lock``` was moved into the ```_ct``` support class, to reduce model method pollution
|
514
|
-
* Moved a bunch of code into more focused piles of module mixins
|
515
|
-
|
516
|
-
### 4.1.0
|
517
|
-
|
518
|
-
* Added support for Rails 4.0.0.rc1 and Ruby 2.0.0 (while maintaining backward compatibility with Rails 3, BOOYA)
|
519
|
-
* Added ```#to_dot_digraph```, suitable for Graphviz rendering
|
520
|
-
|
521
|
-
### 4.0.1
|
522
|
-
|
523
|
-
* Numeric, deterministically ordered siblings will always be [0..#{self_and_siblings.count}]
|
524
|
-
(previously, the sort order might use negative values, which broke the preordering).
|
525
|
-
Resolves [issue 49](https://github.com/mceachen/closure_tree/issues/49). Thanks for the help,
|
526
|
-
[Leonel Galan](https://github.com/leonelgalan), [Juan Hoyos](https://github.com/elhoyos), and
|
527
|
-
[Michael Elfassy](https://github.com/elfassy)!
|
528
|
-
|
529
|
-
* The ```order``` option can be a symbol now. Resolves [issue 46](https://github.com/mceachen/closure_tree/issues/46).
|
530
|
-
|
531
|
-
### 4.0.0
|
532
|
-
|
533
|
-
* Moved all of closure_tree's implementation-detail methods into a ```ClosureTree::Support```
|
534
|
-
instance, which removes almost all of the namespace pollution in your models that wasn't
|
535
|
-
for normal consumption. If you were using any of these methods, they're now available through
|
536
|
-
the "_ct" class and instance member.
|
537
|
-
|
538
|
-
*This change may break consumers*, so I incremented the major version number, even though no new
|
539
|
-
functionality was released.
|
540
|
-
|
541
|
-
### 3.10.2
|
542
|
-
|
543
|
-
* Prevent faulty SQL statement when ```#siblings``` is called on an unsaved records.
|
544
|
-
Resolves [issue 52](https://github.com/mceachen/closure_tree/pull/52). Perfect pull
|
545
|
-
request by [Gary Greyling](https://github.com/garygreyling).
|
546
|
-
|
547
|
-
* The ```.roots``` class method now correctly respects the ```:order``` option.
|
548
|
-
Resolves [issue 53](https://github.com/mceachen/closure_tree/issues/53).
|
549
|
-
Thanks for finding this, [Brendon Muir](https://github.com/brendon)!
|
550
|
-
|
551
|
-
### 3.10.1
|
552
|
-
|
553
|
-
* Multipart constant names like "Admin::PageHierarchy" are now supported.
|
554
|
-
Resolves [issue 47](https://github.com/mceachen/closure_tree/issues/47).
|
555
|
-
Thanks for the perfect pull request, [Simon Menke](https://github.com/fd)!
|
556
|
-
|
557
|
-
* Committing transactions involving large numbers of hierarchy model classes was very slow due
|
558
|
-
to hash collisions in the hierarchy class. A better hash implementation addressed
|
559
|
-
[issue 48](https://github.com/mceachen/closure_tree/issues/48).
|
560
|
-
Thanks, [Joel Turkel](https://github.com/jturkel)!
|
561
|
-
|
562
|
-
### 3.10.0
|
563
|
-
|
564
|
-
* Added ```#roots_and_descendants_preordered```.
|
565
|
-
Thanks for the suggestion, [Leonel Galan](https://github.com/leonelgalan)!
|
566
|
-
|
567
|
-
### 3.9.0
|
568
|
-
|
569
|
-
* Added ```.child_ids```.
|
570
|
-
* Removed ```dependent => destroy``` on the descendant_hierarchy and ancestor_hierarchy collections
|
571
|
-
(they were a mistake).
|
572
|
-
* Clarified documentation for creation and child associations.
|
573
|
-
Because ```Tag.create!(:parent => ...)``` requires a ```.reload```, I removed it as an example.
|
574
|
-
|
575
|
-
All three of these improvements were suggested by Andrew Bromwich. Thanks!
|
576
|
-
|
577
|
-
### 3.8.2
|
578
|
-
|
579
|
-
* find_by_path uses 1 SELECT now. BOOM.
|
580
|
-
|
581
|
-
### 3.8.1
|
582
|
-
|
583
|
-
* Double-check locking for find_or_create_by_path
|
584
|
-
|
585
|
-
### 3.8.0
|
586
|
-
|
587
|
-
* Support for preordered descendants. This requires a numeric sort order column.
|
588
|
-
Resolves [feature request 38](https://github.com/mceachen/closure_tree/issues/38).
|
589
|
-
* Moved modules from ```acts_as_tree``` into separate files
|
590
|
-
|
591
|
-
### 3.7.3
|
592
|
-
|
593
|
-
Due to MySQL's inability to lock rows properly, I've switched to advisory_locks for
|
594
|
-
all write paths. This will prevent deadlocks, addressing
|
595
|
-
[issue 41](https://github.com/mceachen/closure_tree/issues/41).
|
596
|
-
|
597
|
-
### 3.7.2
|
598
|
-
|
599
|
-
* Support for UUID primary keys. Addresses
|
600
|
-
[issue 40](https://github.com/mceachen/closure_tree/issues/40). Thanks for the pull request,
|
601
|
-
[Julien](https://github.com/calexicoz)!
|
602
|
-
|
603
|
-
### 3.7.1
|
604
|
-
|
605
|
-
* Moved requires into ActiveSupport.on_load
|
606
|
-
* Added ```require 'with_advisory_lock'```
|
607
|
-
|
608
|
-
### 3.7.0
|
609
|
-
|
610
|
-
**Thread safety!**
|
611
|
-
* [Advisory locks](https://github.com/mceachen/with_advisory_lock) were
|
612
|
-
integrated with the class-level ```find_or_create_by_path``` and ```rebuild!```.
|
613
|
-
* Pessimistic locking is used by the instance-level ```find_or_create_by_path```.
|
614
|
-
|
615
|
-
### 3.6.9
|
616
|
-
|
617
|
-
* [Don Morrison](https://github.com/elskwid) massaged the [#hash_tree](#nested-hashes) query to
|
618
|
-
be more efficient, and found a bug in ```hash_tree```'s query that resulted in duplicate rows,
|
619
|
-
wasting time on the ruby side.
|
620
|
-
|
621
|
-
### 3.6.7
|
622
|
-
|
623
|
-
* Added workaround for ActiveRecord::Observer usage pre-db-creation. Addresses
|
624
|
-
[issue 32](https://github.com/mceachen/closure_tree/issues/32).
|
625
|
-
Thanks, [Don Morrison](https://github.com/elskwid)!
|
626
|
-
|
627
|
-
### 3.6.6
|
628
|
-
|
629
|
-
* Added support for Rails 4's [strong parameter](https://github.com/rails/strong_parameters).
|
630
|
-
Thanks, [James Miller](https://github.com/bensie)!
|
631
|
-
|
632
|
-
### 3.6.5
|
633
|
-
|
634
|
-
* Use ```quote_table_name``` instead of ```quote_column_name```. Addresses
|
635
|
-
[issue 29](https://github.com/mceachen/closure_tree/issues/29). Thanks,
|
636
|
-
[Marcello Barnaba](https://github.com/vjt)!
|
637
|
-
|
638
|
-
### 3.6.4
|
639
|
-
|
640
|
-
* Use ```.pluck``` when available for ```.ids_from```. Addresses
|
641
|
-
[issue 26](https://github.com/mceachen/closure_tree/issues/26). Thanks,
|
642
|
-
[Chris Sturgill](https://github.com/sturgill)!
|
643
|
-
|
644
|
-
### 3.6.3
|
645
|
-
|
646
|
-
* Fixed [issue 24](https://github.com/mceachen/closure_tree/issues/24), which optimized ```#hash_tree```
|
647
|
-
for roots. Thanks, [Saverio Trioni](https://github.com/rewritten)!
|
648
|
-
|
649
|
-
### 3.6.2
|
650
|
-
|
651
|
-
* Fixed [issue 23](https://github.com/mceachen/closure_tree/issues/23), which added support for ```#siblings```
|
652
|
-
when sort_order wasn't specified. Thanks, [Gary Greyling](https://github.com/garygreyling)!
|
653
|
-
|
654
|
-
### 3.6.1
|
655
|
-
|
656
|
-
* Fixed [issue 20](https://github.com/mceachen/closure_tree/issues/20), which affected
|
657
|
-
deterministic ordering when siblings where different STI classes. Thanks, [edwinramirez](https://github.com/edwinramirez)!
|
658
|
-
|
659
|
-
### 3.6.0
|
660
|
-
|
661
|
-
Added support for:
|
662
|
-
* ```:hierarchy_class_name``` as an option
|
663
|
-
* ActiveRecord::Base.table_name_prefix
|
664
|
-
* ActiveRecord::Base.table_name_suffix
|
665
|
-
|
666
|
-
This addresses [issue 21](https://github.com/mceachen/closure_tree/issues/21). Thanks, [Judd Blair](https://github.com/juddblair)!
|
667
|
-
|
668
|
-
### 3.5.2
|
669
|
-
|
670
|
-
* Added ```find_all_by_generation```
|
671
|
-
for [feature request 17](https://github.com/mceachen/closure_tree/issues/17).
|
672
|
-
|
673
|
-
### 3.4.2
|
674
|
-
|
675
|
-
* Fixed [issue 18](https://github.com/mceachen/closure_tree/issues/18), which affected
|
676
|
-
append_node/prepend_node ordering when the first node didn't have an explicit order_by value
|
677
|
-
|
678
|
-
### 3.4.1
|
679
|
-
|
680
|
-
* Reverted .gemspec mistake that changed add_development_dependency to add_runtime_dependency
|
681
|
-
|
682
|
-
### 3.4.0
|
683
|
-
|
684
|
-
Fixed [issue 15](https://github.com/mceachen/closure_tree/issues/15):
|
685
|
-
* "parent" is now attr_accessible, which adds support for constructor-provided parents.
|
686
|
-
* updated readme accordingly
|
687
|
-
|
688
|
-
### 3.3.2
|
689
|
-
|
690
|
-
* Merged calebphillips' patch for a more efficient leaves query
|
691
|
-
|
692
|
-
### 3.3.1
|
693
|
-
|
694
|
-
* Added support for partially-unsaved hierarchies [issue 13](https://github.com/mceachen/closure_tree/issues/13):
|
695
|
-
```
|
696
|
-
a = Tag.new(name: "a")
|
697
|
-
b = Tag.new(name: "b")
|
698
|
-
a.children << b
|
699
|
-
a.save
|
700
|
-
```
|
701
|
-
|
702
|
-
### 3.3.0
|
703
|
-
|
704
|
-
* Added [```hash_tree```](#nested-hashes).
|
705
|
-
|
706
|
-
### 3.2.1
|
707
|
-
|
708
|
-
* Added ```ancestor_ids```, ```descendant_ids```, and ```sibling_ids```
|
709
|
-
* Added example spec to solve [issue 9](https://github.com/mceachen/closure_tree/issues/9)
|
710
|
-
|
711
|
-
### 3.2.0
|
712
|
-
|
713
|
-
* Added support for deterministic ordering of nodes.
|
714
|
-
|
715
|
-
### 3.1.0
|
716
|
-
|
717
|
-
* Switched to using ```has_many :though``` rather than ```has_and_belongs_to_many```
|
718
|
-
|
719
|
-
### 3.0.4
|
720
|
-
|
721
|
-
* Merged [pull request](https://github.com/mceachen/closure_tree/pull/8) to fix ```.siblings``` and ```.self_and_siblings```
|
722
|
-
(Thanks, [eljojo](https://github.com/eljojo)!)
|
723
|
-
|
724
|
-
### 3.0.3
|
725
|
-
|
726
|
-
* Added support for ActiveRecord's whitelist_attributes
|
727
|
-
(Make sure you read [the Rails Security Guide](http://guides.rubyonrails.org/security.html), and
|
728
|
-
enable ```config.active_record.whitelist_attributes``` in your ```config/application.rb``` ASAP!)
|
729
|
-
|
730
|
-
### 3.0.2
|
731
|
-
|
732
|
-
* Fix for ancestry-loop detection (performed by a validation, not through raising an exception in before_save)
|
733
|
-
|
734
|
-
### 3.0.1
|
735
|
-
|
736
|
-
* Support 3.2.0's fickle deprecation of InstanceMethods (Thanks, [jheiss](https://github.com/mceachen/closure_tree/pull/5))!
|
737
|
-
|
738
|
-
### 3.0.0
|
739
|
-
|
740
|
-
* Support for polymorphic trees
|
741
|
-
* ```find_by_path``` and ```find_or_create_by_path``` signatures changed to support constructor attributes
|
742
|
-
* tested against Rails 3.1.3
|
743
|
-
|
744
|
-
### 2.0.0
|
745
|
-
|
746
|
-
* Had to increment the major version, as rebuild! will need to be called by prior consumers to support the new ```leaves``` class and instance methods.
|
747
|
-
* Tag deletion is supported now along with ```:dependent => :destroy``` and ```:dependent => :delete_all```
|
748
|
-
* Switched from default rails plugin directory structure to rspec
|
749
|
-
* Support for running specs under different database engines: ```export DB ; for DB in sqlite3 mysql postgresql ; do rake ; done```
|
493
|
+
See https://github.com/mceachen/closure_tree/blob/master/CHANGELOG.md
|
750
494
|
|
751
495
|
## Thanks to
|
752
496
|
|
data/lib/closure_tree/model.rb
CHANGED
@@ -7,7 +7,8 @@ module ClosureTree
|
|
7
7
|
included do
|
8
8
|
belongs_to :parent,
|
9
9
|
:class_name => _ct.model_class.to_s,
|
10
|
-
:foreign_key => _ct.parent_column_name
|
10
|
+
:foreign_key => _ct.parent_column_name,
|
11
|
+
:inverse_of => :children
|
11
12
|
|
12
13
|
attr_accessible :parent if _ct.use_attr_accessible?
|
13
14
|
|
@@ -16,7 +17,8 @@ module ClosureTree
|
|
16
17
|
has_many :children, *_ct.has_many_with_order_option(
|
17
18
|
:class_name => _ct.model_class.to_s,
|
18
19
|
:foreign_key => _ct.parent_column_name,
|
19
|
-
:dependent => _ct.options[:dependent]
|
20
|
+
:dependent => _ct.options[:dependent],
|
21
|
+
:inverse_of => :parent)
|
20
22
|
|
21
23
|
has_many :ancestor_hierarchies, *_ct.has_many_without_order_option(
|
22
24
|
:class_name => _ct.hierarchy_class_name,
|
@@ -46,12 +48,14 @@ module ClosureTree
|
|
46
48
|
|
47
49
|
# Returns true if this node has no parents.
|
48
50
|
def root?
|
49
|
-
|
51
|
+
# Accessing the parent will fetch that row from the database,
|
52
|
+
# so if we are persisted, just check that the parent_id column is nil.
|
53
|
+
persisted? ? _ct_parent_id.nil? : parent.nil?
|
50
54
|
end
|
51
55
|
|
52
56
|
# Returns true if this node has a parent, and is not a root.
|
53
57
|
def child?
|
54
|
-
!
|
58
|
+
!root?
|
55
59
|
end
|
56
60
|
|
57
61
|
# Returns true if this node has no children.
|
data/lib/closure_tree/version.rb
CHANGED
data/spec/label_spec.rb
CHANGED
@@ -84,6 +84,17 @@ describe Label do
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
context "Parent/child inverse relationships" do
|
88
|
+
it "should associate both sides of the parent and child relationships" do
|
89
|
+
parent = Label.new(:name => 'parent')
|
90
|
+
child = parent.children.build(:name => 'child')
|
91
|
+
parent.should be_root
|
92
|
+
parent.should_not be_leaf
|
93
|
+
child.should_not be_root
|
94
|
+
child.should be_leaf
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
87
98
|
context "DateLabel" do
|
88
99
|
it "should find or create by path" do
|
89
100
|
date = DateLabel.find_or_create_by_path(%w{2011 November 23})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: closure_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew McEachen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|