Class: Testament::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/testament/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ Project

Returns a new instance of Project.



9
10
11
12
13
14
15
# File 'lib/testament/project.rb', line 9

def initialize(arguments)
  @database = Database.new arguments.fetch('database')
  @name = arguments.fetch('project')
  @user = arguments.fetch('user')
  @version = arguments.fetch('version')
  @default_category = arguments.fetch('default_category')
end

Instance Attribute Details

#default_categoryObject (readonly)

Returns the value of attribute default_category.



7
8
9
# File 'lib/testament/project.rb', line 7

def default_category
  @default_category
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/testament/project.rb', line 7

def name
  @name
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/testament/project.rb', line 7

def user
  @user
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/testament/project.rb', line 7

def version
  @version
end

Class Method Details

.loadObject



48
49
50
51
52
# File 'lib/testament/project.rb', line 48

def self.load
  config_path = ".testament/config.yml"
  config = YAML.load(ERB.new(File.read(config_path)).result)
  new config
end

Instance Method Details

#logObject



39
40
41
# File 'lib/testament/project.rb', line 39

def log
  database.db[:executions].order(:start_time).all
end

#record(command_words) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/testament/project.rb', line 17

def record(command_words)
  start_time = Time.now
  system *command_words
  end_time = Time.now
  elapsed_milliseconds = ((end_time - start_time) * 1000).round
  command = command_words.join(' ')

  memento = {
    project: name,
    command: command,
    start_time: start_time,
    elapsed_milliseconds: elapsed_milliseconds,
    exit_status: $?.exitstatus,
    user: user,
    version: version,
    category: default_category
  }

  database.record memento
  memento
end

#report(name) ⇒ Object



43
44
45
46
# File 'lib/testament/project.rb', line 43

def report(name)
  require 'testament/report'
  Testament::Report.find(name).new database.db
end