Class: GRI::Cast

Inherits:
Object show all
Defined in:
lib/gri/cast.rb,
lib/gri/plugin/bootstrap.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCast

Returns a new instance of Cast.



22
23
24
25
26
27
28
# File 'lib/gri/cast.rb', line 22

def initialize
  root_dir = Config['root-dir'] ||= Config::ROOT_PATH
  log_dir = Config['log-dir'] || Config['root-dir'] + '/log'
  Log.init "#{log_dir}/#{File.basename $0}.log"
rescue SystemCallError
  Log.init '/tmp/gricast.log'
end

Class Method Details

.layoutObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gri/cast.rb', line 67

def self.layout
  <<EOS
<html>
<head>
<title><%= @title %></title>
<style>
td.text-right {text-align:right;}
hr {border:none;border-top:1px #cccccc solid;}
</style>
</head>
<body>
<%= yield %>
</body>
</html>
EOS
end

.parse_path_info(env) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/gri/cast.rb', line 12

def self.parse_path_info env
  if (path_info = env['PATH_INFO']) =~ %r{^/(?:list|graph)\b}
    path_info = Regexp.last_match.post_match
  end
  if path_info
    dummy, service_name, section_name, graph_name = path_info.split /\// #/
  end
  return service_name, section_name, graph_name
end

Instance Method Details

#call(env) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gri/cast.rb', line 30

def call env
  req = GRI::Request.new env
  params = req.params
  cast_dir = Config['cast-dir'] || (Config::ROOT_PATH + '/cast')
  if params['grp']
    cast_dir = cast_dir + '/' + params['grp']
  end

  if (req.query_string =~ /\A(\d+),(\d+)\z/)
    app = Page.new :dirs=>[cast_dir], :clicked=>true, :imgx=>$1, :imgy=>$2
  elsif params['r'] or params['tag']
    if params['stime']
      app = Graph.new :dirs=>[cast_dir]
    else
      app = Page.new :dirs=>[cast_dir]
    end
  elsif params['search'].to_i == 1
    app = List.new :dirs=>[cast_dir]
  elsif
    case env['PATH_INFO']
    when %r{^/api/}
      app = API.new
    when %r{^/graph/}
      app = Cgraph.new :dir=>cast_dir
    when %r{^/page}
      app = Page.new :dirs=>[cast_dir]
    else
      app = Clist.new :dir=>cast_dir
    end
  end
  app.call env
end

#public_dirObject



63
64
65
# File 'lib/gri/cast.rb', line 63

def public_dir
  File.dirname(__FILE__) + '/../../public'
end