Class: Jbuilder::KeyFormatter
- Inherits:
-
Object
- Object
- Jbuilder::KeyFormatter
- Defined in:
- lib/jbuilder.rb
Instance Method Summary collapse
- #format(key) ⇒ Object
-
#initialize(*args) ⇒ KeyFormatter
constructor
A new instance of KeyFormatter.
- #initialize_copy(original) ⇒ Object
Constructor Details
#initialize(*args) ⇒ KeyFormatter
Returns a new instance of KeyFormatter.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jbuilder.rb', line 11 def initialize(*args) @format = {} @cache = {} = args. args.each do |name| @format[name] = [] end .each do |name, paramaters| @format[name] = paramaters end end |
Instance Method Details
#format(key) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jbuilder.rb', line 28 def format(key) @cache[key] ||= @format.inject(key.to_s) do |result, args| func, args = args if func.is_a? Proc func.call(result, *args) else result.send(func, *args) end end end |
#initialize_copy(original) ⇒ Object
24 25 26 |
# File 'lib/jbuilder.rb', line 24 def initialize_copy(original) @cache = {} end |