Class: DataMapper::Is::Temporal::TemporalListProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-is-temporal/is/temporal.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_object, list, temporal_list_model, temporal_list_name, name, context) ⇒ TemporalListProxy

Returns a new instance of TemporalListProxy.



290
291
292
293
294
295
296
297
298
299
300
# File 'lib/dm-is-temporal/is/temporal.rb', line 290

def initialize(base_object, list, temporal_list_model, temporal_list_name, name, context)
  @base_object = base_object
  @list = list
  @temporal_list_name = temporal_list_name
  @temporal_list_model = temporal_list_model
  @name = name
  @context = context

  @bidirectional_method = DataMapper::Inflector.singularize(
      DataMapper::Inflector.tableize(base_object.class.name.split('::').last))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



415
416
417
# File 'lib/dm-is-temporal/is/temporal.rb', line 415

def method_missing(sym, *args, &block)
  @list.__send__(sym, *args, &block)
end

Instance Method Details

#<<(x) ⇒ Object



302
303
304
305
306
307
308
309
# File 'lib/dm-is-temporal/is/temporal.rb', line 302

def <<(x)
  new_model = @temporal_list_model.create(:updated_at => @context, @name => x)
  if x.respond_to?("#{@bidirectional_method}=")
    x.send("#{@bidirectional_method}=", @base_object)
  end
  @base_object.send(@temporal_list_name) << new_model
  @list << x
end

#[]=(x, y) ⇒ Object



317
318
319
# File 'lib/dm-is-temporal/is/temporal.rb', line 317

def []=(x,y)
  raise "Unsupported method"
end

#clearObject



311
312
313
314
315
# File 'lib/dm-is-temporal/is/temporal.rb', line 311

def clear
  @base_object.send(@temporal_list_name).each do |temporal|
    temporal.deleted_at = @context
  end
end

#collect!Object



325
326
327
# File 'lib/dm-is-temporal/is/temporal.rb', line 325

def collect!
  raise "Unsupported method"
end

#compact!Object



329
330
331
# File 'lib/dm-is-temporal/is/temporal.rb', line 329

def compact!
  raise "Unsupported method"
end

#delete(obj) ⇒ Object



333
334
335
336
337
338
339
340
# File 'lib/dm-is-temporal/is/temporal.rb', line 333

def delete(obj)
  @base_object.send(@temporal_list_name).each do |temporal|
    if temporal.send(@name) == obj
      temporal.deleted_at = @context
      return true
    end
  end
end

#delete_at(i) ⇒ Object



342
343
344
345
# File 'lib/dm-is-temporal/is/temporal.rb', line 342

def delete_at(i)
  # probably won't ever support this - not really doing order
  raise "Unsupported method"
end

#delete_ifObject



347
348
349
350
351
352
353
# File 'lib/dm-is-temporal/is/temporal.rb', line 347

def delete_if
  @base_object.send(@temporal_list_name).each do |temporal|
    if yield(temporal.send(@name))
      temporal.deleted_at = @context
    end
  end
end

#drop(i) ⇒ Object



355
356
357
# File 'lib/dm-is-temporal/is/temporal.rb', line 355

def drop(i)
  raise "Unsupported method"
end

#drop_while(i) ⇒ Object



359
360
361
# File 'lib/dm-is-temporal/is/temporal.rb', line 359

def drop_while(i)
  raise "Unsupported method"
end

#fill(*args) ⇒ Object



363
364
365
# File 'lib/dm-is-temporal/is/temporal.rb', line 363

def fill(*args)
  raise "Unsupported method"
end

#flatten!(level = nil) ⇒ Object



367
368
369
# File 'lib/dm-is-temporal/is/temporal.rb', line 367

def flatten!(level=nil)
  raise "Unsupported method"
end

#insert(index, *args) ⇒ Object



375
376
377
# File 'lib/dm-is-temporal/is/temporal.rb', line 375

def insert(index, *args)
  raise "Unsupported method"
end

#map!Object



321
322
323
# File 'lib/dm-is-temporal/is/temporal.rb', line 321

def map!
  raise "Unsupported method"
end

#popObject



379
380
381
382
383
# File 'lib/dm-is-temporal/is/temporal.rb', line 379

def pop
  temporal = @base_object.send(@temporal_list_name).last
  temporal.deleted_at = @context
  temporal.send(@name)
end

#push(*obj) ⇒ Object



385
386
387
388
389
# File 'lib/dm-is-temporal/is/temporal.rb', line 385

def push(*obj)
  obj.each do |o|
    self.<< o
  end
end

#rehject!Object



391
392
393
# File 'lib/dm-is-temporal/is/temporal.rb', line 391

def rehject!
  raise "Unsupported method"
end

#replace(other_array = nil) ⇒ Object



371
372
373
# File 'lib/dm-is-temporal/is/temporal.rb', line 371

def replace(other_array=nil)
  raise "Unsupported method"
end

#reverse!Object



395
396
397
# File 'lib/dm-is-temporal/is/temporal.rb', line 395

def reverse!
  raise "Unsupported method"
end

#shuffle!Object



399
400
401
# File 'lib/dm-is-temporal/is/temporal.rb', line 399

def shuffle!
  raise "Unsupported method"
end

#slice(*args) ⇒ Object



403
404
405
# File 'lib/dm-is-temporal/is/temporal.rb', line 403

def slice(*args)
  raise "Unsupported method"
end

#sort!Object



407
408
409
# File 'lib/dm-is-temporal/is/temporal.rb', line 407

def sort!
  raise "Unsupported method"
end

#uniq!Object



411
412
413
# File 'lib/dm-is-temporal/is/temporal.rb', line 411

def uniq!
  raise "Unsupported method"
end