Permalink
Browse files

Update lib/ancestry/has_ancestry.rb

Use stabby lambda for named scope in order to be compatible with rails 4 and use ruby 1.9 syntax
  • Loading branch information...
1 parent 864acf1 commit 10d1977987919c65b36f390db8a117de396d125b @Systho committed Jan 23, 2013
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/ancestry/has_ancestry.rb
@@ -33,14 +33,14 @@ def has_ancestry options = {}
validate :ancestry_exclude_self
# Named scopes
- scope :roots, :conditions => {ancestry_column => nil}
- scope :ancestors_of, lambda { |object| {:conditions => to_node(object).ancestor_conditions} }
- scope :children_of, lambda { |object| {:conditions => to_node(object).child_conditions} }
- scope :descendants_of, lambda { |object| {:conditions => to_node(object).descendant_conditions} }
- scope :subtree_of, lambda { |object| {:conditions => to_node(object).subtree_conditions} }
- 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}") }
+ scope :roots, ->(){ where(ancestry_column => nil) }
+ scope :ancestors_of, ->(object){ where(to_node(object).ancestor_conditions) }
+ scope :children_of, ->(object){ where(to_node(object).child_conditions) }, lambda { |object| {:conditions => to_node(object).child_conditions} }
+ scope :descendants_of, ->(object){ where(to_node(object).descendant_conditions) }, lambda { |object| {:conditions => to_node(object).descendant_conditions} }
+ scope :subtree_of, ->(object){ where(to_node(object).subtree_conditions) }, lambda { |object| {:conditions => to_node(object).subtree_conditions} }
+ scope :siblings_of, ->(object){ where(to_node(object).sibling_conditions) }, 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, ->(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

0 comments on commit 10d1977

Please sign in to comment.