Sha256: e06f49c70382e61594fcce5c27b88c0e17ec75c1c96f08bff4287ec104335eea

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

require 'set'

module Squib

  # DSL method. See http://squib.readthedocs.io
  def enable_build_globally group
    groups = (ENV['SQUIB_BUILD'] ||= '').split(',')
    ENV['SQUIB_BUILD'] = (groups << group).uniq.join(',')
  end
  module_function :enable_build_globally

  # DSL method. See http://squib.readthedocs.io
  def disable_build_globally group
    groups = (ENV['SQUIB_BUILD'] ||= '').split(',')
    groups.delete(group.to_s)
    ENV['SQUIB_BUILD'] = groups.uniq.join(',')
  end
  module_function :disable_build_globally

  class Deck

    # DSL method. See http://squib.readthedocs.io
    def build grp = :all, &block
      raise 'Please provide a block' unless block_given?
      block.yield if build_groups.include? grp
    end

    # DSL method. See http://squib.readthedocs.io
    def enable_build grp
      build_groups # make sure it's initialized
      @build_groups << grp
    end

    # DSL method. See http://squib.readthedocs.io
    def disable_build grp
      build_groups # make sure it's initialized
      @build_groups.delete grp
    end

    # DSL method. See http://squib.readthedocs.io
    def build_groups
      @build_groups ||= Set.new.add(:all)
    end

    # Not a DSL method, but initialized from Deck.new
    def enable_groups_from_env!
      return if ENV['SQUIB_BUILD'].nil?
      ENV['SQUIB_BUILD'].split(',').each do |grp|
        enable_build grp.strip.to_sym
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
squib-0.19.0 lib/squib/dsl/groups.rb
squib-0.19.0b lib/squib/dsl/groups.rb
squib-0.19.0a lib/squib/dsl/groups.rb
squib-0.15.2 lib/squib/api/groups.rb
squib-0.15.1 lib/squib/api/groups.rb
squib-0.14.2 lib/squib/api/groups.rb