class Normalizr::Bag

Public Class Methods

new(bag={}) click to toggle source
# File lib/normalizr/bag.rb, line 5
def initialize bag={}, opts
  @bag = bag
  @opts = opts
end

Public Instance Methods

add(name, value) click to toggle source
# File lib/normalizr/bag.rb, line 10
def add name, value
  if value[:id].nil? || @opts[:new_keys]
    value[:id] = next_guid!
  end
  @bag[name.to_sym] ||= {}
  @bag[name.to_sym][value[:id]] = value
  value[:id]
end
get(name, id) click to toggle source
# File lib/normalizr/bag.rb, line 19
def get name, id
  @bag[name.to_sym][id]
end
next_guid!() click to toggle source
# File lib/normalizr/bag.rb, line 27
def next_guid!
  SecureRandom.uuid
end
to_hash() click to toggle source
# File lib/normalizr/bag.rb, line 23
def to_hash
  @bag.dup
end