Sha256: 82d5888a9fd3a724d3f72f7dbb80d29c7b132d2eb227038bb5ec9897451c3dfa

Contents?: true

Size: 819 Bytes

Versions: 5

Compression:

Stored size: 819 Bytes

Contents

require 'vedeu/models/interface'

# Todo: mutation (persistence)

module Vedeu
  EntityNotFound = Class.new(StandardError)

  module InterfaceStore
    extend self

    def update(name, attributes = {})
      interface = query(name)
      interface.attributes = attributes
      interface

    rescue EntityNotFound
      create(attributes)

    end

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

    def query(interface_name)
      storage.select do |name, interface|
        return interface if name == interface_name
      end unless interface_name.nil? || interface_name.empty?

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

    def reset
      @storage = {}
    end

    private

    def storage
      @storage ||= {}
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.1.7 lib/vedeu/support/interface_store.rb
vedeu-0.1.6 lib/vedeu/support/interface_store.rb
vedeu-0.1.5 lib/vedeu/support/interface_store.rb
vedeu-0.1.4 lib/vedeu/support/interface_store.rb
vedeu-0.1.3 lib/vedeu/support/interface_store.rb