Sha256: 8c895ba21883ede34548fcfef8da5158e66ff1fcfee2140b2765cabd9a0c5407

Contents?: true

Size: 792 Bytes

Versions: 2

Compression:

Stored size: 792 Bytes

Contents

module Pessimize
  class DSL
    def initialize(collector)
      @collector = collector
      @current_groups = nil
    end

    def parse(definition)
      instance_eval definition, __FILE__, __LINE__
    end

    def method_missing(name, *args)
      collector.add_declaration(name.to_s, *args)
    end

  protected
    attr_reader :collector
    attr_accessor :current_groups

    def gem(*args)
      if current_groups
        current_groups.each do |group|
          collector.add_grouped_gem(group, *args)
        end
      else
        collector.add_gem(*args)
      end
    end

    def group(group, *others)
      groups = [group].flatten + others
      if block_given?
        self.current_groups = groups
        yield
        self.current_groups = nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pessimize-0.1.0 lib/pessimize/dsl.rb
pessimize-0.0.3 lib/pessimize/dsl.rb