Class: LinkMiddleware::MemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/link-middleware/store.rb

Overview

Use for testing only!

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MemoryStore

Returns a new instance of MemoryStore.



8
9
10
# File 'lib/link-middleware/store.rb', line 8

def initialize(options={})
  @store = {}
end

Instance Method Details

#add(context_uri, header) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/link-middleware/store.rb', line 12

def add(context_uri, header)
  stored_header = @store[context_uri] || LinkHeader.new
  header.links.each do |link|
    stored_header << link
  end
  @store[context_uri] = stored_header
  return true             
end

#read(context_uri) ⇒ Object



34
35
36
# File 'lib/link-middleware/store.rb', line 34

def read(context_uri)
  @store[context_uri] || LinkHeader.new
end

#remove(context_uri, header) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/link-middleware/store.rb', line 21

def remove(context_uri, header)
  stored_header = @store[context_uri] || LinkHeader.new
  return true if stored_header.links.empty?
  
  #if there are links to remove, which aren't in the stored set, then return false
  return false if !(header.links - stored_header.links).empty?
  
  #otherwise remove them
  final = stored_header.links - header.links
  @store[context_uri] = LinkHeader.new( final )
  return true             
end