C0 code coverage information

Generated on Sat Feb 02 17:44:24 +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.
Name Total lines Lines of code Total coverage Code coverage
lib/ramaze/action/render.rb 148 93
98.6% 
97.8% 
  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   class Action
  6 
  7     # Render this instance of Action, this will (eventually) pass itself to
  8     # Action#engine.transform
  9     # Usage, given that Foo is a Controller and has the method/template
 10     # for index:
 11     #  > Action(:controller => Foo).render
 12     #  #> 'bar'
 13 
 14     def render
 15       Inform.dev("The Action: #{self}")
 16       Thread.current[:action] = self
 17 
 18       if should_cache?
 19         cached_render
 20       else
 21         uncached_render
 22       end
 23     end
 24 
 25     private
 26 
 27     # Return the cached output of the action if it exists, otherwise do a
 28     # normal Action#uncached_render and store the output in the Cache.actions.
 29     # Action#cached_render is only called if Action#should_cache? returns
 30     # true.
 31 
 32     def cached_render
 33       if Global.file_cache
 34         cached_render_file
 35       else
 36         cached_render_memory
 37       end
 38     end
 39 
 40     def cached_render_file
 41       rendered = uncached_render
 42 
 43       global_epath = Global.public_root/self.controller.mapping/extended_path
 44       FileUtils.mkdir_p(File.dirname(global_epath))
 45       File.open(global_epath, 'w+') {|fp| fp.print(rendered) }
 46 
 47       rendered
 48     end
 49 
 50     def cached_render_memory
 51       action_cache = Cache.actions
 52       full_path = self.controller.mapping/extended_path
 53 
 54       # backwards compat with trait :actions_cached => []
 55       cache_opts = actions_cached.is_a?(Hash) ? actions_cached[path.to_sym] : {}
 56 
 57       if cache_opts[:key]
 58         action_cache[full_path] ||= {}
 59         cache = action_cache[full_path][ cache_opts[:key].call ] ||= {}
 60       else
 61         cache = action_cache[full_path] ||= {}
 62       end
 63 
 64       if cache.size > 0 and (cache_opts[:ttl].nil? or cache[:time] + cache_opts[:ttl] > Time.now)
 65         Inform.debug("Using Cached version")
 66         Response.current['Content-Type'] = cache[:type]
 67       else
 68         Inform.debug("Compiling Action")
 69         cache.replace({ :time => Time.now, :content => uncached_render, :type => Response.current['Content-Type'] })
 70       end
 71 
 72       cache[:content]
 73     end
 74 
 75     # The 'normal' rendering process. Passes the Action instance to
 76     # Action#engine.transform, which returns the output of the action.
 77     # Layout will be found and rendered in this step after self was rendered.
 78 
 79     def uncached_render
 80       content = [before_process,
 81                  engine.transform(self),
 82                  after_process].join
 83 
 84       if path and tlayout = layout
 85         [instance, tlayout.instance].each do |i|
 86           i.instance_variable_set("@content", content)
 87         end
 88 
 89         content = tlayout.render
 90 
 91         # restore Action.current after render above
 92         Thread.current[:action] = self
 93       end
 94 
 95       content
 96     end
 97 
 98     # Determine whether or not we have a layout to process and sets it up
 99     # correctly to be rendered in the same context as current action.
100     # Will return false if the layout is the same as current action to avoid
101     # infinite recursion and also if no layout on this controller was found.
102 
103     def layout
104       return false unless layouts = controller.trait[:layout]
105 
106       possible = [layouts[path], layouts[:all]].compact
107       denied = layouts[:deny].to_a
108 
109       if layout = possible.first
110         layout_action = Ramaze::Controller.resolve(layout)
111 
112         return false if denied.include?(path) or layout_action.path == path
113 
114         if layout_action.controller != controller
115           instance.instance_variables.each do |x|
116             if layout_action.instance.instance_variable_defined?(x)
117               Inform.warn "overwriting instance variable #{x} from layout controller with instance variable from action controller."
118             end
119             layout_action.instance.instance_variable_set(x, instance.instance_variable_get(x))
120           end
121         else
122           layout_action.binding = binding
123           layout_action.controller = controller
124           layout_action.instance = instance
125         end
126 
127         layout_action.path = nil
128         layout_action
129       end
130     end
131 
132     def actions_cached
133       controller.trait[:actions_cached]
134     end
135 
136     # return true if the action is flagged for caching. Called by
137     # Action#render.
138 
139     def should_cache?
140       ctrait = controller.trait
141 
142       [ Global.cache_all,
143         ctrait[:cache_all],
144         actions_cached.map{|k,v| k.to_s}.include?(method),
145       ].any?
146     end
147   end
148 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.

Valid XHTML 1.0! Valid CSS!