Class: Nutella::RunList

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/config/runlist.rb

Constant Summary collapse

RUN_LIST_FILE =
File.dirname(__FILE__)+"/../../runlist.json"

Instance Method Summary collapse

Instance Method Details

#add?(runid) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
# File 'lib/config/runlist.rb', line 15

def add?(runid)
  begin
    result = JSON.parse(IO.read(RUN_LIST_FILE)).to_set.add? runid
  rescue
    # No file, create one
    result = [runid].to_set
  end
  writeFile(result)
end

#delete?(runid) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/config/runlist.rb', line 25

def delete?(runid)
  begin
    result = JSON.parse(IO.read(RUN_LIST_FILE)).to_set.delete? runid
  rescue
    removeRunListFile
    result = nil # List is empty, so nil
  end
  writeFile(result)
end

#empty?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# File 'lib/config/runlist.rb', line 43

def empty?
  begin
    return JSON.parse(IO.read(RUN_LIST_FILE)).empty?
  rescue
    true # There is no file so list is empty
  end
end

#extractRunId(run) ⇒ Object



69
70
71
# File 'lib/config/runlist.rb', line 69

def extractRunId(run)
  run.to_s.empty? ? Nutella.currentProject.config["name"] : Nutella.currentProject.config["name"] + "_" + run
end

#include?(runid) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'lib/config/runlist.rb', line 35

def include?(runid)
  begin
    return JSON.parse(IO.read(RUN_LIST_FILE)).include? runid
  rescue
    false # There is no file so it doens't include runid
  end
end

#lengthObject



65
66
67
# File 'lib/config/runlist.rb', line 65

def length
  to_a.length
end

#to_a(projectName = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/config/runlist.rb', line 51

def to_a(projectName=nil)
  begin
    list = JSON.parse(IO.read(RUN_LIST_FILE))
    # filter by project
    if projectName == nil
      return list
    else
      return list.select { |run| run.start_with?(projectName) }
    end
  rescue
    Array.new # There is no file or something went wrong
  end
end