Sha256: 16efbebfb6539640bd907e22e63a7a055b7b04066896190f703d297c92e3b194

Contents?: true

Size: 685 Bytes

Versions: 22

Compression:

Stored size: 685 Bytes

Contents

require 'jbuilder/jbuilder'
require 'active_support/core_ext/array'

class Jbuilder
  class KeyFormatter
    def initialize(*args)
      @format = {}
      @cache = {}

      options = args.extract_options!
      args.each do |name|
        @format[name] = []
      end
      options.each do |name, parameters|
        @format[name] = parameters
      end
    end

    def initialize_copy(original)
      @cache = {}
    end

    def format(key)
      @cache[key] ||= @format.inject(key.to_s) do |result, args|
        func, args = args
        if ::Proc === func
          func.call result, *args
        else
          result.send func, *args
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
jbuilder-2.13.0 lib/jbuilder/key_formatter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/jbuilder-2.12.0/lib/jbuilder/key_formatter.rb
jbuilder-2.12.0 lib/jbuilder/key_formatter.rb
jbuilder-2.11.5 lib/jbuilder/key_formatter.rb
jbuilder-2.11.4 lib/jbuilder/key_formatter.rb
jbuilder-2.11.3 lib/jbuilder/key_formatter.rb
jbuilder-2.11.2 lib/jbuilder/key_formatter.rb
jbuilder-2.11.1 lib/jbuilder/key_formatter.rb
jbuilder-2.11.0 lib/jbuilder/key_formatter.rb
jbuilder-2.10.2 lib/jbuilder/key_formatter.rb
jbuilder-2.10.1 lib/jbuilder/key_formatter.rb
jbuilder-2.10.0 lib/jbuilder/key_formatter.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/jbuilder-2.9.1/lib/jbuilder/key_formatter.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/jbuilder-2.9.1/lib/jbuilder/key_formatter.rb
jbuilder-2.9.1 lib/jbuilder/key_formatter.rb
jbuilder-2.9.0 lib/jbuilder/key_formatter.rb
jbuilder-2.8.0 lib/jbuilder/key_formatter.rb
jbuilder-2.7.0 lib/jbuilder/key_formatter.rb
jbuilder-2.6.4 lib/jbuilder/key_formatter.rb
jbuilder-2.6.3 lib/jbuilder/key_formatter.rb