Class: Jets::Stack::Function
- Inherits:
-
Object
- Object
- Jets::Stack::Function
- Extended by:
- Memoist
- Defined in:
- lib/jets/stack/function.rb
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #base_search_expression ⇒ Object
-
#handler_dest ⇒ Object
Relative path app/shared/functions/kevin.py => handlers/shared/functions/kevin.py.
-
#initialize(template) ⇒ Function
constructor
A new instance of Function.
-
#internal? ⇒ Boolean
Internal flag is mainly used to disable WARN messages.
- #internal_search_expression ⇒ Object
- #lang ⇒ Object
- #lang_map ⇒ Object
- #meth ⇒ Object
- #search_expression ⇒ Object
- #source_file ⇒ Object
Constructor Details
#initialize(template) ⇒ Function
Returns a new instance of Function.
6 7 8 |
# File 'lib/jets/stack/function.rb', line 6 def initialize(template) @template = template end |
Instance Attribute Details
#template ⇒ Object (readonly)
Returns the value of attribute template.
5 6 7 |
# File 'lib/jets/stack/function.rb', line 5 def template @template end |
Instance Method Details
#base_search_expression ⇒ Object
50 51 52 53 54 55 |
# File 'lib/jets/stack/function.rb', line 50 def base_search_expression attributes = @template.values.first handler = attributes['Properties']['Handler'] handler.split('.')[0..-2].join('.') + '.*' # search_expression # Example: handlers/shared/functions/jets/s3_bucket_config.* end |
#handler_dest ⇒ Object
Relative path app/shared/functions/kevin.py => handlers/shared/functions/kevin.py
64 65 66 67 |
# File 'lib/jets/stack/function.rb', line 64 def handler_dest return unless source_file source_file.sub(%r{.*/app/}, "handlers/") end |
#internal? ⇒ Boolean
Internal flag is mainly used to disable WARN messages
58 59 60 |
# File 'lib/jets/stack/function.rb', line 58 def internal? !!Dir.glob(internal_search_expression).first end |
#internal_search_expression ⇒ Object
45 46 47 48 |
# File 'lib/jets/stack/function.rb', line 45 def internal_search_expression internal = File.("../internal", File.dirname(__FILE__)) base_search_expression.sub('handlers/shared/', "#{internal}/app/shared/") end |
#lang ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jets/stack/function.rb', line 16 def lang return if internal? if source_file # Detect language from file extension ext = File.extname(source_file).sub(/^\./,'').to_sym lang_map[ext] else puts "WARN: Unable to find a source file for function. Looked at: #{search_expression}".color(:yellow) end end |
#lang_map ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/jets/stack/function.rb', line 28 def lang_map { rb: :ruby, py: :python, js: :node, } end |
#meth ⇒ Object
10 11 12 13 14 |
# File 'lib/jets/stack/function.rb', line 10 def meth attributes = @template.values.first handler = attributes['Properties']['Handler'] handler.split('.').last end |
#search_expression ⇒ Object
41 42 43 |
# File 'lib/jets/stack/function.rb', line 41 def search_expression base_search_expression.sub('handlers/shared/', "#{Jets.root}/app/shared/") end |
#source_file ⇒ Object
36 37 38 |
# File 'lib/jets/stack/function.rb', line 36 def source_file Dir.glob(search_expression).first end |