Class: ChatX::Helpers

Inherits:
Object
  • Object
show all
Defined in:
lib/chatx/models/helpers.rb

Class Method Summary collapse

Class Method Details

.cached(key, scope = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chatx/models/helpers.rb', line 18

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

.symbolize_hash_keys(hash) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/chatx/models/helpers.rb', line 5

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