Sha256: 3f6284568915d18b0e70a5bc9aff7fbf8c4d4acd24d9b78690758850a4fe1717

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require_relative 'values'

module RakeFactory
  class ParameterView
    attr_reader(:task)

    def initialize(target, reader_class, writer_class, runtime_arguments)
      instance_eval do
        define_reader_methods(target, reader_class)
        define_writer_methods(target, writer_class, runtime_arguments)
      end
      self.class.instance_eval do
        define_singleton_method :parameter_set do
          reader_class.parameter_set
        end
      end
    end

    private

    def define_reader_methods(target, reader_class)
      reader_class.parameter_set.each do |parameter|
        define_reader_method(target, parameter)
      end
    end

    def define_reader_method(target, parameter)
      define_singleton_method parameter.reader_method do
        target.send(parameter.reader_method)
      end
    end

    def define_writer_methods(target, writer_class, runtime_arguments)
      writer_class.parameter_set.each do |parameter|
        define_writer_method(target, parameter, runtime_arguments)
      end
    end

    def define_writer_method(target, parameter, runtime_arguments)
      return unless parameter.configurable?

      define_singleton_method parameter.writer_method do |value|
        if target.respond_to?(parameter.writer_method)
          target.send(
            parameter.writer_method,
            Values.resolve(value).append_argument(runtime_arguments)
          )
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rake_factory-0.32.0.pre.2 lib/rake_factory/parameter_view.rb
rake_factory-0.32.0.pre.1 lib/rake_factory/parameter_view.rb
rake_factory-0.31.0 lib/rake_factory/parameter_view.rb
rake_factory-0.30.0.pre.8 lib/rake_factory/parameter_view.rb
rake_factory-0.30.0.pre.7 lib/rake_factory/parameter_view.rb
rake_factory-0.30.0.pre.6 lib/rake_factory/parameter_view.rb