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.
34 35 36 37 |
# File 'lib/pdk/answer_file.rb', line 34 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.
22 23 24 |
# File 'lib/pdk/answer_file.rb', line 22 def answer_file_path @answer_file_path end |
#answers ⇒ Object (readonly)
Returns the value of attribute answers.
21 22 23 |
# File 'lib/pdk/answer_file.rb', line 21 def answers @answers end |
Instance Method Details
#[](question) ⇒ Object
Retrieve the stored answer to a question.
44 45 46 |
# File 'lib/pdk/answer_file.rb', line 44 def [](question) answers[question] end |
#update!(new_answers = {}) ⇒ Object
Update the stored answers in memory and then save them to disk.
56 57 58 59 60 61 62 63 64 |
# File 'lib/pdk/answer_file.rb', line 56 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 |