Module: Twterm::History::Savable
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
Instance Method Details
#add(item) ⇒ Object
21 22 23 24 |
# File 'lib/twterm/history/savable.rb', line 21 def add(item) @history << item unless @history.include?(item) @history = history.take(1000) end |
#initialize ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/twterm/history/savable.rb', line 6 def initialize unless File.exist?(file) @history = [] return end begin @history = YAML.load(File.read(file)) || [] rescue @history = [] end Scheduler.new(300) { save } end |
#save ⇒ Object
26 27 28 |
# File 'lib/twterm/history/savable.rb', line 26 def save File.open(file, 'w', 0600) { |f| f.write(history.to_yaml) } end |