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


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

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


64
65
66
# File 'lib/jsonapi/formatter.rb', line 64

def formatter_klass
  @formatter_klass
end

Instance Method Details

#cachedObject


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

def cached
  self
end

#format(arg) ⇒ Object


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

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

#unformat(arg) ⇒ Object


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

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