Sha256: d8ab3f97e4f3e43b2217a346e729877390c0f09f6c04285218530e1b359161fd

Contents?: true

Size: 710 Bytes

Versions: 3

Compression:

Stored size: 710 Bytes

Contents

# frozen_string_literal: true

module Rake
  module Funnel
    module Support
      class Patch
        def initialize(context = nil)
          @context = context

          yield self if block_given?
        end

        def setup(&block)
          @setup = block
        end

        def reset(&block)
          @reset = block
        end

        def apply!
          return self if @memo

          @memo = (@setup || noop).call(@context)

          self
        end

        def revert!
          return self unless @memo

          (@reset || noop).call(@memo)
          @memo = nil

          self
        end

        private

        def noop
          proc {}
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rake-funnel-0.24.0 lib/rake/funnel/support/patch.rb
rake-funnel-0.23.0 lib/rake/funnel/support/patch.rb
rake-funnel-0.22.3 lib/rake/funnel/support/patch.rb