Module: Legion::Extensions::Builder::Base

Included in:
Actors, Helpers, Runners
Defined in:
lib/legion/extensions/builders/base.rb

Instance Method Summary collapse

Instance Method Details

#const_defined_two?(item, root = Kernel) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/legion/extensions/builders/base.rb', line 19

def const_defined_two?(item, root = Kernel)
  root.const_defined?(item.to_s)
end

#define_constant_two(item, root: Kernel, type: Module) ⇒ Object



23
24
25
26
27
# File 'lib/legion/extensions/builders/base.rb', line 23

def define_constant_two(item, root: Kernel, type: Module)
  return true if root.const_defined?(item)

  root.const_set(item.to_s, type.new)
end

#define_get(item, root: Kernel, type: Module) ⇒ Object



29
30
31
32
# File 'lib/legion/extensions/builders/base.rb', line 29

def define_get(item, root: Kernel, type: Module)
  define_constant_two(item, root: root, type: type) if const_defined_two?(item, root: root)
  root.const_get(item)
end

#find_files(name, path = extension_path) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/legion/extensions/builders/base.rb', line 5

def find_files(name, path = extension_path)
  files = []
  return files unless Dir.exist? "#{path}/#{name}"

  Dir["#{path}/#{name}/*.rb"].each do |file|
    files.push(file)
  end
  files
end

#require_files(files) ⇒ Object



15
16
17
# File 'lib/legion/extensions/builders/base.rb', line 15

def require_files(files)
  files.each { |file| require file }
end