class Intercom::Lib::FlatStore

Sub-class of {Hash} for storing custom data attributes. Doesn’t allow nested Hashes or Arrays. And requires {String} or {Symbol} keys.

Public Class Methods

new(attributes={}) click to toggle source
# File lib/intercom/lib/flat_store.rb, line 8
def initialize(attributes={})
  (attributes).each do |key, value|
    validate_key_and_value(key, value)
    self[key] = value
  end
end

Public Instance Methods

[](key) click to toggle source
Calls superclass method
# File lib/intercom/lib/flat_store.rb, line 20
def [](key)
  super(key.to_s)
end
[]=(key, value) click to toggle source
Calls superclass method
# File lib/intercom/lib/flat_store.rb, line 15
def []=(key, value)
  validate_key_and_value(key, value)
  super(key.to_s, value)
end

Private Instance Methods

validate_key_and_value(key, value) click to toggle source
# File lib/intercom/lib/flat_store.rb, line 25
def validate_key_and_value(key, value)
  raise ArgumentError.new("This does not support nested data structures (key: #{key}, value: #{value}") if value.is_a?(Array) || value.is_a?(Hash)
  raise ArgumentError.new("Key must be String or Symbol: #{key}") unless key.is_a?(String) || key.is_a?(Symbol)
end