Class: CacheIt::Config
- Inherits:
-
Object
- Object
- CacheIt::Config
- Defined in:
- lib/cache_it.rb
Instance Method Summary collapse
- #counters(*counters) ⇒ Object
- #expires_in(expires_in = nil, &block) ⇒ Object
- #index(*index) ⇒ Object
- #indexes ⇒ Object
-
#initialize(model) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(model) ⇒ Config
Returns a new instance of Config.
177 178 179 180 181 |
# File 'lib/cache_it.rb', line 177 def initialize(model) @model = model @indexes ||= [[@model.primary_key]] @counters ||= [] end |
Instance Method Details
#counters(*counters) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/cache_it.rb', line 198 def counters(*counters) return @counters unless counters.present? counters = counters.map {|n|n.to_s} unless counters.all? {|n| @model.columns_hash[n].try(:type) == :integer} raise ArgumentError, "counters must be column names for integer attributes" end counters.each do |name| @counters.push name unless @counters.include? name end validate return nil end |
#expires_in(expires_in = nil, &block) ⇒ Object
211 212 213 214 215 216 217 218 219 |
# File 'lib/cache_it.rb', line 211 def expires_in(expires_in = nil, &block) unless expires_in or block_given? @expires_in.respond_to?(:call) ? @expires_in.call : @expires_in else raise ArgumentError, "use block or args" if expires_in and block_given? @expires_in = expires_in || block return nil end end |
#index(*index) ⇒ Object
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/cache_it.rb', line 183 def index(*index) return nil unless index.present? index = index.map {|n|n.to_s}.sort unless index.all? {|n| @model.column_names.include? n} raise ArgumentError, "index must be list of column names" end @indexes.push index unless @indexes.include? index validate return nil end |
#indexes ⇒ Object
194 195 196 |
# File 'lib/cache_it.rb', line 194 def indexes @indexes end |