Sha256: b5f2d1c6ecb59b8bb59c255d6bb93523e7bc1350bc99eb8196b39dc581b5a254

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

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}::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:   {}
            }

            if settings.key?(:runners) && settings[:runners].key?(runner_name.to_sym)
              @runners[runner_name.to_sym][:desc] = settings[:runners][runner_name.to_sym][:desc]
            end

            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

5 entries across 5 versions & 1 rubygems

Version Path
legionio-0.4.3 lib/legion/extensions/builders/runners.rb
legionio-0.4.2 lib/legion/extensions/builders/runners.rb
legionio-0.4.1 lib/legion/extensions/builders/runners.rb
legionio-0.4.0 lib/legion/extensions/builders/runners.rb
legionio-0.3.2 lib/legion/extensions/builders/runners.rb