class Ruboty::Brains::LocalYAML
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/ruboty/brains/local_yaml.rb, line 9 def initialize super @thread = Thread.new { sync } @thread.abort_on_exception = true end
Public Instance Methods
data()
click to toggle source
# File lib/ruboty/brains/local_yaml.rb, line 15 def data @data ||= pull || {} end
Private Instance Methods
file_path()
click to toggle source
# File lib/ruboty/brains/local_yaml.rb, line 44 def file_path (ENV['LOCAL_YAML_PATH'] || './ruboty.yml') end
interval()
click to toggle source
# File lib/ruboty/brains/local_yaml.rb, line 48 def interval (ENV['LOCAL_YAML_SAVE_INTERVAL'] || 5).to_i end
pull()
click to toggle source
# File lib/ruboty/brains/local_yaml.rb, line 28 def pull return nil unless File.exist?(file_path) YAML.load File.read(file_path) end
push()
click to toggle source
# File lib/ruboty/brains/local_yaml.rb, line 21 def push yaml = data.to_yaml return if yaml == @old_yaml File.open(file_path, 'w') { |f| f.write yaml } @old_yaml = yaml end
sync()
click to toggle source
# File lib/ruboty/brains/local_yaml.rb, line 33 def sync loop do wait push end end
wait()
click to toggle source
# File lib/ruboty/brains/local_yaml.rb, line 40 def wait sleep(interval) end