Sha256: fb7043308384f7c821e96f001b271ebea6364aa3b8e3ec9490e8d5c3882853d7

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

require_relative 'base'

module Legion
  module Extensions
    module Builder
      module Runners
        include Legion::Extensions::Builder::Base

        attr_reader :runners
        def build_runners
          @runners = {}
          lex_class.const_set('Runners', Module.new) unless lex_class.const_defined?('Runners')
          require_files(runner_files)
          build_runner_list
        end

        def build_runner_list
          runner_files.each do |file|
            runner_name = file.split('/').last.sub('.rb', '')
            runner_class = lex_class.to_s + '::Runners::' + runner_name.split('_').collect(&:capitalize).join
            loaded_runner = Kernel.const_get(runner_class)
            @runners[runner_name.to_sym] = {
              extension:       lex_class.to_s.downcase,
              extension_name:  extension_name,
              extension_class: lex_class,
              runner_name:     runner_name,
              runner_class:    runner_class,
              runner_path:     file,
              class_methods:   {}
            }

            loaded_runner.public_instance_methods(false).each do |runner_method|
              @runners[runner_name.to_sym][:class_methods][runner_method] = {
                args: loaded_runner.instance_method(runner_method).parameters
              }
            end

            loaded_runner.methods(false).each do |runner_method|
              @runners[runner_name.to_sym][:class_methods][runner_method] = {
                args: loaded_runner.method(runner_method).parameters
              }
            end
          end
        end

        def runner_files
          @runner_files ||= find_files('runners')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legionio-0.2.0 lib/legion/extensions/builders/runners.rb