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
-
#handler_dest ⇒ Object
Relative path app/shared/functions/kevin.py => handlers/shared/functions/kevin.py.
-
#initialize(template) ⇒ Function
constructor
A new instance of Function.
- #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
#handler_dest ⇒ Object
Relative path app/shared/functions/kevin.py => handlers/shared/functions/kevin.py
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jets/stack/function.rb', line 48 def handler_dest return unless source_file dest = source_file.sub(%r{.*/app/}, "handlers/") if lang == :ruby filename = dest.split('.').first filename + '.js' # change extension to .js because ruby uses a node shim else dest end end |
#lang ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/jets/stack/function.rb', line 16 def lang 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}".colorize(:yellow) end end |
#lang_map ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/jets/stack/function.rb', line 26 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
39 40 41 42 43 44 |
# File 'lib/jets/stack/function.rb', line 39 def search_expression attributes = @template.values.first handler = attributes['Properties']['Handler'] search_expression = handler.split('.')[0..-2].join('.') + '.*' search_expression.sub('handlers/shared/', "#{Jets.root}app/shared/") end |
#source_file ⇒ Object
34 35 36 |
# File 'lib/jets/stack/function.rb', line 34 def source_file Dir.glob(search_expression).first end |