Sha256: fb0ecb2d4f1aa86bf602163da52abeea8176006a64d132f7d8c0d021eeaf39a4

Contents?: true

Size: 1.12 KB

Versions: 206

Compression:

Stored size: 1.12 KB

Contents

module Origen
  class Generator
    class PatternIterator
      attr_accessor :key

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

      def loop(&block)
        @loop = block
      end

      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

      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

      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

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

Version data entries

206 entries across 206 versions & 1 rubygems

Version Path
origen-0.60.18 lib/origen/generator/pattern_iterator.rb
origen-0.60.17 lib/origen/generator/pattern_iterator.rb
origen-0.60.16 lib/origen/generator/pattern_iterator.rb
origen-0.60.14 lib/origen/generator/pattern_iterator.rb
origen-0.60.13 lib/origen/generator/pattern_iterator.rb
origen-0.60.12 lib/origen/generator/pattern_iterator.rb
origen-0.60.11 lib/origen/generator/pattern_iterator.rb
origen-0.60.10 lib/origen/generator/pattern_iterator.rb
origen-0.60.9 lib/origen/generator/pattern_iterator.rb
origen-0.60.8 lib/origen/generator/pattern_iterator.rb
origen-0.60.7 lib/origen/generator/pattern_iterator.rb
origen-0.60.6 lib/origen/generator/pattern_iterator.rb
origen-0.60.5 lib/origen/generator/pattern_iterator.rb
origen-0.60.4 lib/origen/generator/pattern_iterator.rb
origen-0.60.3 lib/origen/generator/pattern_iterator.rb
origen-0.60.2 lib/origen/generator/pattern_iterator.rb
origen-0.60.1 lib/origen/generator/pattern_iterator.rb
origen-0.60.0 lib/origen/generator/pattern_iterator.rb
origen-0.59.8 lib/origen/generator/pattern_iterator.rb
origen-0.59.7 lib/origen/generator/pattern_iterator.rb