Sha256: de464894030917bd6c6e9a9e4d7a130fa2d41d687ff049e068ba94ec0d94896d

Contents?: true

Size: 930 Bytes

Versions: 13

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module RakeFactory
  module Configurable
    def self.included(base)
      base.class_eval do
        attr_accessor(:configuration_block)
      end
    end

    def initialize(*args, &configuration_block)
      arity = method(:initialize).super_method.arity
      super(*args.slice(0, arity), &configuration_block)
      process_configuration_block(configuration_block)
    end

    def process_configuration_block(configuration_block)
      set_if_value_present(:configuration_block, configuration_block)
    end

    def invoke_configuration_block_on(target, args)
      return unless configuration_block

      params = args ? [target, args] : [target]
      configuration_block.call(
        *params.slice(0, configuration_block.arity)
      )
    end

    private

    def set_if_value_present(key, value)
      send("#{key}=", value) if respond_to?("#{key}=") && !value.nil?
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rake_factory-0.34.0.pre.2 lib/rake_factory/configurable.rb
rake_factory-0.34.0.pre.1 lib/rake_factory/configurable.rb
rake_factory-0.33.0 lib/rake_factory/configurable.rb
rake_factory-0.32.0.pre.6 lib/rake_factory/configurable.rb
rake_factory-0.32.0.pre.5 lib/rake_factory/configurable.rb
rake_factory-0.32.0.pre.4 lib/rake_factory/configurable.rb
rake_factory-0.32.0.pre.3 lib/rake_factory/configurable.rb
rake_factory-0.32.0.pre.2 lib/rake_factory/configurable.rb
rake_factory-0.32.0.pre.1 lib/rake_factory/configurable.rb
rake_factory-0.31.0 lib/rake_factory/configurable.rb
rake_factory-0.30.0.pre.8 lib/rake_factory/configurable.rb
rake_factory-0.30.0.pre.7 lib/rake_factory/configurable.rb
rake_factory-0.30.0.pre.6 lib/rake_factory/configurable.rb