class Shoebox::Storage
Constants
- UnknownResourceType
Attributes
data[R]
resource_types[R]
Public Class Methods
new(*resource_types)
click to toggle source
# File lib/shoebox/storage.rb, line 7 def initialize(*resource_types) @resource_types = resource_types.flatten reset end
Public Instance Methods
all(resource_type)
click to toggle source
# File lib/shoebox/storage.rb, line 30 def all(resource_type) validate_resource_type(resource_type) data[resource_type].values end
fetch(resource_type, resource_id, &value)
click to toggle source
# File lib/shoebox/storage.rb, line 12 def fetch(resource_type, resource_id, &value) validate_resource_type(resource_type) data[resource_type][resource_id] ||= value.call end
get(resource_type, resource_id)
click to toggle source
# File lib/shoebox/storage.rb, line 24 def get(resource_type, resource_id) validate_resource_type(resource_type) data[resource_type][resource_id] end
reset()
click to toggle source
# File lib/shoebox/storage.rb, line 36 def reset @data = Hash.new resource_types.each do |resource_type| data[resource_type] = Hash.new end end
stash(resource_type, resource_id, value)
click to toggle source
# File lib/shoebox/storage.rb, line 18 def stash(resource_type, resource_id, value) validate_resource_type(resource_type) data[resource_type][resource_id] = value end
Private Instance Methods
validate_resource_type(resource_type)
click to toggle source
# File lib/shoebox/storage.rb, line 48 def validate_resource_type(resource_type) unless resource_types.include?(resource_type) raise UnknownResourceType.new( "#{resource_type} is not a known resource type" ) end end