Top Level Namespace

Constant Summary collapse

SCHEDULER =
Rufus::Scheduler.start_new

Instance Method Summary collapse

Instance Method Details

#development?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/dashing.rb', line 74

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

#first_dashboardObject



100
101
102
103
104
# File 'lib/dashing.rb', line 100

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



90
91
92
# File 'lib/dashing.rb', line 90

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

#latest_eventsObject



94
95
96
97
98
# File 'lib/dashing.rb', line 94

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

#production?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/dashing.rb', line 78

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

#send_event(id, body) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/dashing.rb', line 82

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