Sha256: f758401dc6e9ca3e03ba21ead0558f58725333c3f71db58f06ba3fca1bffcf02

Contents?: true

Size: 799 Bytes

Versions: 2

Compression:

Stored size: 799 Bytes

Contents

module ChatX
  class Helpers
    @cache = {}

    def self.symbolize_hash_keys(hash)
      hash.each_key do |key|
        # rubocop:disable Lint/RescueWithoutErrorClass
        hash[(begin
                key.to_sym
              rescue
                key
              end) || key] = hash.delete(key)
        # rubocop:enable: Lint/RescueWithoutErrorClass
      end
      hash
    end

    def self.cached(key, scope = nil)
      @cache ||= {}
      if !scope.nil?
        @cache[scope] ||= {}
        @cache[scope][key] = yield if @cache[scope][key].nil?
        @cache[scope][key]
      else
        @cache[key] = yield if @cache[key].nil?
        @cache[key]
      end
    end
  end

  class InitializationDataException < RuntimeError
    def initialize(msg)
      super(msg)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chatx-0.0.1 lib/chatx/models/helpers.rb
chatx-0.0.0.pre.pre3 lib/chatx/models/helpers.rb