Module: MethodCacher

Defined in:
lib/method_cacher/base.rb,
lib/method_cacher/railtie.rb,
lib/method_cacher/version.rb

Defined Under Namespace

Modules: Base Classes: Configuration, Railtie

Constant Summary collapse

VERSION =
'0.1.0'
@@config =
MethodCacher::Configuration.new

Class Method Summary collapse

Class Method Details

.configure(&block) ⇒ Object

Gives a block configuration style like that of Rails.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/method_cacher/base.rb', line 25

def self.configure(&block)
  if block_given?
    if block.arity == 1
      # allows this style config: MethodCacher.configure do |config| config.variable = ... end
      yield config
    else
      # allows this style config: MethodCacher.configure do config.variable = ... end
      # While this option is more elegant because it doesn't require a block variable, it loses access to
      # methods defined in the calling context because the context switches to that of the self object.
      instance_eval &block
    end
  end
end