Module: DashingContrib::History

Extended by:
History
Included in:
History
Defined in:
lib/dashing-contrib/history.rb

Instance Method Summary collapse

Instance Method Details

#append_to(target_array = [], source_obj = {}, max_size = 1000) ⇒ Object



35
36
37
38
# File 'lib/dashing-contrib/history.rb', line 35

def append_to(target_array=[], source_obj = {}, max_size=1000)
  target_array.shift while target_array.size >= max_size
  target_array << source_obj
end

#historyObject



8
9
10
# File 'lib/dashing-contrib/history.rb', line 8

def history
  Sinatra::Application.settings.history
end

#history_fileObject



12
13
14
# File 'lib/dashing-contrib/history.rb', line 12

def history_file
  Sinatra::Application.settings.history_file
end

#json_event(event_name, default = nil) ⇒ Object



29
30
31
32
33
# File 'lib/dashing-contrib/history.rb', line 29

def json_event(event_name, default = nil)
  MultiJson.load(raw_event(event_name), { symbolize_keys: true })
rescue
  default
end

#raw_event(event_name) ⇒ Object



22
23
24
25
26
27
# File 'lib/dashing-contrib/history.rb', line 22

def raw_event(event_name)
  return nil if history[event_name].nil?
  history[event_name].gsub(/^data:/, '')
rescue
  nil
end

#saveObject



16
17
18
19
20
# File 'lib/dashing-contrib/history.rb', line 16

def save
  File.open(history_file, 'w') do |f|
    f.puts history.to_yaml
  end
end