Class: Fir::History

Inherits:
Object
  • Object
show all
Defined in:
lib/fir/history.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHistory

Returns a new instance of History.



10
11
12
# File 'lib/fir/history.rb', line 10

def initialize
  @active_selection = 0
end

Instance Attribute Details

#active_selectionObject (readonly)

Returns the value of attribute active_selection.



8
9
10
# File 'lib/fir/history.rb', line 8

def active_selection
  @active_selection
end

Class Method Details

.add_line_to_history_file(line) ⇒ Object



47
48
49
50
# File 'lib/fir/history.rb', line 47

def add_line_to_history_file(line)
  return unless history_file
  File.open(history_file, 'a') { |f| f.puts(line) }
end

.historyObject



39
40
41
42
43
44
45
# File 'lib/fir/history.rb', line 39

def history
  if history_file && File.exist?(history_file)
    IO.readlines(history_file).map(&:chomp)
  else
    []
  end
end

.history_fileObject



34
35
36
37
# File 'lib/fir/history.rb', line 34

def history_file
  @history_file ||= Fir.config[:history] &&
                    File.expand_path(Fir.config[:history])
end

Instance Method Details

#downObject



22
23
24
# File 'lib/fir/history.rb', line 22

def down
  @active_selection -= 1 if active_selection.positive?
end

#resetObject



14
15
16
# File 'lib/fir/history.rb', line 14

def reset
  @active_selection = 0
end

#suggestion(line) ⇒ Object



26
27
28
29
30
31
# File 'lib/fir/history.rb', line 26

def suggestion(line)
  Fir::Suggestion.new(
    line,
    Fir::History.history
  ).generate(active_selection)
end

#upObject



18
19
20
# File 'lib/fir/history.rb', line 18

def up
  @active_selection += 1
end