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.
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_klass ⇒ Object (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
#cached ⇒ Object
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 |
#uncached ⇒ Object
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 |