Class: Jets::Lambda::Task
- Inherits:
-
Object
- Object
- Jets::Lambda::Task
- Defined in:
- lib/jets/lambda/task.rb
Constant Summary collapse
- @@lang_exts =
{ ruby: '.rb', python: '.py', node: '.js', }
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#iam_policy ⇒ Object
readonly
Returns the value of attribute iam_policy.
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#managed_iam_policy ⇒ Object
readonly
Returns the value of attribute managed_iam_policy.
-
#meth ⇒ Object
readonly
Returns the value of attribute meth.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #build_function_iam? ⇒ Boolean
- #full_handler(handler_function) ⇒ Object
-
#get_type ⇒ Object
The get_type method works for controller and job classes.
- #handler_base ⇒ Object
- #handler_path ⇒ Object
-
#initialize(class_name, meth, options = {}) ⇒ Task
constructor
A new instance of Task.
- #lang_ext ⇒ Object
- #name ⇒ Object
- #poly_src_path ⇒ Object
-
#replacements ⇒ Object
Useful for Jets::Resource late building.
Constructor Details
#initialize(class_name, meth, options = {}) ⇒ Task
Returns a new instance of Task.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/jets/lambda/task.rb', line 4 def initialize(class_name, meth, ={}) @class_name = class_name.to_s @meth = meth @options = @type = [:type] || get_type # controller, job, or function @resources = [:resources] || {} @properties = [:properties] || {} @iam_policy = [:iam_policy] @managed_iam_policy = [:managed_iam_policy] @lang = [:lang] || :ruby end |
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
2 3 4 |
# File 'lib/jets/lambda/task.rb', line 2 def class_name @class_name end |
#iam_policy ⇒ Object (readonly)
Returns the value of attribute iam_policy.
3 4 5 |
# File 'lib/jets/lambda/task.rb', line 3 def iam_policy @iam_policy end |
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
3 4 5 |
# File 'lib/jets/lambda/task.rb', line 3 def lang @lang end |
#managed_iam_policy ⇒ Object (readonly)
Returns the value of attribute managed_iam_policy.
3 4 5 |
# File 'lib/jets/lambda/task.rb', line 3 def managed_iam_policy @managed_iam_policy end |
#meth ⇒ Object (readonly)
Returns the value of attribute meth.
3 4 5 |
# File 'lib/jets/lambda/task.rb', line 3 def meth @meth end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
3 4 5 |
# File 'lib/jets/lambda/task.rb', line 3 def properties @properties end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
3 4 5 |
# File 'lib/jets/lambda/task.rb', line 3 def resources @resources end |
#type ⇒ Object
Returns the value of attribute type.
2 3 4 |
# File 'lib/jets/lambda/task.rb', line 2 def type @type end |
Instance Method Details
#build_function_iam? ⇒ Boolean
16 17 18 |
# File 'lib/jets/lambda/task.rb', line 16 def build_function_iam? !!(@iam_policy || @managed_iam_policy) end |
#full_handler(handler_function) ⇒ Object
67 68 69 |
# File 'lib/jets/lambda/task.rb', line 67 def full_handler(handler_function) "#{handler_base}.#{handler_function}" end |
#get_type ⇒ Object
The get_type method works for controller and job classes.
Usually able to get the type from the class name. Examples:
PostsController => controller
HardJob => job
However, for function types, we are not able to get the type for multiple of reasons. First, function types are allowed to be named with or without _function. Examples:
path => class => type
app/functions/hello.rb => Hello => function
app/functions/hello_function.rb => HelloFunction => function
The second reason is that functions are not regular ruby classes. Instead they are anonymous classes created with Class.new. When classes are created with Class.new the method_added hook has “” (blank string) as the self class name. We add the class_type to the task later on as we are constructing the class as part of the Class.new logic.
For controller and job standard ruby classes though it can easily be determinated as part of initialization. So we get the type for convenience then.
For anonymous function classes, we just set to nil and will later fix in FunctionConstructor.
Returns: “controller”, “job” or nil
61 62 63 64 65 |
# File 'lib/jets/lambda/task.rb', line 61 def get_type unless @class_name.empty? # when anonymous class is created with Class.new @class_name.underscore.split('_').last # controller, job or rule end end |
#handler_base ⇒ Object
75 76 77 78 79 |
# File 'lib/jets/lambda/task.rb', line 75 def handler_base base = "handlers/#{@type.pluralize}/#{@class_name.underscore}" base += "/#{@lang}" if @lang != :ruby base += "/#{@meth}" end |
#handler_path ⇒ Object
71 72 73 |
# File 'lib/jets/lambda/task.rb', line 71 def handler_path "#{handler_base}#{lang_ext}" end |
#lang_ext ⇒ Object
29 30 31 |
# File 'lib/jets/lambda/task.rb', line 29 def lang_ext @@lang_exts[@lang] end |
#name ⇒ Object
20 21 22 |
# File 'lib/jets/lambda/task.rb', line 20 def name @meth end |
#poly_src_path ⇒ Object
81 82 83 |
# File 'lib/jets/lambda/task.rb', line 81 def poly_src_path handler_path.sub("handlers/", "app/") end |
#replacements ⇒ Object
Useful for Jets::Resource late building.
87 88 89 90 91 |
# File 'lib/jets/lambda/task.rb', line 87 def replacements { namespace: "#{@class_name.gsub('::','')}#{@meth.to_s.camelize}", # camelized because used in not just keys but also values } end |