Class: JSONAPI::FormatterWrapperCache
- Inherits:
-
Object
- Object
- JSONAPI::FormatterWrapperCache
- Defined in:
- lib/jsonapi/formatter.rb
Overview
Warning: Not thread-safe. Wrap in ThreadLocalVar as needed.
Instance Attribute Summary collapse
-
#formatter_klass ⇒ Object
readonly
Returns the value of attribute formatter_klass.
Instance Method Summary collapse
- #cached ⇒ Object
- #format(arg) ⇒ Object
-
#initialize(formatter_klass) ⇒ FormatterWrapperCache
constructor
A new instance of FormatterWrapperCache.
- #uncached ⇒ Object
- #unformat(arg) ⇒ Object
Constructor Details
#initialize(formatter_klass) ⇒ FormatterWrapperCache
Returns a new instance of FormatterWrapperCache.
72 73 74 75 76 |
# File 'lib/jsonapi/formatter.rb', line 72 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_klass ⇒ Object (readonly)
Returns the value of attribute formatter_klass.
70 71 72 |
# File 'lib/jsonapi/formatter.rb', line 70 def formatter_klass @formatter_klass end |
Instance Method Details
#cached ⇒ Object
86 87 88 |
# File 'lib/jsonapi/formatter.rb', line 86 def cached self end |
#format(arg) ⇒ Object
78 79 80 |
# File 'lib/jsonapi/formatter.rb', line 78 def format(arg) @format_cache.get(arg) end |
#uncached ⇒ Object
90 91 92 |
# File 'lib/jsonapi/formatter.rb', line 90 def uncached return @formatter_klass end |
#unformat(arg) ⇒ Object
82 83 84 |
# File 'lib/jsonapi/formatter.rb', line 82 def unformat(arg) @unformat_cache.get(arg) end |