class Focuslight::Web
Public Class Methods
rule(*args)
click to toggle source
TODO: both of static method and helper method
# File lib/focuslight/web.rb, line 25 def self.rule(*args) Focuslight::Validator.rule(*args) end
Public Instance Methods
data()
click to toggle source
# File lib/focuslight/web.rb, line 83 def data @data ||= Focuslight::Data.new end
delete(graph)
click to toggle source
short interval update is always enabled in focuslight
TODO: option to disable?
# File lib/focuslight/web.rb, line 105 def delete(graph) if graph.complex? data().remove_complex(graph.id) else rrd().remove(graph) data().remove(graph.id) end parts = [:service, :section].map{|s| urlencode(graph.send(s))} {error: 0, location: url_for("/list/%s/%s" % parts)} end
format_number(num)
click to toggle source
# File lib/focuslight/web.rb, line 137 def format_number(num) # 12345678 => "12,345,678" num.to_s.reverse.chars.each_slice(3).map{|slice| slice.reverse.join}.reverse.join(',') end
linkpath(ary, prefix='/list')
click to toggle source
# File lib/focuslight/web.rb, line 133 def linkpath(ary, prefix='/list') [prefix, ary.map{|v| urlencode(v)}].join('/') end
number_type_rule()
click to toggle source
# File lib/focuslight/web.rb, line 87 def number_type_rule type = data().number_type if type == Float Focuslight::Validator.rule(:real) elsif type == Integer or type == :Bignum Focuslight::Validator.rule(:int) else raise "unknown number_type #{data().number_type}" end end
pathinfo(params)
click to toggle source
# File lib/focuslight/web.rb, line 116 def pathinfo(params) items = [] return items unless params[:service_name] items << params[:service_name] return items unless params[:section_name] items << params[:section_name] return items unless params[:graph_name] items << params[:graph_name] return items unless params[:t] items << params[:t] items end
rrd()
click to toggle source
# File lib/focuslight/web.rb, line 98 def rrd @rrd ||= Focuslight::RRD.new end
rule(*args)
click to toggle source
# File lib/focuslight/web.rb, line 79 def rule(*args) Focuslight::Validator.rule(*args) end
selected?(real, option)
click to toggle source
# File lib/focuslight/web.rb, line 142 def selected?(real, option) real == option ? 'selected' : '' end
url_for(url_fragment, mode=nil, options = nil)
click to toggle source
# File lib/focuslight/web.rb, line 36 def url_for(url_fragment, mode=nil, options = nil) if mode.is_a? Hash options = mode mode = nil end if mode.nil? mode = :path_only end mode = mode.to_sym unless mode.is_a? Symbol optstring = nil if options.is_a? Hash optstring = '?' + options.map { |k,v| "#{k}=#{URI.encode_www_form_component(v.to_s)}" }.join('&') end case mode when :path_only base = request.script_name when :full scheme = request.scheme if (scheme == 'http' && request.port == 80 || scheme == 'https' && request.port == 443) port = "" else port = ":#{request.port}" end base = "#{scheme}://#{request.host}#{port}#{request.script_name}" else raise TypeError, "Unknown url_for mode #{mode.inspect}" end "#{base}#{url_fragment}#{optstring}" end
urlencode(str)
click to toggle source
# File lib/focuslight/web.rb, line 71 def urlencode(str) CGI.escape(str) end
validate(*args)
click to toggle source
# File lib/focuslight/web.rb, line 75 def validate(*args) Focuslight::Validator.validate(*args) end