Class: Boxen::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/boxen/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, flags) ⇒ Runner

Returns a new instance of Runner.



18
19
20
21
22
23
24
# File 'lib/boxen/runner.rb', line 18

def initialize(config, flags)
  @config   = config
  @flags    = flags
  @puppet   = Boxen::Puppeteer.new(@config)
  @checkout = Boxen::Checkout.new(@config)
  @hooks    = Boxen::Hook.all
end

Instance Attribute Details

#checkoutObject (readonly)

Returns the value of attribute checkout.



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

def checkout
  @checkout
end

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/boxen/runner.rb', line 12

def config
  @config
end

#flagsObject (readonly)

Returns the value of attribute flags.



13
14
15
# File 'lib/boxen/runner.rb', line 13

def flags
  @flags
end

#hooksObject (readonly)

Returns the value of attribute hooks.



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

def hooks
  @hooks
end

#puppetObject (readonly)

Returns the value of attribute puppet.



14
15
16
# File 'lib/boxen/runner.rb', line 14

def puppet
  @puppet
end

Instance Method Details

#processObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/boxen/runner.rb', line 26

def process
  # --env prints out the current BOXEN_ env vars.

  exec "env | grep ^BOXEN_ | sort" if flags.env?

  process_flags

  process_args

  # Actually run Puppet and return its result

  puppet.run
end

#process_argsObject



110
111
112
113
114
115
116
# File 'lib/boxen/runner.rb', line 110

def process_args
  projects = flags.args.join(',')
  File.open("#{config.repodir}/.projects", "w+") do |f|
    f.truncate 0
    f.write projects
  end
end

#process_flagsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/boxen/runner.rb', line 50

def process_flags

  # --projects prints a list of available projects and exits.

  if flags.projects?
    puts "You can install any of these projects with `#{$0} <project-name>`:\n"

    config.projects.each do |project|
      puts "  #{project.name}"
    end

    exit
  end

  # --disable-services stops all services

  if flags.disable_services?
    Boxen::Service.list.each do |service|
      puts "Disabling #{service}..."
      service.disable
    end

    exit
  end

  # --enable-services starts all services

  if flags.enable_services?
    Boxen::Service.list.each do |service|
      puts "Enabling #{service}..."
      service.enable
    end

    exit
  end

  # --list-services lists all services

  if flags.list_services?
    Boxen::Service.list.each do |service|
      puts service
    end

    exit
  end

  # --restart-services restarts all services

  if flags.restart_services?
    Boxen::Service.list.each do |service|
      puts "Restarting #{service}..."
      service.disable
      service.enable
    end

    exit
  end

end

#report(result) ⇒ Object



44
45
46
47
48
# File 'lib/boxen/runner.rb', line 44

def report(result)
  hooks.each { |hook| hook.new(config, checkout, puppet, result).run }

  result
end

#runObject



40
41
42
# File 'lib/boxen/runner.rb', line 40

def run
  report(process)
end