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.
Name Total lines Lines of code Total coverage Code coverage
lib/ramaze/helper/cache.rb 142 27
100.0% 
100.0% 
  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 
  6   # This helper is providing easy access to a couple of Caches to use for
  7   # smaller amounts of data.
  8 
  9   module CacheHelper
 10 
 11     # Create the Cache.value_cache on inclusion if it doesn't exist yet.
 12     def self.included(klass)
 13       Cache.add(:value_cache) unless Cache::CACHES.has_key?(:value_cache)
 14     end
 15 
 16     # Example:
 17     #
 18     #   class FooController < Ramaze::Controller
 19     #     helper :cache
 20     #     cache :index, :map_of_the_internet
 21     #   end
 22     #
 23     # cache supports these options
 24     #   [+:ttl+]  time-to-live in seconds
 25     #   [+:key+]  proc that returns a key to store cache with
 26     #
 27     # Example:
 28     #
 29     #   class CacheController < Ramaze::Controller
 30     #     helper :cache
 31     #
 32     #     # for each distinct value of request['name']
 33     #     # cache rendered output of name action for 60 seconds
 34     #     cache :name, :key => lambda{ request['name'] }, :ttl => 60
 35     #
 36     #     def name
 37     #       "hi #{request['name']}"
 38     #     end
 39     #   end
 40     #
 41     # cache acts as a wrapper for value_cache if no args are given
 42 
 43     def cache *args
 44       return value_cache if args.size == 0
 45 
 46       if args.last.is_a? Hash
 47         opts = args.pop
 48       end
 49       opts ||= {}
 50 
 51       args.each do |arg|
 52         actions_cached[arg.to_sym] = opts unless arg.nil?
 53       end
 54     end
 55 
 56     private
 57 
 58     # use this to cache values in your controller and templates,
 59     # for example heavy calculations or time-consuming queries.
 60 
 61     def value_cache
 62       Cache.value_cache
 63     end
 64 
 65     # action_cache holds rendered output of actions for which caching is enabled.
 66     #
 67     # For simple cases:
 68     #
 69     #   class Controller < Ramaze::Controller
 70     #     map '/path/to'
 71     #     helper :cache
 72     #     cache :action
 73     #
 74     #     def action with, params
 75     #       'rendered output'
 76     #     end
 77     #   end
 78     #
 79     #   { '/path/to/action/with/params' => {
 80     #       :time => Time.at(rendering),
 81     #       :type => 'content/type',
 82     #       :content => 'rendered output'
 83     #     }
 84     #   }
 85     #
 86     # If an additional key is provided:
 87     #
 88     #   class Controller < Ramaze::Controller
 89     #     map '/path/to'
 90     #     helper :cache
 91     #     cache :action, :key => lambda{ 'value of key proc' }
 92     #
 93     #     def action
 94     #       'output'
 95     #     end
 96     #   end
 97     #
 98     #   { '/path/to/action' => {
 99     #       'value of key proc' => {
100     #         :time => Time.at(rendering),
101     #         :type => 'content/type',
102     #         :content => 'output'
103     #       }
104     #     }
105     #   }
106     #
107     # Caches can be invalidated after a certain amount of time
108     # by supplying a :ttl option (in seconds)
109     #
110     #   class Controller < Ramaze::Controller
111     #     helper :cache
112     #     cache :index, :ttl => 60
113     #
114     #     def index
115     #       Time.now.to_s
116     #     end
117     #   end
118     #
119     # or by deleting values from action_cache directly
120     #
121     #   action_cache.clear
122     #   action_cache.delete '/index'
123     #   action_cache.delete '/path/to/action'
124 
125     def action_cache
126       Cache.actions
127     end
128 
129     # This refers to the class-trait of cached actions, you can
130     # add/remove actions to be cached.
131     #
132     # Example:
133     #
134     #   class FooController < Ramaze::Controller
135     #     trait :actions_cached => [:index, :map_of_the_internet]
136     #   end
137 
138     def actions_cached
139       ancestral_trait[:actions_cached]
140     end
141   end
142 end

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

Valid XHTML 1.0! Valid CSS!