C0 code coverage information
Generated on Sat Feb 02 17:44:26 +0100 2008 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2 # All files in this distribution are subject to the terms of the Ruby license.
3
4 module Ramaze
5 unless defined?(GlobalStruct) # prevent problems for SourceReload
6 class GlobalStruct < Struct.new('Global', *OPTIONS.keys)
7 end
8 end
9
10 # Class for Ramaze::Global instance.
11 class GlobalStruct
12
13 ENV_TRIGGER = {
14 'EVENT' => lambda{ require 'ramaze/adapter/evented_mongrel' },
15 'SWIFT' => lambda{ require 'ramaze/adapter/swiftiplied_mongrel' }
16 }
17
18 # mapping of :adapter => to the right class-name.
19 ADAPTER_ALIAS = {
20 :cgi => :Cgi,
21 :fcgi => :Fcgi,
22 :scgi => :Scgi,
23 :thin => :Thin,
24 :lsws => :Lsws,
25 :webrick => :WEBrick,
26 :mongrel => :Mongrel,
27 :evented_mongrel => :Mongrel,
28 :swiftiplied_mongrel => :Mongrel,
29 }
30
31 # mapping of :cache => to the right class-name.
32 CACHE_ALIAS = {
33 :memcached => :MemcachedCache,
34 :memory => :MemoryCache,
35 :yaml => :YAMLStoreCache,
36 }
37
38 class << self
39 alias setup fill
40 end
41
42 # Called from Ramaze::start, sets all the options.
43 def startup(options = {})
44 options.each do |key, value|
45 if (method(key) rescue false)
46 send("#{key}=", value)
47 else
48 create_member(key, value)
49 end
50 end
51
52 ENV_TRIGGER.values_at(*ENV.keys).compact.each{|l| l.call}
53
54 engines = self[:load_engines]
55 (Symbol === engines ? [engines] : engines).each do |engine|
56 Ramaze::Template.const_get(engine)
57 end
58 end
59
60 # batch-assignment of key/value from hash, yields self if a block is given.
61 def setup(hash = {})
62 hash.each do |key, value|
63 self.send("#{key}=", value)
64 end
65 yield(self) if block_given?
66 end
67
68
69 # Object wraps
70
71 # get right classname, require the file for given adapter and answer with
72 # the actual class.
73 def adapter
74 if internal = self[:adapter]
75 class_name = ADAPTER_ALIAS.fetch(internal.to_sym, internal)
76 unless Ramaze::Adapter.const_defined?(class_name)
77 require("ramaze/adapter"/internal.to_s.downcase)
78 end
79 Ramaze::Adapter.const_get(class_name)
80 end
81 end
82
83 # get right classname, require the file for given cache and answer with
84 # the actual class.
85 def cache
86 cache_name = self[:cache].to_sym
87 class_name = CACHE_ALIAS[cache_name] || cache_name
88 cache = Ramaze.const_get(class_name)
89 end
90
91 # a range built from port and the number of spawns.
92 def ports
93 (port.to_i..(port.to_i + (spawn.to_i - 1)))
94 end
95
96 # reassigns the interval in the instance of SourceReload that is running or
97 # just waiting.
98 def sourcereload=(interval)
99 self[:sourcereload] = interval
100 sri = Thread.main[:sourcereload]
101 sri.interval = interval if sri
102 end
103
104 def template_root
105 [ tr = self[:template_root],
106 APPDIR/tr,
107 APPDIR/'template',
108 ].find{|path| File.directory?(path) } || self[:template_root]
109 end
110
111 def public_root
112 [ pr = self[:public_root],
113 APPDIR/pr,
114 ].find{|path| File.directory?(path) } || self[:public_root]
115 end
116
117 def list_directories=(active)
118 require 'ramaze/dispatcher'
119 d = Ramaze::Dispatcher
120 self[:list_directories] = active
121 if active
122 d::FILTER.put_within(d::Directory, :after => d::File, :before => d::Action)
123 else
124 d::FILTER.delete(d::Directory)
125 end
126 end
127
128
129 # External helpers
130
131 # Answers with values for given keys by sending each to self
132 def values_at(*keys)
133 keys.map{|key| __send__(key)}
134 end
135
136 # Creates a new attr_accessor like method-pair.
137 def create_member key, value = nil
138 Inform.warn "Create #{key}=#{value.inspect} on Global"
139
140 @table ||= {}
141 key = key.to_sym
142
143 (class << self; self; end).class_eval do
144 define_method(key){ @table[key] }
145 define_method("#{key}="){|val| @table[key] = val }
146 end
147
148 @table[key] = value
149 end
150 end
151 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.