ancestry 4.3.0 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19e9d786304fcb6d41f135572b0475167d378bafd24f1e084bab1aa87b759dc5
4
- data.tar.gz: 34d82c19057c6036e0e05080fa84569cf4343b8a2ebb19f718ea5093e398e4bf
3
+ metadata.gz: 1628363389f64272d25675e727b155ba36c221404a95fc7d7d41de12b2185614
4
+ data.tar.gz: 2a76d777929b18efa86bde34b969f11ab58c3f44424e82c97e69ef8f348d1c96
5
5
  SHA512:
6
- metadata.gz: e954ca39aabe660070650e2917f5efdd115a10da25c8d7874b565278d2ba6b69b2c17b3bc6138452fec2823675f6ff7c767b10d33c999ac568133736c08fbccf
7
- data.tar.gz: 4b3561088670192638cfd7016936d80cb547cf6b1f8f642af62800876fe49de22373ff6f2802442d5f5330668bca487b0b232491eb28d24090fcc6a531f6e45a
6
+ metadata.gz: 5ece87f9d1577748ffbaaf8617afdc4bf4094f653300b4a2df043a5f16822b267da877f0689b7d792f5f2174f1b4e1b41333e89c0e9dc23c388af30712267953
7
+ data.tar.gz: a12ce97c69b384100eecf3a347dcd3fea0abb60193c71b0e6a83d667c8f6a4cfdeba7e401e743bf95cf59f4d87ddc550d63b258ac294dd057ca7c518f1c8540f
data/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@
3
3
  Doing our best at supporting [SemVer](http://semver.org/) with
4
4
  a nice looking [Changelog](http://keepachangelog.com).
5
5
 
6
+ ## Version [4.3.1] <sub><sup>2023-03-19</sub></sup>
7
+ * Fix: added back fields that were removed in #589 [#637](https://github.com/stefankroes/ancestry/pull/637) (thx @znz)
8
+ - ancestor_ids_in_database
9
+ - parent_id_in_database
10
+
6
11
  ## Version [4.3.0] <sub><sup>2023-03-09</sub></sup>
7
12
 
8
13
  * Fix: materialized_path2 strategy [#597](https://github.com/stefankroes/ancestry/pull/597) (thx @kshnurov)
@@ -83,12 +83,7 @@ module Ancestry
83
83
  # Create counter cache column accessor and set to option or default
84
84
  if options[:counter_cache]
85
85
  cattr_accessor :counter_cache_column
86
-
87
- if options[:counter_cache] == true
88
- self.counter_cache_column = :children_count
89
- else
90
- self.counter_cache_column = options[:counter_cache]
91
- end
86
+ self.counter_cache_column = options[:counter_cache] == true ? 'children_count' : options[:counter_cache].to_s
92
87
 
93
88
  after_create :increase_parent_counter_cache, if: :has_parent?
94
89
  after_destroy :decrease_parent_counter_cache, if: :has_parent?
@@ -62,7 +62,7 @@ module Ancestry
62
62
 
63
63
  # Counter Cache
64
64
  def increase_parent_counter_cache
65
- self.ancestry_base_class.increment_counter _counter_cache_column, parent_id
65
+ self.ancestry_base_class.increment_counter counter_cache_column, parent_id
66
66
  end
67
67
 
68
68
  def decrease_parent_counter_cache
@@ -74,7 +74,7 @@ module Ancestry
74
74
  return if defined?(@_trigger_destroy_callback) && !@_trigger_destroy_callback
75
75
  return if ancestry_callbacks_disabled?
76
76
 
77
- self.ancestry_base_class.decrement_counter _counter_cache_column, parent_id
77
+ self.ancestry_base_class.decrement_counter counter_cache_column, parent_id
78
78
  end
79
79
 
80
80
  def update_parent_counter_cache
@@ -83,14 +83,10 @@ module Ancestry
83
83
  return unless changed
84
84
 
85
85
  if parent_id_was = parent_id_before_last_save
86
- self.ancestry_base_class.decrement_counter _counter_cache_column, parent_id_was
86
+ self.ancestry_base_class.decrement_counter counter_cache_column, parent_id_was
87
87
  end
88
88
 
89
- parent_id && self.ancestry_base_class.increment_counter(_counter_cache_column, parent_id)
90
- end
91
-
92
- def _counter_cache_column
93
- self.ancestry_base_class.counter_cache_column.to_s
89
+ parent_id && increase_parent_counter_cache
94
90
  end
95
91
 
96
92
  # Ancestors
@@ -124,10 +124,18 @@ module Ancestry
124
124
  parse_ancestry_column(read_attribute(self.ancestry_base_class.ancestry_column))
125
125
  end
126
126
 
127
+ def ancestor_ids_in_database
128
+ parse_ancestry_column(attribute_in_database(self.class.ancestry_column))
129
+ end
130
+
127
131
  def ancestor_ids_before_last_save
128
132
  parse_ancestry_column(attribute_before_last_save(self.ancestry_base_class.ancestry_column))
129
133
  end
130
134
 
135
+ def parent_id_in_database
136
+ parse_ancestry_column(attribute_in_database(self.class.ancestry_column)).last
137
+ end
138
+
131
139
  def parent_id_before_last_save
132
140
  parse_ancestry_column(attribute_before_last_save(self.ancestry_base_class.ancestry_column)).last
133
141
  end
@@ -1,3 +1,3 @@
1
1
  module Ancestry
2
- VERSION = '4.3.0'
2
+ VERSION = '4.3.1'
3
3
  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: 4.3.0
4
+ version: 4.3.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: 2023-03-09 00:00:00.000000000 Z
12
+ date: 2023-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -112,7 +112,6 @@ files:
112
112
  - MIT-LICENSE
113
113
  - README.md
114
114
  - lib/ancestry.rb
115
- - lib/ancestry/array_pattern_validator.rb
116
115
  - lib/ancestry/class_methods.rb
117
116
  - lib/ancestry/exceptions.rb
118
117
  - lib/ancestry/has_ancestry.rb
@@ -121,8 +120,6 @@ files:
121
120
  - lib/ancestry/materialized_path.rb
122
121
  - lib/ancestry/materialized_path2.rb
123
122
  - lib/ancestry/materialized_path_pg.rb
124
- - lib/ancestry/materialized_path_string.rb
125
- - lib/ancestry/materialized_path_string2.rb
126
123
  - lib/ancestry/version.rb
127
124
  homepage: https://github.com/stefankroes/ancestry
128
125
  licenses:
@@ -148,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
145
  - !ruby/object:Gem::Version
149
146
  version: '0'
150
147
  requirements: []
151
- rubygems_version: 3.1.6
148
+ rubygems_version: 3.2.32
152
149
  signing_key:
153
150
  specification_version: 4
154
151
  summary: Organize ActiveRecord model into a tree structure
@@ -1,27 +0,0 @@
1
- module Ancestry
2
- class ArrayPatternValidator < ActiveModel::EachValidator
3
- def initialize(options)
4
- raise ArgumentError, "Pattern unspecified, Specify using :pattern" unless options[:pattern]
5
-
6
- options[:pattern] = /\A#{options[:pattern].to_s}\Z/ unless options[:pattern].to_s.include?('\A')
7
- options[:id] = true unless options.key?(:id)
8
- options[:integer] = true unless options.key?(:integer)
9
-
10
- super
11
- end
12
-
13
- def validate_each(record, attribute, value)
14
- if options[:id] && value.include?(record.id)
15
- record.errors.add(attribute, I18n.t("ancestry.exclude_self", {:class_name => self.class.name.humanize}))
16
- end
17
-
18
- if value.any? { |v| v.to_s !~ options[:pattern] }
19
- record.errors.add(attribute, "illegal characters")
20
- end
21
-
22
- if options[:integer] && value.any? { |v| v < 1 }
23
- record.errors.add(attribute, "non positive ancestor id")
24
- end
25
- end
26
- end
27
- end
@@ -1,46 +0,0 @@
1
- module Ancestry
2
- class MaterializedPathString < ActiveRecord::Type::Value
3
- def initialize(casting: :to_i, delimiter: '/')
4
- @casting = casting&.to_proc
5
- @delimiter = delimiter
6
- end
7
-
8
- def type
9
- :materialized_path_string
10
- end
11
-
12
- # convert to database type
13
- def serialize(value)
14
- if value.kind_of?(Array)
15
- value.map(&:to_s).join(@delimiter).presence
16
- elsif value.kind_of?(Integer)
17
- value.to_s
18
- elsif value.nil? || value.kind_of?(String)
19
- value
20
- else
21
- byebug
22
- puts "curious type: #{value.class}"
23
- end
24
- end
25
-
26
- def cast(value)
27
- cast_value(value) #unless value.nil? (want to get rid of this - fix default value)
28
- end
29
-
30
- # called by cast (form or setter) or deserialize (database)
31
- def cast_value(value)
32
- if value.kind_of?(Array)
33
- super
34
- elsif value.nil?
35
- # would prefer to use default here
36
- # but with default, it kept thinking the field had changed when it hadn't
37
- # (that may be a rails bug though)
38
- super([])
39
- else
40
- #TODO: test ancestry=1
41
- super(value.to_s.split(@delimiter).map(&@casting))
42
- end
43
- end
44
- end
45
- end
46
- ActiveRecord::Type.register(:materialized_path_string, Ancestry::MaterializedPathString)
@@ -1,46 +0,0 @@
1
- # used for materialized path
2
- class MaterializedPathString2 < ActiveRecord::Type::Value
3
- def initialize(casting: :to_i, delimiter: '/')
4
- @casting = casting&.to_proc
5
- @delimiter = delimiter
6
- end
7
-
8
- def type
9
- :materialized_path_string2
10
- end
11
-
12
- # convert to database type
13
- def serialize(value)
14
- if value.kind_of?(Array)
15
- # TODO: check all values to ensure no extra slashes
16
- value.empty? ? @delimiter : "#{@delimiter}#{value.map(&:to_s).join(@delimiter)}#{@delimiter}"
17
- elsif value.kind_of?(Integer)
18
- value.to_s
19
- elsif value.nil? || value.kind_of?(String)
20
- value
21
- else
22
- byebug
23
- puts "curious type: #{value.class}"
24
- end
25
- end
26
-
27
- def cast(value)
28
- cast_value(value) #unless value.nil? (want to get rid of this - fix default value)
29
- end
30
-
31
- # called by cast (form or setter) or deserialize (database)
32
- def cast_value(value)
33
- if value.kind_of?(Array)
34
- super
35
- elsif value.nil?
36
- # would prefer to use default here
37
- # but with default, it kept thinking the field had changed when it hadn't
38
- super([])
39
- else
40
- #TODO: test ancestry=1
41
- super(value.to_s.split(@delimiter).map(&@casting))
42
- end
43
- end
44
- end
45
- end
46
- ActiveRecord::Type.register(:materialized_path_string2, Ancestry::MaterializedPathString)