Sha256: d570e1a33f5c652abc8518f071aed50b527b41bdf6f324aca98077d484b5c93e

Contents?: true

Size: 433 Bytes

Versions: 9

Compression:

Stored size: 433 Bytes

Contents

module AngularSprinkles
  class KeyGenerator
    def initialize(args)
      @counter = args.fetch(:counter)
      @cache = args.fetch(:cache)
    end

    def call(object)
      return @cache.get(object) if @cache.set?(object)

      klass = "#{object.class}".gsub("::", "__")
      count = @counter.inc(klass)
      generated_key = "#{klass}_#{count}"

      @cache.set(object, generated_key)

      generated_key
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
angular_sprinkles-0.3.3 lib/angular_sprinkles/key_generator.rb
angular_sprinkles-0.3.2 lib/angular_sprinkles/key_generator.rb
angular_sprinkles-0.3.1 lib/angular_sprinkles/key_generator.rb
angular_sprinkles-0.3.0 lib/angular_sprinkles/key_generator.rb
angular_sprinkles-0.2.14 lib/angular_sprinkles/key_generator.rb
angular_sprinkles-0.2.13 lib/angular_sprinkles/key_generator.rb
angular_sprinkles-0.2.12 lib/angular_sprinkles/key_generator.rb
angular_sprinkles-0.2.11 lib/angular_sprinkles/key_generator.rb
angular_sprinkles-0.2.10 lib/angular_sprinkles/key_generator.rb