Sha256: 35725393f03b11dfb36ca6f4c382fb7b9aa8874ded5789c9fef592a31b562640

Contents?: true

Size: 824 Bytes

Versions: 23

Compression:

Stored size: 824 Bytes

Contents

require 'yaml'
require 'multi_json'

module DashingContrib
  module History
    extend self

    def history
      Sinatra::Application.settings.history
    end

    def history_file
      Sinatra::Application.settings.history_file
    end

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

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

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

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

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
dashing-contrib-0.2.9 lib/dashing-contrib/history.rb
dashing-contrib-0.2.8 lib/dashing-contrib/history.rb
dashing-contrib-0.2.7 lib/dashing-contrib/history.rb
dashing-contrib-0.2.6 lib/dashing-contrib/history.rb
dashing-contrib-0.2.5 lib/dashing-contrib/history.rb
dashing-contrib-0.2.4 lib/dashing-contrib/history.rb
dashing-contrib-0.2.3 lib/dashing-contrib/history.rb
dashing-contrib-0.2.2 lib/dashing-contrib/history.rb
dashing-contrib-0.2.1 lib/dashing-contrib/history.rb
dashing-contrib-0.2.0 lib/dashing-contrib/history.rb
dashing-contrib-0.1.14 lib/dashing-contrib/history.rb
dashing-contrib-0.1.12 lib/dashing-contrib/history.rb
dashing-contrib-0.1.11 lib/dashing-contrib/history.rb
dashing-contrib-0.1.10 lib/dashing-contrib/history.rb
dashing-contrib-0.1.9 lib/dashing-contrib/history.rb
dashing-contrib-0.1.8 lib/dashing-contrib/history.rb
dashing-contrib-0.1.7 lib/dashing-contrib/history.rb
dashing-contrib-0.1.6 lib/dashing-contrib/history.rb
dashing-contrib-0.1.5 lib/dashing-contrib/history.rb
dashing-contrib-0.1.4 lib/dashing-contrib/history.rb