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.



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

def initialize(config, flags)
  @config = config
  @flags  = flags
  @puppet   = Boxen::Puppeteer.new(@config)
  @checkout = Boxen::Checkout.new(@config)
  @reporter = Boxen::Reporter.new(@config, @checkout, @puppet)
end

Instance Attribute Details

#checkoutObject (readonly)

Returns the value of attribute checkout.



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

def checkout
  @checkout
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#flagsObject (readonly)

Returns the value of attribute flags.



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

def flags
  @flags
end

#puppetObject (readonly)

Returns the value of attribute puppet.



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

def puppet
  @puppet
end

#reporterObject (readonly)

Returns the value of attribute reporter.



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

def reporter
  @reporter
end

Instance Method Details

#issues?Boolean

Should the result of this run have any effect on GitHub issues?

Returns:

  • (Boolean)


110
111
112
# File 'lib/boxen/runner.rb', line 110

def issues?
  !config.stealth? && !config.pretend? && checkout.master?
end

#processObject



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

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



103
104
105
106
# File 'lib/boxen/runner.rb', line 103

def process_args
  projects = flags.args.join(',')
  Facter.add('cli_boxen_projects') { setcode { projects } }
end

#process_flagsObject



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
# File 'lib/boxen/runner.rb', line 56

def process_flags

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

  if flags.projects?
    config.projects.each do |project|
      prefix = project.installed? ? "*" : " "
      puts "#{prefix} #{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

end

#report(result) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/boxen/runner.rb', line 43

def report(result)
  return result unless issues?

  if result.success?
    reporter.close_failures
  else
    warn "Sorry! Creating an issue on #{config.reponame}."
    reporter.record_failure
  end

  result
end

#runObject



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

def run
  report(process)
end