Class: Undestroy::Transfer

Inherits:
Object
  • Object
show all
Defined in:
lib/undestroy/transfer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Transfer

Returns a new instance of Transfer.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
# File 'lib/undestroy/transfer.rb', line 5

def initialize(args={})
  raise ArgumentError, ":klass option required" unless args[:klass]
  args[:fields] ||= {}

  self.target = args[:target] || args[:klass].new

  # Set instance values directly to avoid AR's filtering of protected fields
  args[:fields].each do |field, value|
    self.target[field] = value
  end
end

Instance Attribute Details

#targetObject

Returns the value of attribute target.



3
4
5
# File 'lib/undestroy/transfer.rb', line 3

def target
  @target
end

Instance Method Details

#runObject



17
18
19
# File 'lib/undestroy/transfer.rb', line 17

def run
  self.target.save
end