public
Rubygem
Description: Extras for DataMapper, including bridges to DataObjects::Migrations and Merb::DataMapper
Homepage: http://datamapper.org
Clone URL: git://github.com/sam/dm-more.git
Search Repo:
fixed return-value in dm-adjust
Sindre Aarsaether (author)
Sat Jun 14 16:20:44 -0700 2008
commit  687e83fa5eaf331dceabdbbb584119cc12d6c851
tree    2df624612fad9c8771a8019f1978f0a18c245d65
parent  02c0ce8ec546a0dfb9f7c0ff8a2d0dab692e9a99
...
11
12
13
14
15
 
 
16
17
18
...
44
45
46
47
48
 
 
49
50
51
...
64
65
66
 
 
67
68
69
...
11
12
13
 
 
14
15
16
17
18
...
44
45
46
 
 
47
48
49
50
51
...
64
65
66
67
68
69
70
71
0
@@ -11,8 +11,8 @@ module DataMapper
0
     # @param attributes <Hash> A hash of attributes to adjust, and their adjustment
0
     # @param load <TrueClass,FalseClass>
0
     # @public
0
- def adjust(attributes, load=true)
0
-
0
+ def adjust(attributes={}, load=true)
0
+ return true if attributes.empty?
0
       adjust_attributes = {}
0
       # Finding the actual properties to adjust
0
       model.properties(repository.name).slice(*attributes.keys).each do |property|
0
@@ -44,8 +44,8 @@ module DataMapper
0
        
0
       end
0
       
0
- # Asking the repository (adapter) to do its magic.
0
- repository.adjust(adjust_attributes,scoped_query)
0
+ # Asking the repository (adapter) to do its magic.
0
+ affected = repository.adjust(adjust_attributes,scoped_query)
0
       
0
       # Reload the objects that was preloaded _and_ affected, unless this collection is loaded
0
       model.all(keys_to_reload).reload(:fields => attributes.keys) if keys_to_reload && !keys_to_reload.empty?
0
@@ -64,6 +64,8 @@ module DataMapper
0
         end
0
       end
0
       
0
+ return affected
0
+
0
     end
0
 
0
   end
...
3
4
5
6
7
8
9
10
11
12
13
...
19
20
21
22
23
 
 
24
25
26
...
125
126
127
128
129
130
131
132
133
...
174
175
176
177
178
 
179
180
181
182
 
 
183
184
185
...
3
4
5
 
 
 
 
 
6
7
8
...
14
15
16
 
 
17
18
19
20
21
...
120
121
122
 
 
 
123
124
125
...
166
167
168
 
169
170
171
172
 
 
173
174
175
176
177
0
@@ -3,11 +3,6 @@ module DataMapper
0
     module NestedSet
0
 
0
       ##
0
- # Include the GeneratorMethods now. Wait with the other methods until
0
- # plugin is actually called (to keep from cluttering namespace)
0
- #
0
-
0
- ##
0
       # docs in the works
0
       #
0
       def is_nested_set(options={})
0
@@ -19,8 +14,8 @@ module DataMapper
0
         property :lft, Integer, :writer => :private
0
         property :rgt, Integer, :writer => :private
0
 
0
- belongs_to :parent, :class_name => self.name, :child_key => [ options[:child_key] ], :order => [:lft.asc]
0
- has n, :children,:class_name => self.name, :child_key => [ options[:child_key] ], :order => [:lft.asc]
0
+ belongs_to :parent, :class_name => self.name, :child_key => [ *options[:child_key] ], :order => [:lft.asc]
0
+ has n, :children, :class_name => self.name, :child_key => [ *options[:child_key] ], :order => [:lft.asc]
0
 
0
         before :create do
0
           # scenarios:
0
@@ -125,9 +120,6 @@ module DataMapper
0
         end
0
 
0
         ##
0
- # does all the actual movement in #move, but does not save afterwards. this is used internally in
0
- # before :save, and will probably be marked private. should not be used by organic beings.
0
- #
0
         # @see move
0
         def move_without_saving(vector)
0
           if vector.is_a? Hash then action,object = vector.keys[0],vector.values[0] else action = vector end
0
@@ -174,12 +166,12 @@ module DataMapper
0
             self.class.all(:rgt.gte => position).adjust(:rgt => gap)
0
             self.class.all(:lft.gte => position).adjust(:lft => gap)
0
             # offset this node (and all its descendants) to the right position
0
- offset = position - self.lft
0
             old_position = self.lft
0
+ offset = position - old_position
0
             self.class.all(:rgt => self.lft..self.rgt).adjust(:lft => offset, :rgt => offset)
0
             # close the gap this movement left behind.
0
- self.class.all(:rgt.gt => old_position).adjust(:rgt => -gap)
0
- self.class.all(:lft.gt => old_position).adjust(:lft => -gap)
0
+ self.class.all(:rgt.gt => old_position).adjust(:rgt => -gap,false)
0
+ self.class.all(:lft.gt => old_position).adjust(:lft => -gap,false)
0
           else
0
             # make a gap where the new node can be inserted
0
             self.class.all(:rgt.gte => position).adjust(:rgt => 2)

Comments

  • solnic Sun Jun 15 10:00:39 -0700 2008

    self.class.all(:rgt.gt => old_position).adjust(:rgt => -gap,false)
    self.class.all(:lft.gt => old_position).adjust(:lft => -gap,false)

    ^^

    this causes a syntax error:

    gems/dm-is-nested_set-0.9.2/lib/dm-is-nested_set/is/nested_set.rb:173: syntax error, unexpected ‘)’, expecting tASSOC

    :)