Class: Tache::Safe

Inherits:
Tache
  • Object
show all
Defined in:
lib/tache/safe.rb

Overview

TODO: This means that subclasses have to override has_key? if they want to support key_missing. The other option is to return :missing from key_missing by default and stipulate that subclasses must call super if they can’t find the key, that does however mean a couple of extra method calls, one to [] and one to key_missing, even if key not supported. Is extra overhead worth it for being able to override just key_missing?

Example:

def has_key?(key)
  super || @thingy.respond_to?(key)
end

def key_missing(key)
  @thingy.send(key)
end

Another option would be to have a handles_key? method akin to responds_to_missing?

Defined Under Namespace

Classes: Context

Constant Summary

Constants inherited from Tache

ENTITIES, VERSION

Instance Method Summary collapse

Methods inherited from Tache

#compile, compile, #escape, #partial, #partials, #partials=, #render, render

Instance Method Details

#[](key) ⇒ Object



28
29
30
# File 'lib/tache/safe.rb', line 28

def [](key)
  allowed_method?(key) ? send(key) : key_missing(key)
end

#contextObject



20
21
22
# File 'lib/tache/safe.rb', line 20

def context
  @context ||= Context.new(self)
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/tache/safe.rb', line 24

def has_key?(key)
  allowed_method?(key)
end

#key_missing(key) ⇒ Object



32
33
34
# File 'lib/tache/safe.rb', line 32

def key_missing(key)
  nil
end

#to_sObject



36
37
38
# File 'lib/tache/safe.rb', line 36

def to_s
  ''
end