Class: Adalog::InMemoryRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/adalog/in_memory_repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**repo_options) ⇒ InMemoryRepo

Returns a new instance of InMemoryRepo.



6
7
8
# File 'lib/adalog/in_memory_repo.rb', line 6

def initialize(**repo_options)
  @storage = Array.new
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



4
5
6
# File 'lib/adalog/in_memory_repo.rb', line 4

def storage
  @storage
end

Instance Method Details

#allObject



33
34
35
# File 'lib/adalog/in_memory_repo.rb', line 33

def all
  storage.dup
end

#clear!Object



27
28
29
30
# File 'lib/adalog/in_memory_repo.rb', line 27

def clear!
  @storage = Array.new
  :ok
end

#fetch(**options) ⇒ Object



11
12
13
# File 'lib/adalog/in_memory_repo.rb', line 11

def fetch(**options)
  all
end

#insert(entry = nil, **options) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/adalog/in_memory_repo.rb', line 16

def insert(entry = nil, **options)
  converted_entry = Adalog::Entry.build(entry = nil, **options)
  if converted_entry.valid?
    storage.unshift(converted_entry)
    [:ok, converted_entry]
  else
    [:error, converted_entry.errors]
  end
end