Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

White space fixes

* Trim whitespace from end of lines
* Trim whitespace only lines
* Add blank line to end of files
  • Loading branch information...
commit c093fe65e01336b88db3e81ceb411d75eed2548c 1 parent cd59fc6
@anthonybatchelor-examtime authored
View
36 lib/ancestry/class_methods.rb
@@ -3,8 +3,8 @@ module ClassMethods
# Fetch tree node if necessary
def to_node object
if object.is_a?(self.base_class) then object else find(object) end
- end
-
+ end
+
# Scope on relative depth options
def scope_depth depth_options, depth
depth_options.inject(self.base_class) do |scope, option|
@@ -26,7 +26,7 @@ def orphan_strategy= orphan_strategy
raise Ancestry::AncestryException.new("Invalid orphan strategy, valid ones are :rootify,:adopt, :restrict and :destroy.")
end
end
-
+
# Arrangement
def arrange options = {}
scope =
@@ -38,8 +38,8 @@ def arrange options = {}
# Get all nodes ordered by ancestry and start sorting them into an empty hash
arrange_nodes scope.all(options)
end
-
- # Arrange array of nodes into a nested hash of the form
+
+ # Arrange array of nodes into a nested hash of the form
# {node => children}, where children = {} if the node has no children
def arrange_nodes(nodes)
# Get all nodes ordered by ancestry and start sorting them into an empty hash
@@ -55,9 +55,9 @@ def arrange_nodes(nodes)
arranged_nodes
end
end
-
- # Pseudo-preordered array of nodes. Children will always follow parents,
- # but the ordering of nodes within a rank depends on their order in the
+
+ # Pseudo-preordered array of nodes. Children will always follow parents,
+ # but the ordering of nodes within a rank depends on their order in the
# array that gets passed in
def sort_by_ancestry(nodes)
arranged = nodes.is_a?(Hash) ? nodes : arrange_nodes(nodes.sort_by{|n| n.ancestry || '0'})
@@ -73,8 +73,8 @@ def sort_by_ancestry(nodes)
def check_ancestry_integrity! options = {}
parents = {}
exceptions = [] if options[:report] == :list
-
- self.base_class.unscoped do
+
+ self.base_class.unscoped do
# For each node ...
self.base_class.find_each do |node|
begin
@@ -112,7 +112,7 @@ def restore_ancestry_integrity!
parents = {}
# Wrap the whole thing in a transaction ...
self.base_class.transaction do
- self.base_class.unscoped do
+ self.base_class.unscoped do
# For each node ...
self.base_class.find_each do |node|
# ... set its ancestry to nil if invalid
@@ -129,9 +129,9 @@ def restore_ancestry_integrity!
until parent.nil? || parent == node.id
parent = parents[parent]
end
- parents[node.id] = nil if parent == node.id
+ parents[node.id] = nil if parent == node.id
end
-
+
# For each node ...
self.base_class.find_each do |node|
# ... rebuild ancestry from parents array
@@ -146,10 +146,10 @@ def restore_ancestry_integrity!
end
end
end
-
+
# Build ancestry from parent id's for migration purposes
def build_ancestry_from_parent_ids! parent_id = nil, ancestry = nil
- self.base_class.unscoped do
+ self.base_class.unscoped do
self.base_class.find_each(:conditions => {:parent_id => parent_id}) do |node|
node.without_ancestry_callbacks do
node.update_attribute ancestry_column, ancestry
@@ -158,12 +158,12 @@ def build_ancestry_from_parent_ids! parent_id = nil, ancestry = nil
end
end
end
-
+
# Rebuild depth cache if it got corrupted or if depth caching was just turned on
def rebuild_depth_cache!
raise Ancestry::AncestryException.new("Cannot rebuild depth cache for model without depth caching.") unless respond_to? :depth_cache_column
-
- self.base_class.unscoped do
+
+ self.base_class.unscoped do
self.base_class.find_each do |node|
node.update_attribute depth_cache_column, node.depth
end
View
2  lib/ancestry/exceptions.rb
@@ -4,4 +4,4 @@ class AncestryException < RuntimeError
class AncestryIntegrityException < AncestryException
end
-end
+end
View
14 lib/ancestry/has_ancestry.rb
@@ -7,7 +7,7 @@ def has_ancestry options = {}
raise Ancestry::AncestryException.new("Unknown option for has_ancestry: #{key.inspect} => #{value.inspect}.")
end
end
-
+
# Include instance methods
include Ancestry::InstanceMethods
@@ -25,13 +25,13 @@ def has_ancestry options = {}
# Save self as base class (for STI)
cattr_accessor :base_class
self.base_class = self
-
+
# Validate format of ancestry column value
validates_format_of ancestry_column, :with => Ancestry::ANCESTRY_PATTERN, :allow_nil => true
# Validate that the ancestor ids don't include own id
validate :ancestry_exclude_self
-
+
# Named scopes
scope :roots, :conditions => {ancestry_column => nil}
scope :ancestors_of, lambda { |object| {:conditions => to_node(object).ancestor_conditions} }
@@ -41,7 +41,7 @@ def has_ancestry options = {}
scope :siblings_of, lambda { |object| {:conditions => to_node(object).sibling_conditions} }
scope :ordered_by_ancestry, reorder("(case when #{table_name}.#{ancestry_column} is null then 0 else 1 end), #{table_name}.#{ancestry_column}")
scope :ordered_by_ancestry_and, lambda { |order| reorder("(case when #{table_name}.#{ancestry_column} is null then 0 else 1 end), #{table_name}.#{ancestry_column}, #{order}") }
-
+
# Update descendants with new ancestry before save
before_save :update_descendants_with_new_ancestry
@@ -60,7 +60,7 @@ def has_ancestry options = {}
# Validate depth column
validates_numericality_of depth_cache_column, :greater_than_or_equal_to => 0, :only_integer => true, :allow_nil => false
end
-
+
# Create named scopes for depth
{:before_depth => '<', :to_depth => '<=', :at_depth => '=', :from_depth => '>=', :after_depth => '>'}.each do |scope_name, operator|
scope scope_name, lambda { |depth|
@@ -69,9 +69,9 @@ def has_ancestry options = {}
}
end
end
-
+
# Alias has_ancestry with acts_as_tree, if it's available.
- if !defined?(ActsAsTree)
+ if !defined?(ActsAsTree)
alias_method :acts_as_tree, :has_ancestry
end
end
View
8 lib/ancestry/instance_methods.rb
@@ -27,7 +27,7 @@ def update_descendants_with_new_ancestry
end
end
end
-
+
# Apply orphan strategy
def apply_orphan_strategy
# Skip this if callbacks are disabled
@@ -229,16 +229,16 @@ def primary_key_type
end
def unscoped_descendants
self.base_class.unscoped do
- self.base_class.all(:conditions => descendant_conditions)
+ self.base_class.all(:conditions => descendant_conditions)
end
end
-
+
# basically validates the ancestry, but also applied if validation is
# bypassed to determine if chidren should be affected
def sane_ancestry?
ancestry.nil? || (ancestry.to_s =~ Ancestry::ANCESTRY_PATTERN && !ancestor_ids.include?(self.id))
end
-
+
def unscoped_find id
self.base_class.unscoped { self.base_class.find(id) }
end
Please sign in to comment.
Something went wrong with that request. Please try again.