Sha256: c9bf96ee9dee941d612536a5aeef53a64910e340e8ba281a5ce080693d064891

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 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, include_all = false)
      has_port?(sym) || super(sym)
    end

    private

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
origen-0.60.19 lib/origen/ports.rb
origen-0.60.18 lib/origen/ports.rb
origen-0.60.17 lib/origen/ports.rb
origen-0.60.16 lib/origen/ports.rb
origen-0.60.14 lib/origen/ports.rb
origen-0.60.13 lib/origen/ports.rb
origen-0.60.12 lib/origen/ports.rb
origen-0.60.11 lib/origen/ports.rb
origen-0.60.10 lib/origen/ports.rb
origen-0.60.9 lib/origen/ports.rb
origen-0.60.8 lib/origen/ports.rb