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 = "#{Jets.root}/#{code_path}"
end

Instance Method Details

#adjust_tasks(klass) ⇒ Object

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



45
46
47
48
49
50
51
52
# File 'lib/jets/lambda/function_constructor.rb', line 45

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

#buildObject



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

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