Class: Jets::Cfn::TemplateBuilders::FunctionProperties::BaseBuilder
- Inherits:
-
Object
- Object
- Jets::Cfn::TemplateBuilders::FunctionProperties::BaseBuilder
- Defined in:
- lib/jets/cfn/template_builders/function_properties/base_builder.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#class_properties ⇒ Object
Class properties example:.
- #env_file_properties ⇒ Object
-
#finalize_properties!(props) ⇒ Object
Add properties managed by Jets.
-
#full_handler(props) ⇒ Object
Ensure that the handler path is normalized.
-
#function_properties ⇒ Object
Function properties example:.
- #get_runtime(props) ⇒ Object
-
#global_properties ⇒ Object
Global properties example: jets defaults are in jets/default/application.rb.
-
#initialize(task) ⇒ BaseBuilder
constructor
A new instance of BaseBuilder.
- #map ⇒ Object
- #properties ⇒ Object
Constructor Details
#initialize(task) ⇒ BaseBuilder
Returns a new instance of BaseBuilder.
10 11 12 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 10 def initialize(task) @task = task end |
Instance Method Details
#class_properties ⇒ Object
Class properties example:
class PostsController < ApplicationController
class_timeout 22
...
end
82 83 84 85 86 87 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 82 def class_properties # klass is PostsController, HardJob, GameRule, Hello or HelloFunction klass = Jets::Klass.from_task(@task) class_properties = klass.class_properties Pascalize.pascalize(class_properties.deep_stringify_keys) end |
#env_file_properties ⇒ Object
100 101 102 103 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 100 def env_file_properties env_vars = Jets::Dotenv.load!(true) Pascalize.pascalize(environment: { variables: env_vars }) end |
#finalize_properties!(props) ⇒ Object
Add properties managed by Jets.
27 28 29 30 31 32 33 34 35 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 27 def finalize_properties!(props) handler = full_handler(props) runtime = get_runtime(props) props.merge!( "FunctionName" => map.function_name, "Handler" => handler, "Runtime" => runtime, ) end |
#full_handler(props) ⇒ Object
Ensure that the handler path is normalized.
42 43 44 45 46 47 48 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 42 def full_handler(props) if props["Handler"] map.handler_value(props["Handler"]) else default_handler end end |
#function_properties ⇒ Object
Function properties example:
class PostsController < ApplicationController
timeout 18
def index
...
end
96 97 98 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 96 def function_properties Pascalize.pascalize(@task.properties.deep_stringify_keys) end |
#get_runtime(props) ⇒ Object
37 38 39 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 37 def get_runtime(props) props["Runtime"] || default_runtime end |
#global_properties ⇒ Object
Global properties example: jets defaults are in jets/default/application.rb. Your application’s default config/application.rb then get used. Example:
Jets.application.configure do
config.function = ActiveSupport::OrderedOptions.new
config.function.timeout = 10
config.function.runtime = "nodejs8.10"
config.function.memory_size = 3008
end
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 60 def global_properties baseline = { Code: { S3Bucket: {Ref: "S3Bucket"}, # from child stack S3Key: map.code_s3_key }, Role: { Ref: "IamRole" }, Environment: { Variables: map.environment }, }.deep_stringify_keys app_config_props = Jets.application.config.function.to_h app_config_props = Pascalize.pascalize(app_config_props.deep_stringify_keys) baseline.deep_merge(app_config_props) end |
#map ⇒ Object
14 15 16 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 14 def map @map ||= Jets::Cfn::TemplateMappers::LambdaFunctionMapper.new(@task) end |
#properties ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/jets/cfn/template_builders/function_properties/base_builder.rb', line 18 def properties props = env_file_properties .deep_merge(global_properties) .deep_merge(class_properties) .deep_merge(function_properties) finalize_properties!(props) end |