Sha256: fb0ecb2d4f1aa86bf602163da52abeea8176006a64d132f7d8c0d021eeaf39a4

Contents?: true

Size: 1.12 KB

Versions: 207

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

207 entries across 207 versions & 1 rubygems

Version Path
origen-0.7.38 lib/origen/generator/pattern_iterator.rb
origen-0.7.37 lib/origen/generator/pattern_iterator.rb
origen-0.7.36 lib/origen/generator/pattern_iterator.rb
origen-0.7.35 lib/origen/generator/pattern_iterator.rb
origen-0.7.34 lib/origen/generator/pattern_iterator.rb
origen-0.7.33 lib/origen/generator/pattern_iterator.rb
origen-0.7.32 lib/origen/generator/pattern_iterator.rb
origen-0.7.31 lib/origen/generator/pattern_iterator.rb
origen-0.7.30 lib/origen/generator/pattern_iterator.rb
origen-0.7.29 lib/origen/generator/pattern_iterator.rb
origen-0.7.28 lib/origen/generator/pattern_iterator.rb
origen-0.7.27 lib/origen/generator/pattern_iterator.rb
origen-0.7.26 lib/origen/generator/pattern_iterator.rb
origen-0.7.25 lib/origen/generator/pattern_iterator.rb
origen-0.7.24 lib/origen/generator/pattern_iterator.rb
origen-0.7.23 lib/origen/generator/pattern_iterator.rb
origen-0.7.22 lib/origen/generator/pattern_iterator.rb
origen-0.7.21 lib/origen/generator/pattern_iterator.rb
origen-0.7.20 lib/origen/generator/pattern_iterator.rb
origen-0.7.19 lib/origen/generator/pattern_iterator.rb