Files

Class Index [+]

Quicksearch

UbiquoDesign::CachePolicies

Public Class Methods

add_conditions(policy, conditions, current_model = nil) click to toggle source

Adds the conditions to the current widget cache policy

     # File vendor/plugins/ubiquo_design/lib/ubiquo_design/cache_policies.rb, line 70
 70:       def add_conditions policy, conditions, current_model = nil
 71:         case conditions
 72:         when Symbol
 73:           if conditions == :self
 74:             policy[:self] = true
 75:           elsif conditions == :params
 76:             policy[:widget_params] = true
 77:           else
 78:             policy[:models][conditions.to_s] = {:params => [],
 79:               :procs => [],
 80:               :identifier => nil}
 81:           end
 82:         when Proc
 83:           policy[:procs] << conditions
 84:         when String
 85:           policy[:models][conditions] = {:params => [],
 86:             :procs => [],
 87:             :identifier => nil}
 88:         when Array
 89:           conditions.each do |condition|
 90:             add_conditions policy, condition
 91:           end
 92:         when Hash
 93:           conditions.each do |key, val|
 94:             if val.is_a?(Hash)
 95:               policy[:models][key.to_s] = {:params => [],
 96:                 :procs => [],
 97:                 :identifier => nil}
 98:               add_conditions policy, val, key.to_s
 99:             else
100:               if key == :expires_in
101:                 policy[:expires_in] = val
102:               else
103:                 if key.is_a?(Proc) || val.is_a?(Proc)
104:                   policy[:models][current_model][:procs] << [val, key]
105:                 else
106:                   policy[:models][current_model][:params] << {val => key}
107:                 end
108:               end
109:             end
110:           end
111:         end
112:           
113:       end
clear(context = nil) click to toggle source

Cleans the current structure

  context: possible context for multiple structures
    # File vendor/plugins/ubiquo_design/lib/ubiquo_design/cache_policies.rb, line 49
49:       def clear(context = nil)
50:         with_scope(context) { current_base.clear }
51:       end
current_base() click to toggle source

Returns the current base hash, given the applied scopes

     # File vendor/plugins/ubiquo_design/lib/ubiquo_design/cache_policies.rb, line 116
116:       def current_base
117:         current = @@policies
118:         @@scopes.each do |scope|
119:           next unless scope
120:           current[scope] = {} unless current[scope]
121:           current = current[scope]
122:         end
123:         current
124:       end
define(context = nil, &block) click to toggle source

Starts the definition of widget cache policies

  context: possible context to create multiple policies
    # File vendor/plugins/ubiquo_design/lib/ubiquo_design/cache_policies.rb, line 11
11:       def define(context = nil, &block)
12:         with_scope(context) do
13:           store_definition(block.call || {})
14:         end
15:       end
get(context = nil) click to toggle source

Returns a hash with the stored policies

    # File vendor/plugins/ubiquo_design/lib/ubiquo_design/cache_policies.rb, line 18
18:       def get(context = nil)
19:         with_scope(context) do
20:           current_base
21:         end
22:       end
get_by_model(instance, context = nil) click to toggle source

Returns a list of widget types which have policies that affect a given instance

    # File vendor/plugins/ubiquo_design/lib/ubiquo_design/cache_policies.rb, line 25
25:       def get_by_model(instance, context = nil)
26:         ([widgets = [], version_widgets = []]).tap do
27:           get(context).each_pair do |widget, policies|
28:             detected = (policies[:models] || []).to_a.detect{|model| instance.is_a?(model.first.to_s.constantize)}
29:             if detected.present?:
30:               related = detected.last
31:               if related[:params].blank? && related[:procs].blank?
32:                 version_widgets << widget
33:               else
34:                 widgets << widget
35:               end
36:             end
37:           end
38:         end
39:       end
store_definition(policies) click to toggle source

Stores a hash with widget cache policies

    # File vendor/plugins/ubiquo_design/lib/ubiquo_design/cache_policies.rb, line 54
54:       def store_definition policies
55:         base = current_base
56:         policies.each_pair do |widget, conditions|
57:           policy = base[widget] || {
58:             :self => true,
59:             :params => [],
60:             :models => {},
61:             :procs => [],
62:             :widget_params => true
63:           }
64:           add_conditions(policy, conditions)
65:           base[widget] = policy
66:         end
67:       end
with_scope(scope) {|ensure @@scopes.pop| ...} click to toggle source

Sets the current context during a declaration

    # File vendor/plugins/ubiquo_design/lib/ubiquo_design/cache_policies.rb, line 42
42:       def with_scope(scope)
43:         (@@scopes ||= []) << scope
44:         yield ensure @@scopes.pop
45:       end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.