Module: Rib::History
- Extended by:
- Plugin
- Defined in:
- lib/rib/core/history.rb
Instance Attribute Summary
Attributes included from Plugin
Instance Method Summary collapse
- #after_loop ⇒ Object
-
#before_loop ⇒ Object
————— Rib API —————.
- #get_input ⇒ Object
-
#history ⇒ Object
The history data.
-
#read_history ⇒ Object
Read config into #history, handled in history_file plugin.
-
#write_history ⇒ Object
Write #history into config, handled in history_file plugin.
Methods included from Plugin
const_missing, disable, disabled?, enable, enabled?, extended
Instance Method Details
#after_loop ⇒ Object
21 22 23 24 25 26 |
# File 'lib/rib/core/history.rb', line 21 def after_loop return super if History.disabled? write_history Rib.say("History wrote to: #{history_file_path}") if $VERBOSE super end |
#before_loop ⇒ Object
————— Rib API —————
11 12 13 14 15 16 17 18 19 |
# File 'lib/rib/core/history.rb', line 11 def before_loop return super if History.disabled? history_file history_size FileUtils.mkdir_p(File.dirname(history_file_path)) read_history Rib.say("History read from: #{history_file_path}") if $VERBOSE super end |
#get_input ⇒ Object
28 29 30 31 |
# File 'lib/rib/core/history.rb', line 28 def get_input return super if History.disabled? (history << super).last end |
#history ⇒ Object
The history data
36 |
# File 'lib/rib/core/history.rb', line 36 def history; config[:history] ||= []; end |
#read_history ⇒ Object
Read config into #history, handled in history_file plugin
39 40 41 42 43 |
# File 'lib/rib/core/history.rb', line 39 def read_history return super if History.disabled? File.exist?(history_file_path) && history.empty? && File.readlines(history_file_path).each{ |e| history << e.chomp } end |
#write_history ⇒ Object
Write #history into config, handled in history_file plugin
46 47 48 49 50 |
# File 'lib/rib/core/history.rb', line 46 def write_history return super if History.disabled? history_text = "#{history.to_a.last(history_size).join("\n")}\n" File.write(history_file_path, history_text) end |