Module: CollectiveIdea::Acts::NestedSet::Model::Validatable
- Defined in:
- lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb
Instance Method Summary (collapse)
-
- (Boolean) all_roots_valid?
Wrapper for each_root_valid? that can deal with scope.
- - (Boolean) all_roots_valid_by_scope?(roots_to_validate)
- - (Boolean) each_root_valid?(roots_to_validate)
- - (Boolean) left_and_rights_valid?
- - (Boolean) no_duplicates_for_columns?
- - (Boolean) valid?
Instance Method Details
- (Boolean) all_roots_valid?
Wrapper for each_root_valid? that can deal with scope.
28 29 30 31 32 33 34 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb', line 28 def all_roots_valid? if [:scope] all_roots_valid_by_scope?(roots) else each_root_valid?(roots) end end |
- (Boolean) all_roots_valid_by_scope?(roots_to_validate)
36 37 38 39 40 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb', line 36 def all_roots_valid_by_scope?(roots_to_validate) roots_grouped_by_scope(roots_to_validate).all? do |scope, grouped_roots| each_root_valid?(grouped_roots) end end |
- (Boolean) each_root_valid?(roots_to_validate)
42 43 44 45 46 47 48 49 50 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb', line 42 def each_root_valid?(roots_to_validate) left = right = 0 roots_to_validate.all? do |root| (root.left > left && root.right > right).tap do left = root.left right = root.right end end end |
- (Boolean) left_and_rights_valid?
13 14 15 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb', line 13 def left_and_rights_valid? SetValidator.new(self).valid? end |
- (Boolean) no_duplicates_for_columns?
17 18 19 20 21 22 23 24 25 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb', line 17 def no_duplicates_for_columns? [quoted_left_column_full_name, quoted_right_column_full_name].all? do |column| # No duplicates select("#{scope_string}#{column}, COUNT(#{column}) as _count"). group("#{scope_string}#{column}"). having("COUNT(#{column}) > 1"). first.nil? end end |
- (Boolean) valid?
9 10 11 |
# File 'lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb', line 9 def valid? left_and_rights_valid? && no_duplicates_for_columns? && all_roots_valid? end |