Sha256: b6a9384137e7289d14394fb88d530a8693d01511943d4b1a06072e025cc4e395

Contents?: true

Size: 644 Bytes

Versions: 3

Compression:

Stored size: 644 Bytes

Contents

require 'yaml'
require 'multi_json'

module DashingContrib
  module History
    extend self

    def history
      Sinatra::Application.settings.history
    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

3 entries across 3 versions & 1 rubygems

Version Path
dashing-contrib-0.1.0 lib/dashing-contrib/history.rb
dashing-contrib-0.0.5 lib/dashing-contrib/history.rb
dashing-contrib-0.0.4 lib/dashing-contrib/history.rb