Class: PDK::AnswerFile
- Inherits:
-
Object
- Object
- PDK::AnswerFile
- Includes:
- Util::Filesystem
- Defined in:
- lib/pdk/answer_file.rb
Instance Attribute Summary collapse
-
#answer_file_path ⇒ Object
readonly
Returns the value of attribute answer_file_path.
-
#answers ⇒ Object
readonly
Returns the value of attribute answers.
Instance Method Summary collapse
-
#[](question) ⇒ Object
Retrieve the stored answer to a question.
-
#initialize(answer_file_path = nil) ⇒ AnswerFile
constructor
Initialises the AnswerFile object, which stores the responses to certain interactive questions.
-
#update!(new_answers = {}) ⇒ Object
Update the stored answers in memory and then save them to disk.
Methods included from Util::Filesystem
directory?, exist?, expand_path, file?, fnmatch, glob, mkdir_p, read_file, readable?, rm, write_file
Constructor Details
#initialize(answer_file_path = nil) ⇒ AnswerFile
Initialises the AnswerFile object, which stores the responses to certain interactive questions.
19 20 21 22 |
# File 'lib/pdk/answer_file.rb', line 19 def initialize(answer_file_path = nil) @answer_file_path = answer_file_path || default_answer_file_path @answers = read_from_disk end |
Instance Attribute Details
#answer_file_path ⇒ Object (readonly)
Returns the value of attribute answer_file_path.
7 8 9 |
# File 'lib/pdk/answer_file.rb', line 7 def answer_file_path @answer_file_path end |
#answers ⇒ Object (readonly)
Returns the value of attribute answers.
6 7 8 |
# File 'lib/pdk/answer_file.rb', line 6 def answers @answers end |
Instance Method Details
#[](question) ⇒ Object
Retrieve the stored answer to a question.
29 30 31 |
# File 'lib/pdk/answer_file.rb', line 29 def [](question) answers[question] end |
#update!(new_answers = {}) ⇒ Object
Update the stored answers in memory and then save them to disk.
41 42 43 44 45 46 47 48 49 |
# File 'lib/pdk/answer_file.rb', line 41 def update!(new_answers = {}) unless new_answers.is_a?(Hash) raise PDK::CLI::FatalError, _('Answer file can be updated only with a Hash') end answers.merge!(new_answers) save_to_disk end |