class FunctionWrapper

Attributes

file_path[RW]
function_class[RW]

Public Class Methods

new(file_path) click to toggle source
# File eezee-3-aka-game-x-engine/managables/programs/game_aided_manufacturing/gam.rb, line 59
def initialize(file_path)
  @file_path = file_path
  @abstract_syntax_tree = RubyVM::AbstractSyntaxTree
    .parse_file(file_path)

  get_command_class_name
end

Public Instance Methods

command_class_name() click to toggle source
# File eezee-3-aka-game-x-engine/managables/programs/game_aided_manufacturing/gam.rb, line 89
def command_class_name
  @command_class_name
end
get_command_class_name() click to toggle source
# File eezee-3-aka-game-x-engine/managables/programs/game_aided_manufacturing/gam.rb, line 67
def get_command_class_name
  # if class is deeper than first level, let's invent Enumerable#recursive_find
  @command_class_node = @abstract_syntax_tree.recursive_find(:children) do |child|
    child.class == RubyVM::AbstractSyntaxTree::Node && child.type == :CLASS
  end

  @command_class_name = @command_class_node
    .children
    .first
    .pretty_print_inspect
    .match(/:(\w+)\)\Z/)[1]
end
new_command_instance(gam_main_instance) click to toggle source
# File eezee-3-aka-game-x-engine/managables/programs/game_aided_manufacturing/gam.rb, line 80
def new_command_instance(gam_main_instance)
  load(@file_path)

  # SEC-TODO: fix eval, especially when considering downloadable functions
  command_instance = eval(@command_class_name).new(gam_main_instance)

  return command_instance
end