class Rollbar::LazyStore

Attributes

loaded_data[R]
raw[R]

Public Class Methods

new(initial_data) click to toggle source
# File lib/rollbar/lazy_store.rb, line 6
def initialize(initial_data)
  initial_data ||= {}

  @raw = initial_data
  @loaded_data = {}
end

Public Instance Methods

==(other) click to toggle source
# File lib/rollbar/lazy_store.rb, line 21
def ==(other)
  raw == if other.is_a?(self.class)
           other.raw
         else
           other
         end
end
[](key) click to toggle source
# File lib/rollbar/lazy_store.rb, line 34
def [](key)
  load_value(key)
end
[]=(key, value) click to toggle source
# File lib/rollbar/lazy_store.rb, line 38
def []=(key, value)
  raw[key] = value

  loaded_data.delete(key)
end
clone() click to toggle source

With this version of clone we ensure that the loaded_data is empty

# File lib/rollbar/lazy_store.rb, line 30
def clone
  self.class.new(raw.clone)
end
data() click to toggle source
# File lib/rollbar/lazy_store.rb, line 44
def data
  raw.reduce({}) do |acc, (k, _)|
    acc[k] = self[k]

    acc
  end
end
eql?(other) click to toggle source
# File lib/rollbar/lazy_store.rb, line 13
def eql?(other)
  if other.is_a?(self.class)
    raw.eql?(other.raw)
  else
    raw.eql?(other)
  end
end

Private Instance Methods

find_value(key) click to toggle source
# File lib/rollbar/lazy_store.rb, line 64
def find_value(key)
  value = raw[key]
  value.respond_to?(:call) ? value.call : value
end
load_value(key) click to toggle source
# File lib/rollbar/lazy_store.rb, line 54
def load_value(key)
  return loaded_data[key] if loaded_data.key?(key)
  return unless raw.key?(key)

  value = find_value(key)
  loaded_data[key] = value

  value
end
method_missing(method_sym, *args, &block) click to toggle source
Calls superclass method
# File lib/rollbar/lazy_store.rb, line 69
def method_missing(method_sym, *args, &block)
  return raw.send(method_sym, *args, &block) if raw.respond_to?(method_sym)

  super
end
respond_to_missing?(method_sym, include_all) click to toggle source
# File lib/rollbar/lazy_store.rb, line 75
def respond_to_missing?(method_sym, include_all)
  raw.respond_to?(method_sym, include_all)
end