Sha256: 57b91b5bde853bab474aa89c59dfa2a812fdf84d741e5bb2b3df667138799876

Contents?: true

Size: 826 Bytes

Versions: 3

Compression:

Stored size: 826 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)
      result = super
      fail UndefinedInterface, "#{name.to_s} could not be found." unless result
      result
    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

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.0.33 lib/vedeu/repository/interface_repository.rb
vedeu-0.0.32 lib/vedeu/repository/interface_repository.rb
vedeu-0.0.31 lib/vedeu/repository/interface_repository.rb