3 self.abstract_class = true
9 return nil if self._skip_load?
11 pm = Manifest.manifest.models[self.my_peta.parent_item_name].classify
12 define_singleton_method("parent_model") do
15 destm = Manifest.manifest.models[self.my_peta.destination_item_name].classify
16 define_singleton_method("destination_model") do
19 pfk = self.my_peta.parent_item_name + '_id'
20 define_singleton_method("binder_key") do
23 dest_key = if self.my_peta.destination_item_name
24 self.my_peta.destination_item_name + '_id'
28 define_singleton_method("destination_key") do
46 def self.destination_model
51 self.__send__ self.class.root_model.item_name
55 self.root.own? operators
58 # super return if my item
59 def visible? operators
60 return false if super == false
61 self.root.visible? operators
64 def self.play_list_order
65 self.table_name + '.t'
68 def self.new_t binder_id
69 r = self.max_t(binder_id)
70 r.blank? ? 0 : r.to_i + 1
73 def self.max_t binder_id
74 self.where([self.binder_key + ' = ?', binder_id]).maximum(:t)
77 def self.find_t binder_id, t
78 self.where([self.binder_key + ' = ? and t = ?', binder_id, t]).first
81 def self.collect_t binder_id
82 r = self.where([self.binder_key + ' = ?', binder_id]).order('t')
88 ary.compact.sort.each do |t|
89 break false unless t == i
95 def self.validate_t binder_id
96 self.serial?(self.collect_t(binder_id))
100 self.class.binder_key
104 self.class.destination_key
108 self.attributes[self.binder_key]
112 if self.destination_key
113 self.attributes[self.destination_key]
120 self.class.where([self.binder_key + ' = ? and t >= ?', self.binder_id, self.t]).update_all('t = t + 1')
123 def lesser_shift old_t
124 self.t = 0 if self.t < 0
125 self.class.where([self.binder_key + ' = ? and (t >= ? and t < ?)', self.binder_id, self.t, old_t]).update_all('t = t + 1')
128 def higher_shift old_t
129 nf = self.class.find_t(self.binder_id, self.t)
130 max_t = self.class.max_t(self.binder_id).to_i
131 self.t = max_t if self.t > max_t
132 self.class.where([self.binder_key + ' = ? and (t > ? and t <= ?)', self.binder_id, old_t, self.t]).update_all('t = t - 1')
135 def update_shift old_t
143 def rotate old_t = nil
146 self.t = self.class.new_t self.binder_id
153 self.update_shift old_t
158 def store operators, old_t = nil
160 self.class.transaction do
161 case self.allow? operators
165 raise ActiveRecord::Forbidden
169 raise ActiveRecord::Rollback unless res
170 res = self.class.validate_t(self.binder_id)
172 self.errors.add :t, 'unserialized'
173 raise ActiveRecord::Rollback
179 # destroy and shorten
182 self.class.transaction do
185 [self.binder_key + ' = ? and (t > ?)', self.binder_id, self.t]
186 ).update_all('t = t - 1')
188 raise ActiveRecord::Rollback unless res