Class: DeployPin::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_pin/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Task

Returns a new instance of Task.



12
13
14
15
16
17
18
# File 'lib/deploy_pin/task.rb', line 12

def initialize(file)
  @file = file
  @uuid = nil
  @group = nil
  @title = ''
  @script = ''
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



6
7
8
# File 'lib/deploy_pin/task.rb', line 6

def file
  @file
end

#groupObject (readonly)

Returns the value of attribute group.



6
7
8
# File 'lib/deploy_pin/task.rb', line 6

def group
  @group
end

#scriptObject (readonly)

Returns the value of attribute script.



6
7
8
# File 'lib/deploy_pin/task.rb', line 6

def script
  @script
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/deploy_pin/task.rb', line 6

def title
  @title
end

#uuidObject (readonly)

Returns the value of attribute uuid.



6
7
8
# File 'lib/deploy_pin/task.rb', line 6

def uuid
  @uuid
end

Instance Method Details

#detailsObject



48
49
50
51
52
53
54
# File 'lib/deploy_pin/task.rb', line 48

def details
  {
    uuid: uuid,
    group: group,
    title: title
  }
end

#done?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/deploy_pin/task.rb', line 30

def done?
  DeployPin::Record.where(uuid: uuid).exists?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/deploy_pin/task.rb', line 56

def eql?(other)
  # same script & different uuid
  script == other.script && uuid != other.uuid
end

#markObject



25
26
27
28
# File 'lib/deploy_pin/task.rb', line 25

def mark
  # store record in the DB
  DeployPin::Record.create(uuid: uuid)
end

#parse_fileObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/deploy_pin/task.rb', line 34

def parse_file
  File.foreach(file) do |line|
    case line.strip
    when /\A# (\d+):(\w+)/
      @uuid = Regexp.last_match(1)
      @group = Regexp.last_match(2)
    when /\A# task_title:(.+)/
      @title = Regexp.last_match(1).strip
    when /\A[^#].*/
      @script += line
    end
  end
end

#runObject



20
21
22
23
# File 'lib/deploy_pin/task.rb', line 20

def run
  # eval script
  eval(script)
end