Permalink
Browse files

Delete trailing whitespaces.

  • Loading branch information...
1 parent 770f2e3 commit 82d2ae78f6fe620fa3013b4436df216dbdbd2c45 @neglectedvalue committed Feb 19, 2011
Showing with 24 additions and 24 deletions.
  1. +10 −10 ancestry.gemspec
  2. +6 −6 lib/ancestry/class_methods.rb
  3. +8 −8 lib/ancestry/has_ancestry.rb
View
20 ancestry.gemspec
@@ -10,17 +10,17 @@ Gem::Specification.new do |s|
s.homepage = 'http://github.com/stefankroes/ancestry'
s.files = [
- 'ancestry.gemspec',
- 'init.rb',
- 'install.rb',
- 'lib/ancestry.rb',
- 'lib/ancestry/has_ancestry.rb',
- 'lib/ancestry/exceptions.rb',
- 'lib/ancestry/class_methods.rb',
- 'lib/ancestry/instance_methods.rb',
- 'MIT-LICENSE',
+ 'ancestry.gemspec',
+ 'init.rb',
+ 'install.rb',
+ 'lib/ancestry.rb',
+ 'lib/ancestry/has_ancestry.rb',
+ 'lib/ancestry/exceptions.rb',
+ 'lib/ancestry/class_methods.rb',
+ 'lib/ancestry/instance_methods.rb',
+ 'MIT-LICENSE',
'README.rdoc'
]
-
+
s.add_dependency 'activerecord', '>= 2.2.2'
end
View
12 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, :restrict and :destroy.")
end
end
-
+
# Arrangement
def arrange options = {}
scope =
@@ -125,7 +125,7 @@ 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|
@@ -140,7 +140,7 @@ 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.find_each(:conditions => {:parent_id => parent_id}) do |node|
@@ -150,7 +150,7 @@ def build_ancestry_from_parent_ids! parent_id = nil, ancestry = nil
build_ancestry_from_parent_ids! node.id, if ancestry.nil? then "#{node.id}" else "#{ancestry}/#{node.id}" 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
View
16 lib/ancestry/has_ancestry.rb
@@ -11,7 +11,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
@@ -29,18 +29,18 @@ 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
primary_key_format = options[:primary_key_format] || /[0-9]+/
validates_format_of ancestry_column, :with => /\A#{primary_key_format.source}(\/#{primary_key_format.source})*\Z/, :allow_nil => true
# Validate that the ancestor ids don't include own id
validate :ancestry_exclude_self
-
+
# Save ActiveRecord version
self.cattr_accessor :rails_3
self.rails_3 = defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::MAJOR >= 3
-
+
# Workaround to support Rails 2
scope_method = if rails_3 then :scope else :named_scope end
@@ -53,7 +53,7 @@ def has_ancestry options = {}
send scope_method, :siblings_of, lambda { |object| {:conditions => to_node(object).sibling_conditions} }
send scope_method, :ordered_by_ancestry, :order => "(case when #{table_name}.#{ancestry_column} is null then 0 else 1 end), #{table_name}.#{ancestry_column}"
send scope_method, :ordered_by_ancestry_and, lambda { |order| {:order => "(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
@@ -72,7 +72,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|
send scope_method, scope_name, lambda { |depth|
@@ -81,9 +81,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

0 comments on commit 82d2ae7

Please sign in to comment.