Sha256: b67026bfbe0a2d930fd955e26b6b609391bd88fb083145c0d1e4a869d1584057

Contents?: true

Size: 1.52 KB

Versions: 21

Compression:

Stored size: 1.52 KB

Contents

module Origen
  module Ports
    autoload :Port,     'origen/ports/port'
    autoload :Section,  'origen/ports/section'
    autoload :BitCollection,  'origen/ports/bit_collection'
    autoload :PortCollection,  'origen/ports/port_collection'

    def add_port(name, options = {})
      p = Port.new(self, name, options)
      if block_given?
        p.send(:defining) do
          yield p
        end
      end
      _ports.add(name.to_s.symbolize, p)
      p
    end

    def port(*args, &block)
      if block_given?
        add_port(*args, &block)
      else
        if args.first
          if has_port?(args.first)
            _ports[args.first.to_s.symbolize]
          else
            if initialized?
              puts "Model #{self.class} does not have a port named #{args.first}, the available ports are:"
              puts _ports.keys
              puts
              fail 'Missing port error'
            else
              # Assume this is a pin definition while the model is still initializing
              add_port(*args)
            end
          end
        else
          _ports
        end
      end
    end
    alias_method :ports, :port

    def has_port?(name)
      _ports.key?(name.to_s.symbolize)
    end

    def method_missing(method, *args, &block)
      if _ports.key?(method.to_s.symbolize)
        _ports[method.to_s.symbolize]
      else
        super
      end
    end

    def respond_to?(sym)
      has_port?(sym) || super(sym)
    end

    private

    def _ports
      @_ports ||= PortCollection.new
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
origen-0.7.3 lib/origen/ports.rb
origen-0.7.2 lib/origen/ports.rb
origen-0.7.1 lib/origen/ports.rb
origen-0.7.0 lib/origen/ports.rb
origen-0.6.12 lib/origen/ports.rb
origen-0.6.11 lib/origen/ports.rb
origen-0.6.10 lib/origen/ports.rb
origen-0.6.9 lib/origen/ports.rb
origen-0.6.8 lib/origen/ports.rb
origen-0.6.7 lib/origen/ports.rb
origen-0.6.6 lib/origen/ports.rb
origen-0.6.5 lib/origen/ports.rb
origen-0.6.4 lib/origen/ports.rb
origen-0.6.3 lib/origen/ports.rb
origen-0.6.2 lib/origen/ports.rb
origen-0.6.1 lib/origen/ports.rb
origen-0.6.0 lib/origen/ports.rb
origen-0.5.11 lib/origen/ports.rb
origen-0.5.10 lib/origen/ports.rb
origen-0.5.9 lib/origen/ports.rb