categoryz3 0.5 → 0.6
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.
@@ -5,6 +5,7 @@ module Categoryz3
|
|
5
5
|
has_many :direct_items , class_name: 'Categoryz3::Item' , inverse_of: :category , dependent: :destroy
|
6
6
|
has_many :child_items , class_name: 'Categoryz3::ChildItem' , inverse_of: :category , dependent: :destroy
|
7
7
|
validates :name , presence: true
|
8
|
+
validates_with Categoryz3::Validators::ParentCategoryValidator
|
8
9
|
|
9
10
|
scope :root_categories, -> { where(parent_id: nil) }
|
10
11
|
scope :parent_categories, -> { root_categories }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Categoryz3
|
2
|
+
module Validators
|
3
|
+
class ParentCategoryValidator < ActiveModel::Validator
|
4
|
+
def validate(record)
|
5
|
+
if record.parent_id && record.parent.path.map{ |category| category.id }.include?(record.id)
|
6
|
+
record.errors[:parent] << "Parent cycle dependency"
|
7
|
+
end
|
8
|
+
if record.id && record.parent_id == record.id
|
9
|
+
record.errors[:parent] << "Can't be parent of itself!"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/categoryz3/version.rb
CHANGED
data/lib/categoryz3.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: categoryz3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/categoryz3/categorizable.rb
|
110
110
|
- lib/categoryz3/engine.rb
|
111
111
|
- lib/categoryz3/validators/child_item_category_validator.rb
|
112
|
+
- lib/categoryz3/validators/parent_category_validator.rb
|
112
113
|
- lib/categoryz3/version.rb
|
113
114
|
- lib/categoryz3.rb
|
114
115
|
- lib/generators/categoryz3/migrations/migrations_generator.rb
|
@@ -131,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
132
|
version: '0'
|
132
133
|
segments:
|
133
134
|
- 0
|
134
|
-
hash:
|
135
|
+
hash: 4499004963160732104
|
135
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
137
|
none: false
|
137
138
|
requirements:
|
@@ -140,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
141
|
version: '0'
|
141
142
|
segments:
|
142
143
|
- 0
|
143
|
-
hash:
|
144
|
+
hash: 4499004963160732104
|
144
145
|
requirements: []
|
145
146
|
rubyforge_project:
|
146
147
|
rubygems_version: 1.8.24
|