Class: NewPage::HistoryHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/new_page/input_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#completionObject (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

Returns:

  • (Boolean)


28
29
30
# File 'lib/new_page/input_hash.rb', line 28

def include?
  @completions.include?(key)
end

#read_historyObject



32
33
34
# File 'lib/new_page/input_hash.rb', line 32

def read_history
  YAML.load_file(@history_file)
end

#write_historyObject



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