class Object

Constants

SCHEDULER

Public Instance Methods

authenticated?(token) click to toggle source
# File lib/dashing/app.rb, line 32
def authenticated?(token)
  return true unless settings.auth_token
  token && Rack::Utils.secure_compare(settings.auth_token, token)
end
development?() click to toggle source
# File lib/dashing/app.rb, line 14
def development?
  ENV['RACK_ENV'] == 'development'
end
first_dashboard() click to toggle source
# File lib/dashing/app.rb, line 169
def first_dashboard
  files = Dir[File.join(settings.views, '*')].collect { |f| File.basename(f, '.*') }
  files -= ['layout']
  files.sort.first
end
format_event(body, name=nil) click to toggle source
# File lib/dashing/app.rb, line 163
def format_event(body, name=nil)
  str = ""
  str << "event: #{name}\n" if name
  str << "data: #{body}\n\n"
end
h(text) click to toggle source
# File lib/dashing/app.rb, line 28
def h(text)
  Rack::Utils.escape_html(text)
end
production?() click to toggle source
# File lib/dashing/app.rb, line 18
def production?
  ENV['RACK_ENV'] == 'production'
end
protected!() click to toggle source
# File lib/dashing/app.rb, line 24
def protected!
  # override with auth logic
end
require_glob(relative_glob) click to toggle source
# File lib/dashing/app.rb, line 175
def require_glob(relative_glob)
  Dir[File.join(settings.root, relative_glob)].each do |file|
    require file
  end
end
send_event(id, body, target=nil) click to toggle source
# File lib/dashing/app.rb, line 149
def send_event(id, body, target=nil)
  body[:id] = id
  body[:updatedAt] ||= (Time.now.to_f * 1000.0).to_i
  event = format_event(body.to_json, target)
  Sinatra::Application.settings.history[id] = event unless target == 'dashboards'
  Sinatra::Application.settings.connections.each { |out, ids|
    begin
      out << event if target == 'dashboards' || ids.nil? || ids.include?(id)
    rescue IOError => e # if the socket is closed an IOError is thrown
      Sinatra::Application.settings.connections.delete(out)
    end
  }
end
stop_with_connection_closing() click to toggle source
# File lib/dashing/app.rb, line 140
def stop_with_connection_closing
  Sinatra::Application.settings.connections.dup.each_key(&:close)
  stop_without_connection_closing
end