Top Level Namespace

Constant Summary collapse

SCHEDULER =
Rufus::Scheduler.start_new

Instance Method Summary collapse

Instance Method Details

#development? ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/dashing.rb', line 115

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

#first_dashboard ⇒ Object



143
144
145
146
147
# File 'lib/dashing.rb', line 143

def first_dashboard
  files = Dir[File.join(settings.views, '*')].collect { |f| File.basename(f, '.*') }
  files -= ['layout']
  files.first
end

#format_event(body, name = nil) ⇒ Object



131
132
133
134
135
# File 'lib/dashing.rb', line 131

def format_event(body, name=nil)
  str = ""
  str << "event: #{name}\n" if name
  str << "data: #{body}\n\n"
end

#latest_events ⇒ Object



137
138
139
140
141
# File 'lib/dashing.rb', line 137

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

#production? ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/dashing.rb', line 119

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

#send_event(id, body, target = nil) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/dashing.rb', line 123

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

#tilt_html_engines ⇒ Object



149
150
151
152
153
154
# File 'lib/dashing.rb', line 149

def tilt_html_engines
  Tilt.mappings.select do |_, engines|
    default_mime_type = engines.first.default_mime_type
    default_mime_type.nil? || default_mime_type == 'text/html'
  end
end