Class: DBViewCTI::Model::CollectionDelegator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/db_view_cti/model/collection_delegator.rb

Instance Method Summary collapse

Constructor Details

#initialize(object, target_class_name) ⇒ CollectionDelegator

Returns a new instance of CollectionDelegator.



7
8
9
10
# File 'lib/db_view_cti/model/collection_delegator.rb', line 7

def initialize(object, target_class_name)
  super(object)
  @target_class_name = target_class_name
end

Instance Method Details

#<<(object, *args, &block) ⇒ Object



12
13
14
# File 'lib/db_view_cti/model/collection_delegator.rb', line 12

def <<(object, *args, &block)
  __getobj__.send('<<', object.try(:convert_to, @target_class_name), *args, &block)
end

#[]=(*args, &block) ⇒ Object



16
17
18
19
# File 'lib/db_view_cti/model/collection_delegator.rb', line 16

def []=(*args, &block)
  object = args.last.convert_to(@target_class_name)
  __getobj__.send('[]=', *(args[0..-2]), object, &block)
end

#delete(*args, &block) ⇒ Object



21
22
23
24
25
26
# File 'lib/db_view_cti/model/collection_delegator.rb', line 21

def delete(*args, &block)
  objects = args.map do |obj|
    obj.respond_to?(:convert_to) ? obj.convert_to(@target_class_name) : obj
  end
  __getobj__.send('delete', *objects, &block)
end

#destroy(*args, &block) ⇒ Object



28
29
30
31
32
33
# File 'lib/db_view_cti/model/collection_delegator.rb', line 28

def destroy(*args, &block)
  objects = args.map do |obj|
    obj.respond_to?(:convert_to) ? obj.convert_to(@target_class_name) : obj
  end
  __getobj__.send('delete', *objects, &block)
end