Class: Origen::Generator::PatternIterator

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/generator/pattern_iterator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyObject

Returns the value of attribute key.



4
5
6
# File 'lib/origen/generator/pattern_iterator.rb', line 4

def key
  @key
end

Instance Method Details

#enabled?(options) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/origen/generator/pattern_iterator.rb', line 50

def enabled?(options)
  options.keys.include?(key)
end

#invoke(options, &block) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/origen/generator/pattern_iterator.rb', line 6

def invoke(options, &block)
  if enabled?(options)
    @loop.call(options[key], &block)
  else
    yield
  end
end

#loop(&block) ⇒ Object



14
15
16
# File 'lib/origen/generator/pattern_iterator.rb', line 14

def loop(&block)
  @loop = block
end

#pattern_name(&block) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/origen/generator/pattern_iterator.rb', line 40

def pattern_name(&block)
  if block
    @pattern_name = block
  elsif @pattern_name
    @pattern_name
  else
    fail "pattern_name must be defined for iterator: #{key}"
  end
end

#setup(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/origen/generator/pattern_iterator.rb', line 18

def setup(&block)
  if block
    @setup = block
  elsif @setup
    @setup
  # Setup is optional for an iterator, return something to keep the caller happy
  else
    ->(arg) { arg }
  end
end

#startup(&block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/origen/generator/pattern_iterator.rb', line 29

def startup(&block)
  if block
    @startup = block
  elsif @startup
    @startup
  # Startup is optional for an iterator, return something to keep the caller happy
  else
    ->(_options, arg) { arg }
  end
end