Class: JSONAPI::FormatterWrapperCache

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi/formatter.rb

Overview

Warning: Not thread-safe. Wrap in ThreadLocalVar as needed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter_klass) ⇒ FormatterWrapperCache

Returns a new instance of FormatterWrapperCache.



70
71
72
73
74
# File 'lib/jsonapi/formatter.rb', line 70

def initialize(formatter_klass)
  @formatter_klass = formatter_klass
  @format_cache = NaiveCache.new{|arg| formatter_klass.format(arg) }
  @unformat_cache = NaiveCache.new{|arg| formatter_klass.unformat(arg) }
end

Instance Attribute Details

#formatter_klassObject (readonly)

Returns the value of attribute formatter_klass.



68
69
70
# File 'lib/jsonapi/formatter.rb', line 68

def formatter_klass
  @formatter_klass
end

Instance Method Details

#cachedObject



84
85
86
# File 'lib/jsonapi/formatter.rb', line 84

def cached
  self
end

#format(arg) ⇒ Object



76
77
78
# File 'lib/jsonapi/formatter.rb', line 76

def format(arg)
  @format_cache.get(arg)
end

#uncachedObject



88
89
90
# File 'lib/jsonapi/formatter.rb', line 88

def uncached
  return @formatter_klass
end

#unformat(arg) ⇒ Object



80
81
82
# File 'lib/jsonapi/formatter.rb', line 80

def unformat(arg)
  @unformat_cache.get(arg)
end