Sha256: e408313d8e8456df3a3d598542a96d70ef30248b3e0eef88f36cabe660ed05e3

Contents?: true

Size: 573 Bytes

Versions: 3

Compression:

Stored size: 573 Bytes

Contents

module Adalog
  class InMemoryRepo

    attr_reader :storage

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


    def fetch(**options)
      all
    end


    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


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


    def all
      storage.dup
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adalog-0.5.0 lib/adalog/in_memory_repo.rb
adalog-0.4.1 lib/adalog/in_memory_repo.rb
adalog-0.4.0 lib/adalog/in_memory_repo.rb