class CollectiveIdea::Acts::NestedSet::SetValidator
Attributes
model[R]
parent[R]
scope[RW]
Public Class Methods
new(model)
click to toggle source
# File lib/awesome_nested_set/set_validator.rb, line 6 def initialize(model) @model = model @scope = model.all @parent = arel_table.alias('parent') end
Public Instance Methods
valid?()
click to toggle source
# File lib/awesome_nested_set/set_validator.rb, line 12 def valid? query.count == 0 end
Private Instance Methods
bound_is_null(column_name)
click to toggle source
# File lib/awesome_nested_set/set_validator.rb, line 44 def bound_is_null(column_name) arel_table[column_name].eq(nil) end
bounds_outside_parent()
click to toggle source
# File lib/awesome_nested_set/set_validator.rb, line 56 def bounds_outside_parent arel_table[left_column_name].lteq(parent[left_column_name]).or(arel_table[right_column_name].gteq(parent[right_column_name])) end
filter_scope()
click to toggle source
# File lib/awesome_nested_set/set_validator.rb, line 35 def filter_scope self.scope = scope.where( bound_is_null(left_column_name). or(bound_is_null(right_column_name)). or(left_bound_greater_than_right). or(parent_not_null.and(bounds_outside_parent)) ) end
join_scope()
click to toggle source
# File lib/awesome_nested_set/set_validator.rb, line 30 def join_scope join_arel = arel_table.join(parent, Arel::Nodes::OuterJoin).on(parent[primary_column_name].eq(arel_table[parent_column_name])) self.scope = scope.joins(join_arel.join_sources) end
left_bound_greater_than_right()
click to toggle source
# File lib/awesome_nested_set/set_validator.rb, line 48 def left_bound_greater_than_right arel_table[left_column_name].gteq(arel_table[right_column_name]) end
parent_not_null()
click to toggle source
# File lib/awesome_nested_set/set_validator.rb, line 52 def parent_not_null arel_table[parent_column_name].not_eq(nil) end
query()
click to toggle source
# File lib/awesome_nested_set/set_validator.rb, line 25 def query join_scope filter_scope end