Class: NewPage::HistoryHandler
- Inherits:
-
Object
- Object
- NewPage::HistoryHandler
- Defined in:
- lib/new_page/input_hash.rb
Instance Attribute Summary collapse
-
#completion ⇒ Object
readonly
Returns the value of attribute completion.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #include? ⇒ Boolean
-
#initialize(history_file: Pathname.new(".history.yaml")) ⇒ HistoryHandler
constructor
A new instance of HistoryHandler.
- #read_history ⇒ Object
- #write_history ⇒ Object
Constructor Details
#initialize(history_file: Pathname.new(".history.yaml")) ⇒ HistoryHandler
Returns a new instance of HistoryHandler.
10 11 12 13 14 15 16 17 18 |
# File 'lib/new_page/input_hash.rb', line 10 def initialize(history_file: Pathname.new(".history.yaml"), **) if (history_file.is_a? Pathname) @history_file = history_file else @history_file = Pathname.new(history_file) end @completion = read_history(history_file) end |
Instance Attribute Details
#completion ⇒ Object (readonly)
Returns the value of attribute completion.
8 9 10 |
# File 'lib/new_page/input_hash.rb', line 8 def completion @completion end |
Instance Method Details
#[](key) ⇒ Object
20 21 22 |
# File 'lib/new_page/input_hash.rb', line 20 def [](key) @completion[key] end |
#[]=(key, value) ⇒ Object
24 25 26 |
# File 'lib/new_page/input_hash.rb', line 24 def []=(key, value) @completion[key] = value end |
#include? ⇒ Boolean
28 29 30 |
# File 'lib/new_page/input_hash.rb', line 28 def include? @completions.include?(key) end |
#read_history ⇒ Object
32 33 34 |
# File 'lib/new_page/input_hash.rb', line 32 def read_history YAML.load_file(@history_file) end |
#write_history ⇒ Object
36 37 38 |
# File 'lib/new_page/input_hash.rb', line 36 def write_history File.open { |file| file.write { |out| out << @completion.to_yaml } } end |