Class: Jets::Cfn::TemplateMappers::LambdaFunctionMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/cfn/template_mappers/lambda_function_mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ LambdaFunctionMapper

Returns a new instance of LambdaFunctionMapper.



3
4
5
6
7
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 3

def initialize(task)
  @task = task
  @app_class = task.class_name.to_s
  # @app_class examples: PostsController, HardJob, Hello, HelloFunction
end

Instance Method Details

#class_actionObject

Example: PostsControllerIndex or SleepJobPerform



20
21
22
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 20

def class_action
  "#{@app_class}_#{@task.meth}".camelize
end

#code_s3_keyObject



46
47
48
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 46

def code_s3_key
  Jets::Naming.code_s3_key
end

#environmentObject



14
15
16
17
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 14

def environment
  env = Jets.config.environment ? Jets.config.environment.to_h : {}
  env.deep_merge(JETS_ENV: Jets.env.to_s)
end

#function_nameObject

Examples:

"#{Jets.config.project_namespace}-sleep_job-perform"
"demo-dev-sleep_job-perform"


27
28
29
30
31
32
33
34
35
36
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 27

def function_name
  # Example values:
  #   @app_class: admin/pages_controller
  #   @task.meth: index
  method = @app_class.underscore
  # method: admin/pages_controller
  method = method.sub('/','-') + "-#{@task.meth}"
  # method: admin-pages_controller-index
  "#{Jets.config.project_namespace}-#{method}"
end

#handlerObject



38
39
40
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 38

def handler
  handler_value(@task.meth)
end

#handler_value(meth) ⇒ Object



42
43
44
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 42

def handler_value(meth)
  "handlers/#{@task.type.pluralize}/#{@app_class.underscore}.#{meth}"
end

#logical_idObject

Example: SleepJobPerformLambdaFunction



10
11
12
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 10

def logical_id
  "#{class_action}LambdaFunction".gsub('::','')
end