Top Level Namespace

Constant Summary collapse

SCHEDULER =
Rufus::Scheduler.start_new

Instance Method Summary collapse

Instance Method Details

#development?Boolean

if File.exists?(settings.history_file)

set history: YAML.load_file(settings.history_file)

else

set history: {}

end

Returns:

  • (Boolean)


23
24
25
# File 'lib/scheduler.rb', line 23

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

#first_dashboardObject



141
142
143
144
145
# File 'lib/dashing.rb', line 141

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) ⇒ Object



129
130
131
132
133
# File 'lib/dashing.rb', line 129

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

#latest_eventsObject



135
136
137
138
139
# File 'lib/dashing.rb', line 135

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

#production?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/dashing.rb', line 117

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

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



121
122
123
124
125
126
127
# File 'lib/dashing.rb', line 121

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_enginesObject



147
148
149
150
151
152
# File 'lib/dashing.rb', line 147

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