Class: Vigil

Inherits:
Object
  • Object
show all
Defined in:
lib/vigil.rb,
lib/vigil/os.rb,
lib/vigil/git.rb,
lib/vigil/project.rb,
lib/vigil/vagrant.rb,
lib/vigil/version.rb,
lib/vigil/pipeline.rb,
lib/vigil/revision.rb,
lib/vigil/vmbuilder.rb,
lib/vigil/test_pipeline.rb,
lib/vigil/revision_repository.rb

Defined Under Namespace

Modules: Git, Vagrant Classes: OS, Pipeline, Project, Revision, RevisionRepository, TestPipeline, VMBuilder

Constant Summary collapse

VERSION =
"0.1"

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Vigil

Returns a new instance of Vigil.



20
21
22
23
24
25
26
# File 'lib/vigil.rb', line 20

def initialize(args)
  @x = args[:os] || Vigil::OS.new
  Vigil.os = @x
  Vigil.run_dir = File.expand_path 'run'
  Vigil.plugman = Plugman.new(plugins: [])
  _initialize_projects(args[:projects] || [])
end

Class Attribute Details

.osObject

Returns the value of attribute os.



15
16
17
# File 'lib/vigil.rb', line 15

def os
  @os
end

.plugmanObject

Returns the value of attribute plugman.



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

def plugman
  @plugman
end

.run_dirObject

Returns the value of attribute run_dir.



16
17
18
# File 'lib/vigil.rb', line 16

def run_dir
  @run_dir
end

Instance Method Details

#_initialize_projects(projects) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/vigil.rb', line 28

def _initialize_projects(projects)
  @projects = projects.map do |p| 
    Project.new(
      name:    p[:name],
      git_url: p[:git][:url],
      branch:  p[:git][:branch]
    )
  end
end

#_less_often_than_every(n_seconds) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/vigil.rb', line 51

def _less_often_than_every(n_seconds)
  start = Time.now
  yield
  _end = Time.now
  if _end - start < n_seconds
    n = n_seconds - (_end - start)
    puts "Sleeping for #{n} sec."
    sleep n
  end
end

#runObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vigil.rb', line 38

def run
  @x.mkdir_p Vigil.run_dir
  loop do
    _less_often_than_every(60) do
      puts "### Vigil loop"
      @projects.each do |p|
        puts "## #{p.inspect}"
        p.run_pipeline
      end
    end
  end
end