Sha256: 71fbae4e2e18903e497e3f5113cdd85b9ceabacefb272f3f1503decc6cfb6d81

Contents?: true

Size: 863 Bytes

Versions: 5

Compression:

Stored size: 863 Bytes

Contents

require_relative '../models/interface'
require_relative 'repository'

module Vedeu
  class UndefinedInterface < StandardError; end

  module InterfaceRepository
    extend Repository
    extend self

    def create(attributes = {})
      super(entity.new(attributes))
    end

    def find(name)
      if result = query(entity, :name, name)
        result

      else
        fail UndefinedInterface, "#{name.to_s} could not be found."

      end
    end

    def update(name, attributes = {})
      interface = find(name)
      interface.attributes = attributes
      interface
    rescue UndefinedInterface
      create(attributes)
    end

    def refresh
      by_layer.map { |interface| interface.refresh }.compact
    end

    def entity
      Interface
    end

    private

    def by_layer
      all.sort_by { |interface| interface.z }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.0.38 lib/vedeu/repository/interface_repository.rb
vedeu-0.0.37 lib/vedeu/repository/interface_repository.rb
vedeu-0.0.36 lib/vedeu/repository/interface_repository.rb
vedeu-0.0.35 lib/vedeu/repository/interface_repository.rb
vedeu-0.0.34 lib/vedeu/repository/interface_repository.rb