Class: Beaker::Answers
- Inherits:
-
Object
- Object
- Beaker::Answers
- Defined in:
- lib/beaker/answers.rb
Overview
This class provides methods for generating PE answer file information.
Class Method Summary collapse
-
.create(version, hosts, options) ⇒ Hash
When given a Puppet Enterprise version, a list of hosts and other qualifying data this method will return the appropriate object that can be used to generate answer file data.
Instance Method Summary collapse
-
#answer_for(options, q, default = nil) ⇒ String
The answer value for a provided question.
-
#answer_string(host) ⇒ String
This converts a data hash provided by answers, and returns a Puppet Enterprise compatible answer file ready for use.
-
#answers ⇒ Hash
Access the answers hash for this version, host and option information.
-
#generate_answers ⇒ Object
Generate the answers hash based upon version, host and option information.
-
#initialize(version, hosts, options) ⇒ Hash
constructor
When given a Puppet Enterprise version, a list of hosts and other qualifying data this method will return a hash (keyed from the hosts) of default Puppet Enterprise answer file data hashes.
Constructor Details
#initialize(version, hosts, options) ⇒ Hash
When given a Puppet Enterprise version, a list of hosts and other qualifying data this method will return a hash (keyed from the hosts) of default Puppet Enterprise answer file data hashes.
60 61 62 63 64 |
# File 'lib/beaker/answers.rb', line 60 def initialize(version, hosts, ) @version = version @hosts = hosts @options = end |
Class Method Details
.create(version, hosts, options) ⇒ Hash
When given a Puppet Enterprise version, a list of hosts and other qualifying data this method will return the appropriate object that can be used to generate answer file data.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/beaker/answers.rb', line 16 def self.create version, hosts, case version when /\A4\.0/ return Version34.new(version, hosts, ) when /\A3\.99/ return Version40.new(version, hosts, ) when /\A3\.7/ return Version34.new(version, hosts, ) when /\A3\.4/ return Version34.new(version, hosts, ) when /\A3\.[2-3]/ return Version32.new(version, hosts, ) when /\A3\.1/ return Version30.new(version, hosts, ) when /\A3\.0/ return Version30.new(version, hosts, ) when /\A2\.8/ return Version28.new(version, hosts, ) when /\A2\.0/ return Version20.new(version, hosts, ) else raise NotImplementedError, "Don't know how to generate answers for #{version}" end end |
Instance Method Details
#answer_for(options, q, default = nil) ⇒ String
The answer value for a provided question. Use the user answer when available, otherwise return the default
46 47 48 |
# File 'lib/beaker/answers.rb', line 46 def answer_for(, q, default = nil) [:answers][q] ? [:answers][q] : default end |
#answer_string(host) ⇒ String
This converts a data hash provided by answers, and returns a Puppet Enterprise compatible answer file ready for use.
end
89 90 91 |
# File 'lib/beaker/answers.rb', line 89 def answer_string(host) answers[host.name].map { |k,v| "#{k}=#{v}" }.join("\n") end |
#answers ⇒ Hash
Access the answers hash for this version, host and option information. If the answers have not yet been calculated, generate them.
74 75 76 |
# File 'lib/beaker/answers.rb', line 74 def answers @answers ||= generate_answers end |
#generate_answers ⇒ Object
Generate the answers hash based upon version, host and option information
67 68 69 |
# File 'lib/beaker/answers.rb', line 67 def generate_answers raise "This should be handled by subclasses!" end |