Sha256: 609ff641bca45c602cafb85cc9d859edc8ff44cc9466859a7a7984798a4e224e

Contents?: true

Size: 876 Bytes

Versions: 4

Compression:

Stored size: 876 Bytes

Contents

# frozen_string_literal: true

require_relative 'parameter_set'

module RakeFactory
  module Parameters
    def self.included(base)
      base.extend(ClassMethods)
    end

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

    def parameter_values
      self.class.parameter_set.read_from(self)
    end

    def setup_parameter_defaults
      self.class.parameter_set.apply_defaults_to(self)
    end

    def check_parameter_requirements
      self.class.parameter_set.enforce_requirements_on(self)
    end

    module ClassMethods
      def parameter_set
        @parameter_set ||= ParameterSet.new
      end

      def parameter(name, options = {})
        parameter = parameter_set.add(name, options)
        parameter.define_on(self)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rake_factory-0.34.0.pre.2 lib/rake_factory/parameters.rb
rake_factory-0.34.0.pre.1 lib/rake_factory/parameters.rb
rake_factory-0.33.0 lib/rake_factory/parameters.rb
rake_factory-0.32.0.pre.6 lib/rake_factory/parameters.rb