Class: Jets::Lambda::FunctionConstructor

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/lambda/function_constructor.rb

Instance Method Summary collapse

Constructor Details

#initialize(code_path) ⇒ FunctionConstructor

Returns a new instance of FunctionConstructor.



31
32
33
# File 'lib/jets/lambda/function_constructor.rb', line 31

def initialize(code_path)
  @code_path = full(code_path)
end

Instance Method Details

#adjust_tasks(klass) ⇒ Object

For anonymous classes method_added during task registeration contains “” for the class name. We adjust it here.



50
51
52
53
54
55
56
57
# File 'lib/jets/lambda/function_constructor.rb', line 50

def adjust_tasks(klass)
  class_name = @code_path.sub(/.*app\/functions\//,'').sub(/\.rb$/, '')
  class_name = class_name.classify
  klass.tasks.each do |task|
    task.class_name = class_name
    task.type = "function"
  end
end

#buildObject



40
41
42
43
44
45
46
# File 'lib/jets/lambda/function_constructor.rb', line 40

def build
  code = IO.read(@code_path)
  function_klass = Class.new(Jets::Lambda::Function)
  function_klass.module_eval(code)
  adjust_tasks(function_klass)
  function_klass # assign this to a Constant for a pretty class name
end

#full(path) ⇒ Object



35
36
37
38
# File 'lib/jets/lambda/function_constructor.rb', line 35

def full(path)
  path = "#{Jets.root}#{path}" unless path.include?(Jets.root.to_s)
  path
end