Top Level Namespace

Constant Summary collapse

SCHEDULER =
Rufus::Scheduler.start_new

Instance Method Summary collapse

Instance Method Details

#development? ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/dashing.rb', line 83

def development?
  ENV['RACK_ENV'] == 'development'
end

#first_dashboard ⇒ Object



109
110
111
112
113
# File 'lib/dashing.rb', line 109

def first_dashboard
  files = Dir[File.join(settings.views, '*.erb')].collect { |f| f.match(/(\w*).erb/)[1] }
  files -= ['layout']
  files.first
end

#format_event(body) ⇒ Object



99
100
101
# File 'lib/dashing.rb', line 99

def format_event(body)
  "data: #{body}\n\n"
end

#latest_events ⇒ Object



103
104
105
106
107
# File 'lib/dashing.rb', line 103

def latest_events
  settings.history.inject("") do |str, (id, body)|
    str << body
  end
end

#production? ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/dashing.rb', line 87

def production?
  ENV['RACK_ENV'] == 'production'
end

#send_event(id, body) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/dashing.rb', line 91

def send_event(id, body)
  body[:id] = id
  body[:updatedAt] ||= Time.now.to_i
  event = format_event(body.to_json)
  Sinatra::Application.settings.history[id] = event
  Sinatra::Application.settings.connections.each { |out| out << event }
end