Class: FireAndForget::Command::CommandBase

Inherits:
Object
  • Object
show all
Defined in:
lib/fire_and_forget/command.rb

Direct Known Subclasses

Fire, GetPid, GetStatus, Kill, SetPid, SetStatus

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, params = {}) ⇒ CommandBase

Returns a new instance of CommandBase.



23
24
25
# File 'lib/fire_and_forget/command.rb', line 23

def initialize(task, params={})
  @task, @params = task, merge_params(task.params, params)
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



21
22
23
# File 'lib/fire_and_forget/command.rb', line 21

def cmd
  @cmd
end

#paramsObject (readonly)

Returns the value of attribute params.



21
22
23
# File 'lib/fire_and_forget/command.rb', line 21

def params
  @params
end

#tagObject (readonly)

Returns the value of attribute tag.



21
22
23
# File 'lib/fire_and_forget/command.rb', line 21

def tag
  @tag
end

#taskObject (readonly)

Returns the value of attribute task.



21
22
23
# File 'lib/fire_and_forget/command.rb', line 21

def task
  @task
end

Instance Method Details

#debugObject



46
47
48
# File 'lib/fire_and_forget/command.rb', line 46

def debug()
  "#{self.class.name.split("::").last} :#{@task_name}\n"
end

#dumpObject



27
28
29
# File 'lib/fire_and_forget/command.rb', line 27

def dump
  Marshal.dump(self)
end

#merge_params(task_params, call_params) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/fire_and_forget/command.rb', line 36

def merge_params(task_params, call_params)
  params = task_params.to_a.inject({}) do |hash, (key, value)|
    hash[key.to_s] = value; hash
  end
  call_params.each do |key, value|
    params[key.to_s] = value
  end if call_params
  params
end

#runObject



31
32
33
# File 'lib/fire_and_forget/command.rb', line 31

def run
  # overridden in subclasses
end