Module: Origen::Ports

Defined in:
lib/origen/ports.rb,
lib/origen/ports/port.rb,
lib/origen/ports/section.rb,
lib/origen/ports/bit_collection.rb,
lib/origen/ports/port_collection.rb

Defined Under Namespace

Classes: BitCollection, Port, PortCollection, Section

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/origen/ports.rb', line 48

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

Instance Method Details

#add_port(name, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/origen/ports.rb', line 8

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

#has_port?(name) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/origen/ports.rb', line 44

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

#port(*args, &block) ⇒ Object Also known as: ports



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/origen/ports.rb', line 19

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

#respond_to?(sym, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/origen/ports.rb', line 56

def respond_to?(sym, include_all = false)
  has_port?(sym) || super(sym)
end