Class: PDK::AnswerFile
- Inherits:
-
Object
- Object
- PDK::AnswerFile
- 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.
Constructor Details
#initialize(answer_file_path = nil) ⇒ AnswerFile
Initialises the AnswerFile object, which stores the responses to certain interactive questions.
32 33 34 35 |
# File 'lib/pdk/answer_file.rb', line 32 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.
42 43 44 |
# File 'lib/pdk/answer_file.rb', line 42 def [](question) answers[question] end |
#update!(new_answers = {}) ⇒ Object
Update the stored answers in memory and then save them to disk.
54 55 56 57 58 59 60 61 62 |
# File 'lib/pdk/answer_file.rb', line 54 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 |