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



22
23
24
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 22

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

#code_s3_keyObject



48
49
50
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 48

def code_s3_key
  Jets::Naming.code_s3_key
end

#environmentObject



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

def environment
  env = Jets.config.environment ? Jets.config.environment.to_h : {}
  jets_env_options = {JETS_ENV: Jets.env.to_s}
  jets_env_options[:JETS_ENV_EXTRA] = Jets.config.env_extra if Jets.config.env_extra
  env.deep_merge(jets_env_options)
end

#function_nameObject

Examples:

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


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

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



40
41
42
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 40

def handler
  handler_value(@task.meth)
end

#handler_value(meth) ⇒ Object



44
45
46
# File 'lib/jets/cfn/template_mappers/lambda_function_mapper.rb', line 44

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