ActsAsFastNestedSet 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -0
  2. data/lib/acts_as_fast_nested_set.rb +24 -13
  3. metadata +12 -4
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ Hoe.new('ActsAsFastNestedSet', Adocca::Acts::ActsAsFastNestedSet::VERSION) do |p
10
10
  p.summary = 'Fast nested set, really fast!'
11
11
  # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
12
12
  # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
13
+ p.extra_deps << ['AdoccaMemcache', '>= 0.1.0']
13
14
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
14
15
  end
15
16
 
@@ -54,7 +54,7 @@ require 'active_record'
54
54
  module Adocca
55
55
  module Acts
56
56
  module ActsAsFastNestedSet
57
- VERSION = "0.0.1"
57
+ VERSION = "0.1.1"
58
58
 
59
59
  def self.append_features(base)
60
60
  super
@@ -89,6 +89,15 @@ module Adocca
89
89
  end
90
90
  set_options(options)
91
91
  include Adocca::Acts::ActsAsFastNestedSet::InstanceMethods
92
+ descendant_invalidation_proc = Proc.new do |instance|
93
+ ob = instance.parent
94
+ while ob
95
+ expire_cached_value("#{self.name}:#{ob.id}:descendants")
96
+ ob = ob.parent
97
+ end
98
+ end
99
+ after_save descendant_invalidation_proc
100
+ after_destroy descendant_invalidation_proc
92
101
  end
93
102
  end
94
103
  module SingletonMethods
@@ -127,19 +136,21 @@ module Adocca
127
136
  # All our children and their children etc
128
137
  #
129
138
  def descendants
130
- self.class.find(:all,
131
- :conditions => ["node_id LIKE ? AND id != ?#{unique_with_and}",
132
- "#{self.node_id}%", self.id] + unique_params)
139
+ cache_value("#{self.class.name}:#{self.id}:descendants") do
140
+ self.class.find(:all,
141
+ :conditions => ["node_id LIKE ? AND id != ?#{unique_with_and}",
142
+ "#{self.node_id}%", self.id] + unique_params)
143
+ end
133
144
  end
134
-
135
- def level
136
- if self.node_id.nil?
137
- 1
138
- else
139
- self.node_id.count "."
140
- end
141
- end
142
-
145
+
146
+ def level
147
+ if self.node_id.nil?
148
+ 1
149
+ else
150
+ self.node_id.count "."
151
+ end
152
+ end
153
+
143
154
  private
144
155
 
145
156
  def unique_statement
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ActsAsFastNestedSet
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2006-11-13 00:00:00 +01:00
6
+ version: 0.1.1
7
+ date: 2006-11-27 00:00:00 +01:00
8
8
  summary: Fast nested set, really fast!
9
9
  require_paths:
10
10
  - lib
@@ -25,7 +25,6 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
- post_install_message:
29
28
  authors:
30
29
  - Ryan Davis
31
30
  files:
@@ -58,3 +57,12 @@ dependencies:
58
57
  - !ruby/object:Gem::Version
59
58
  version: 1.1.4
60
59
  version:
60
+ - !ruby/object:Gem::Dependency
61
+ name: AdoccaMemcache
62
+ version_requirement:
63
+ version_requirements: !ruby/object:Gem::Version::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 0.1.0
68
+ version: