Module: Vedeu::Persistence

Extended by:
Persistence
Included in:
Persistence
Defined in:
lib/vedeu/support/persistence.rb

Instance Method Summary collapse

Instance Method Details

#create(attributes) ⇒ Object



17
18
19
# File 'lib/vedeu/support/persistence.rb', line 17

def create(attributes)
  storage.store(attributes[:name], Interface.new(attributes))
end

#query(value) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/vedeu/support/persistence.rb', line 21

def query(value)
  return false if value.nil? || value.empty?

  storage.select do |name, result|
    return result if name == value
  end

  fail EntityNotFound, "Interface could not be found."
end

#resetObject



31
32
33
# File 'lib/vedeu/support/persistence.rb', line 31

def reset
  @storage = {}
end

#update(name, attributes = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/vedeu/support/persistence.rb', line 9

def update(name, attributes = {})
  interface = query(name)
  interface.attributes = attributes
  interface
rescue EntityNotFound
  create(attributes)
end