Class: ODDB::Persistence::Pointer

Inherits:
Object
  • Object
show all
Defined in:
src/util/persistence.rb,
test/test_util/oddbapp.rb,
test/test_util/persistence.rb,
test/test_model/registration.rb

Constant Summary

SECURE_COMMANDS =
[
  :active_agent, :address, :address_suggestion, :atc_class,
  :analysis_group, :commercial_form, :company, :doctor, :hospital,
  :cyp450, :fachinfo, :feedback, :galenic_form, :galenic_group,
  :generic_group, :indication, :invoice,
  :address_suggestion, :migel_group, :subgroup, :product,
  :narcotic, :narcotics, :orphaned_fachinfo, :orphaned_patinfo,
  :package, :patent, :patinfo, :pdf_patinfo, :position,
  :poweruser, :registration, :sequence, :slate, :sl_entry,
  :sponsor, :substance, :user, :limitation_text, :minifi, 
  :index_therapeuticus
]

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Pointer) initialize(*args)

A new instance of Pointer



185
186
187
# File 'src/util/persistence.rb', line 185

def initialize(*args)
  @directions = args.collect { |arg| [arg].flatten }
end

Instance Attribute Details

- (Object) directions (readonly)

Returns the value of attribute directions



349
350
351
# File 'src/util/persistence.rb', line 349

def directions
  @directions
end

Class Method Details

+ (Object) from_yus_privilege(string)



155
156
157
158
159
160
161
# File 'src/util/persistence.rb', line 155

def from_yus_privilege(string)
  ## does not support encapsulated pointers
  args = string.scan(/!([^!]+)/u).collect { |matches|
    matches.first.split('.').compact
  }
  self.new(*args)
end

+ (Object) parse(string)



150
151
152
153
154
# File 'src/util/persistence.rb', line 150

def parse(string)
  ast = @parser.parse(string)
  ast.compact!
  produce_pointer(ast)
end

Instance Method Details

- (Object) +(other)



338
339
340
341
# File 'src/util/persistence.rb', line 338

def +(other)
  dir = @directions.dup << [other].flatten
  Pointer.new(*dir)
end

- (Object) ==(other)



342
343
344
# File 'src/util/persistence.rb', line 342

def ==(other)
  eql?(other)
end

- (Object) ancestors



188
189
190
191
192
193
194
195
# File 'src/util/persistence.rb', line 188

def ancestors
  pointer = self
  ancestors = []
  while(pointer = pointer.parent)
    ancestors.unshift(pointer)
  end
  ancestors
end

- (Object) append(value)



196
197
198
199
200
201
202
# File 'src/util/persistence.rb', line 196

def append(value)
  @directions << [] unless @directions.last
  last_step = @directions.last
  unless last_step.last == value
    last_step << value
  end
end

- (Object) creator



203
204
205
# File 'src/util/persistence.rb', line 203

def creator
  Pointer.new([:create, self])
end

- (Object) dup



206
207
208
209
# File 'src/util/persistence.rb', line 206

def dup
  directions = @directions.collect { |step| step.dup }
  Pointer.new(*directions)
end

- (Boolean) eql?(other)

Returns:

  • (Boolean)


210
211
212
# File 'src/util/persistence.rb', line 210

def eql?(other)
  to_s.eql?(other.to_s)
end

- (Object) hash



345
346
347
# File 'src/util/persistence.rb', line 345

def hash
  to_s.hash
end

- (Boolean) insecure?

Returns:

  • (Boolean)


213
214
215
216
217
218
219
220
# File 'src/util/persistence.rb', line 213

def insecure?
  @directions.any? { |step|
    !SECURE_COMMANDS.include?(step.first.to_sym) \
    || step.any? { |arg|
      arg.is_a?(Pointer)
    }
  }
end

- (Object) issue_create(app)



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'src/util/persistence.rb', line 221

def issue_create(app)
  new_obj = resolve(app)
  unless new_obj.nil?
    return new_obj
  end
  pointer = dup
  command = pointer.directions.pop
  command[0] = 'create_' << command.first.to_s
  hook = pointer.resolve(app)
  new_obj = hook.send(*(command.compact))
  new_obj.pointer = self
  new_obj.init(app)
  # Only the hook must be stored in issue_create
  # because wie scan its connections for unsaved objects
  # see ODBA::Persistable
  # In the case where the newly created object were saved
  # *before* the hook, any intermediate collections might not 
  # be properly stored, resulting in the newly created object
  # being inaccessible after a restart
  hook.odba_store
  new_obj
end

- (Object) issue_delete(app)



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'src/util/persistence.rb', line 243

def issue_delete(app)
  obj = resolve(app)
  if(obj.respond_to?(:odba_delete))
    ## checkout the object from all indices
    ## if this happens after hook.send(*command), some index-updates 
    ## will fail.
    obj.odba_delete
  end
  if obj.respond_to?(:checkout)
    obj.checkout
  end
  pointer = dup
  command = pointer.directions.pop
  command[0] = 'delete_' << command.first.to_s
  hook = pointer.resolve(app)
  if(hook.respond_to?(command.first))
    hook.send(*(command.compact))
    ### ODBA needs the delete_<command> method to call
    ### odba_store or odba_isolated_store on whoever was the
    ### last connection to this item.
  end
rescue InvalidPathError, UninitializedPathError => e
  warn "Could not delete: #{to_s}, reason: #{e.message}"
end

- (Object) issue_update(hook, values, origin = nil)



267
268
269
270
271
272
273
274
275
276
277
# File 'src/util/persistence.rb', line 267

def issue_update(hook, values, origin = nil)
  obj = resolve(hook)
  unless(obj.nil?)
    diff = obj.diff(values, hook)
    unless diff.empty?
      obj.update_values(diff, origin)
      obj.odba_store
    end
  end
  obj
end

- (Object) last_step



278
279
280
# File 'src/util/persistence.rb', line 278

def last_step
  @directions.last.dup
end

- (Object) parent



281
282
283
284
285
# File 'src/util/persistence.rb', line 281

def parent
  parent = dup
  parent.directions.pop
  parent unless parent.directions.empty?
end

- (Object) resolve(hook)



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'src/util/persistence.rb', line 286

def resolve(hook)
  Persistence.find_by_pointer(to_s) or begin
    lasthook = hook
    laststep = []
    @directions.each { |step|
      if(hook.nil?)
        call = laststep.shift
        args = laststep.join(',')
        msg = "#{to_s} -> #{lasthook.class}::#{call}(#{args}) returned nil"
        raise(UninitializedPathError.new(msg, self))
      elsif(hook.respond_to?(step.first))
        lasthook = hook
        laststep = step
        hook = begin
          hook.send(*step)
        rescue
        end
      else
        call = step.shift
        args = step.join(',')
        msg = "#{to_s} -> undefined Method #{hook.class}::#{call}(#{args})"
        raise(InvalidPathError.new(msg, self))
      end
    }
    hook
  end
end

- (Object) skeleton



313
314
315
316
317
318
# File 'src/util/persistence.rb', line 313

def skeleton
  @directions.collect { |step| 
    cmd = step.first
    cmd.is_a?(Symbol) ? cmd : cmd.intern
  }
end

- (Object) to_s



319
320
321
322
323
324
325
326
327
328
329
330
# File 'src/util/persistence.rb', line 319

def to_s
  ':' << @directions.collect { |orig|
    step = orig.collect { |arg|
      if(arg.is_a? Pointer)
        arg
      else
        arg.to_s.gsub('%','%%').gsub(/[:!,.]/u, '%\0')
      end
    }
    '!' << step.join(',')
  }.join << '.'
end

- (Object) to_yus_privilege



331
332
333
334
335
336
337
# File 'src/util/persistence.rb', line 331

def to_yus_privilege
  @directions.inject('org.oddb.model') { |yus, steps|
    steps = steps.dup
    yus << '.!' << steps.shift.to_s
    steps.inject(yus) { |yus, step| yus << '.' << step.to_s }
  }
end