JohnSmall-acts-as-hausdorff-space 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.document +5 -0
  2. data/.gitignore +10 -0
  3. data/VERSION.yml +1 -1
  4. data/acts-as-hausdorff-space.gemspec +97 -0
  5. data/design_idea.rdoc +27 -0
  6. data/doc/LICENSE.html +113 -0
  7. data/doc/MindoroMarine.html +153 -0
  8. data/doc/MindoroMarine/Acts.html +150 -0
  9. data/doc/MindoroMarine/Acts/HausdorffSpace.html +160 -0
  10. data/doc/MindoroMarine/Acts/HausdorffSpace/ActMethods.html +230 -0
  11. data/doc/MindoroMarine/Acts/HausdorffSpace/ClassMethods.html +466 -0
  12. data/doc/MindoroMarine/Acts/HausdorffSpace/Gap.html +193 -0
  13. data/doc/MindoroMarine/Acts/HausdorffSpace/HSArray.html +234 -0
  14. data/doc/MindoroMarine/Acts/HausdorffSpace/InstanceMethods.html +1152 -0
  15. data/doc/MindoroMarine/Acts/HausdorffSpace/VirtualRoot.html +261 -0
  16. data/doc/README_rdoc.html +386 -0
  17. data/doc/created.rid +1 -0
  18. data/doc/images/brick.png +0 -0
  19. data/doc/images/brick_link.png +0 -0
  20. data/doc/images/bug.png +0 -0
  21. data/doc/images/bullet_black.png +0 -0
  22. data/doc/images/bullet_toggle_minus.png +0 -0
  23. data/doc/images/bullet_toggle_plus.png +0 -0
  24. data/doc/images/date.png +0 -0
  25. data/doc/images/find.png +0 -0
  26. data/doc/images/loadingAnimation.gif +0 -0
  27. data/doc/images/macFFBgHack.png +0 -0
  28. data/doc/images/package.png +0 -0
  29. data/doc/images/page_green.png +0 -0
  30. data/doc/images/page_white_text.png +0 -0
  31. data/doc/images/page_white_width.png +0 -0
  32. data/doc/images/plugin.png +0 -0
  33. data/doc/images/ruby.png +0 -0
  34. data/doc/images/tag_green.png +0 -0
  35. data/doc/images/wrench.png +0 -0
  36. data/doc/images/wrench_orange.png +0 -0
  37. data/doc/images/zoom.png +0 -0
  38. data/doc/index.html +140 -0
  39. data/doc/js/darkfish.js +116 -0
  40. data/doc/js/jquery.js +32 -0
  41. data/doc/js/quicksearch.js +114 -0
  42. data/doc/js/thickbox-compressed.js +10 -0
  43. data/doc/lib/acts-as-hausdorff-space_rb.html +55 -0
  44. data/doc/lib/acts_as_hausdorff_space_rb.html +53 -0
  45. data/doc/rdoc.css +696 -0
  46. data/lib/acts_as_hausdorff_space.rb +22 -14
  47. data/test/acts_as_hausdorff_space_test.rb +13 -0
  48. metadata +48 -4
@@ -139,7 +139,7 @@ module MindoroMarine
139
139
 
140
140
  ############################ INSTANCE METHODS ######################################################
141
141
  module InstanceMethods
142
- attr_accessor :parent,:in_tree
142
+ attr_accessor :in_tree
143
143
 
144
144
  # initialize isn't always called so we can't do this in initialize. This sets up things we need to hold the tree together
145
145
  def after_initialize
@@ -189,15 +189,15 @@ module MindoroMarine
189
189
  # set the parent to be the class.virtual_root
190
190
  # If the parent is already set then don't go to the database to look for it, just return it
191
191
  def parent
192
- if !in_tree && left_col_val && right_col_val && !@parent # only get the parent by SQL if we don't know what it is
193
- @parent = self.class.find :first, :conditions => " #{left_col_val} > #{self.class.left_col_name} and #{left_col_val} < #{self.class.right_col_name} ",:order =>'#{self.class.left_col_name} DESC'
194
- if !@parent
192
+ # if !in_tree && left_col_val && right_col_val && !@parent # only get the parent by SQL if we don't know what it is
193
+ # @parent = self.class.find :first, :conditions => " #{left_col_val} > #{self.class.left_col_name} and #{left_col_val} < #{self.class.right_col_name} ",:order =>'#{self.class.left_col_name} DESC'
194
+ # if !@parent
195
195
  # @is_root = (lft == rgt) || (id == root.id)
196
- return self.class.virtual_root
197
- end
198
- else
196
+ # return self.class.virtual_root
197
+ # end
198
+ # else
199
199
  @parent
200
- end
200
+ # end
201
201
  end
202
202
 
203
203
  # set a new parent. This will save the parent, which will force a save of this child after the parent has had its lft and rgt set
@@ -293,11 +293,15 @@ def children
293
293
  end
294
294
 
295
295
  # Where most of the clever action happens.
296
- # 1. If there's no parent then set the <class>.virtual_root to be the parent before continuing
297
- # 2. Find the left boundary and the right boundary from the parent or the siblings or both
298
- # 3. If this record has no children then set lft=rgt and put it well on the left of the gap
299
- # 4. If there are children then set the lft and rgt to a comfortable size to hold the children
296
+ # 1. If we haven't got a parent and it's not a new record then leave things alone. This allows us to update
297
+ # records in isolation without messing with tree positions
298
+ # 2. If there's no parent then set the <class>.virtual_root to be the parent before continuing
299
+ # 3. Find the left boundary and the right boundary from the parent or the siblings or both
300
+ # 4. If this record has no children then set lft=rgt and put it well on the left of the gap
301
+ # 5. If there are children then set the lft and rgt to a comfortable size to hold the children
302
+
300
303
  def before_save
304
+ if new_record? || parent
301
305
  if !@parent
302
306
  self.class.roots # this loads virtual_root with roots
303
307
  self.class.virtual_root.children << self # if we haven't got a parent then make the virtual root the parent
@@ -312,6 +316,7 @@ gap = far_right - far_left
312
316
  else
313
317
  self.left_col_val = self.right_col_val = far_left+(gap/self.class.bias)
314
318
  end
319
+ end
315
320
  end
316
321
 
317
322
  # Where most of the remaining action happens
@@ -320,19 +325,22 @@ end
320
325
  # The code works out the values required for a single SQL statement that pulls the entire branch across
321
326
  #
322
327
  # If we haven't moved from elsewhere then save each child that needs saving
328
+ # If we haven't got a parent then leave things alone - this allows records to be updated in isolation
323
329
  def after_save
330
+ if parent
324
331
  if @prev_left && @prev_right && @children.size > 0 # if we're moving from somewhere else
325
332
  @children.clear
326
333
  scale = ((right_col_val-left_col_val)/(@prev_right - @prev_left)).abs
327
334
  old_mid_point = (@prev_right + @prev_left)/2
328
335
  new_mid_point = (right_col_val+left_col_val)/2
329
- sql = "update #{self.class.table_name} t1 set t1.#{left_col_name} = ((t1.#{left_col_name} - #{old_mid_point})*#{scale})+#{new_mid_point}, t1.#{right_col_name} = ((t1.#{right_col_name} - #{old_mid_point})*#{scale})+#{new_mid_point} where t1.#{left_col_name} >#{@prev_left} and t1.#{right_col_name} < #{@prev_right} "
336
+ sql = "update #{self.class.table_name} set #{left_col_name} = ((#{left_col_name} - #{old_mid_point})*#{scale})+#{new_mid_point}, #{right_col_name} = ((#{right_col_name} - #{old_mid_point})*#{scale})+#{new_mid_point} where #{left_col_name} >#{@prev_left} and #{right_col_name} < #{@prev_right} "
330
337
  connection.update_sql(sql)
331
338
  build_full_tree # get the children back
332
339
  else
333
340
  @children.each{|child| child.save if !(child.left_col_val && child.right_col_val) } # save only the ones that need lft and rgt
334
341
  end
335
- @prev_left = @prev_right = nil
342
+ @prev_left = @prev_right = nil
343
+ end
336
344
  end
337
345
 
338
346
  # get the siblings. All immediate children of the parent minus self
@@ -92,6 +92,19 @@ context 'Instance Methods - Add a Root' do
92
92
  assert_equal 4,read_root.children.size,"the child didn't get moved"
93
93
  assert_equal 1,read_root.children.first.children.size,"the child didn't appear in the right place"
94
94
  end
95
+
96
+ should 'allow editing one child on its own' do
97
+ all_recs = HausdorffSpaceTest.find :all
98
+ rec = all_recs[3]
99
+ lft = rec.left_col
100
+ rgt = rec.right_col
101
+ id = rec.id
102
+ rec.name = 'new name'
103
+ rec.save
104
+ read_rec = HausdorffSpaceTest.find id
105
+ assert_equal lft,read_rec.left_col,'the left column is wrong on a read read'
106
+ assert_equal rgt,read_rec.right_col,'the right column is wrong on a read read'
107
+ end
95
108
  end # context 'add many children'
96
109
 
97
110
  context 'add many grandchildren' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: JohnSmall-acts-as-hausdorff-space
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Small
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-25 00:00:00 -07:00
12
+ date: 2009-05-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,10 +23,54 @@ extra_rdoc_files:
23
23
  - LICENSE
24
24
  - README.rdoc
25
25
  files:
26
+ - .document
27
+ - .gitignore
26
28
  - LICENSE
27
29
  - README.rdoc
28
30
  - Rakefile
29
31
  - VERSION.yml
32
+ - acts-as-hausdorff-space.gemspec
33
+ - design_idea.rdoc
34
+ - doc/LICENSE.html
35
+ - doc/MindoroMarine.html
36
+ - doc/MindoroMarine/Acts.html
37
+ - doc/MindoroMarine/Acts/HausdorffSpace.html
38
+ - doc/MindoroMarine/Acts/HausdorffSpace/ActMethods.html
39
+ - doc/MindoroMarine/Acts/HausdorffSpace/ClassMethods.html
40
+ - doc/MindoroMarine/Acts/HausdorffSpace/Gap.html
41
+ - doc/MindoroMarine/Acts/HausdorffSpace/HSArray.html
42
+ - doc/MindoroMarine/Acts/HausdorffSpace/InstanceMethods.html
43
+ - doc/MindoroMarine/Acts/HausdorffSpace/VirtualRoot.html
44
+ - doc/README_rdoc.html
45
+ - doc/created.rid
46
+ - doc/images/brick.png
47
+ - doc/images/brick_link.png
48
+ - doc/images/bug.png
49
+ - doc/images/bullet_black.png
50
+ - doc/images/bullet_toggle_minus.png
51
+ - doc/images/bullet_toggle_plus.png
52
+ - doc/images/date.png
53
+ - doc/images/find.png
54
+ - doc/images/loadingAnimation.gif
55
+ - doc/images/macFFBgHack.png
56
+ - doc/images/package.png
57
+ - doc/images/page_green.png
58
+ - doc/images/page_white_text.png
59
+ - doc/images/page_white_width.png
60
+ - doc/images/plugin.png
61
+ - doc/images/ruby.png
62
+ - doc/images/tag_green.png
63
+ - doc/images/wrench.png
64
+ - doc/images/wrench_orange.png
65
+ - doc/images/zoom.png
66
+ - doc/index.html
67
+ - doc/js/darkfish.js
68
+ - doc/js/jquery.js
69
+ - doc/js/quicksearch.js
70
+ - doc/js/thickbox-compressed.js
71
+ - doc/lib/acts-as-hausdorff-space_rb.html
72
+ - doc/lib/acts_as_hausdorff_space_rb.html
73
+ - doc/rdoc.css
30
74
  - lib/acts-as-hausdorff-space.rb
31
75
  - lib/acts_as_hausdorff_space.rb
32
76
  - test/acts_as_hausdorff_space_test.rb
@@ -36,7 +80,7 @@ files:
36
80
  - test/schema.rb
37
81
  - test/sqlite3.rb
38
82
  - test/test_helper.rb
39
- has_rdoc: true
83
+ has_rdoc: false
40
84
  homepage: http://github.com/JohnSmall/acts-as-hausdorff-space
41
85
  post_install_message:
42
86
  rdoc_options:
@@ -60,7 +104,7 @@ requirements: []
60
104
  rubyforge_project:
61
105
  rubygems_version: 1.2.0
62
106
  signing_key:
63
- specification_version: 2
107
+ specification_version: 3
64
108
  summary: Use real numbers instead of integers for nested sets because real numbers are a Hausdorff space
65
109
  test_files:
66
110
  - test/schema.rb