Class: Jets::Builders::ShimVars::App

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/builders/shim_vars/app.rb

Instance Method Summary collapse

Methods inherited from Base

#bundled_zip, #rack_zip, #s3_bucket

Methods included from AwsServices

#apigateway, #aws_lambda, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts

Methods included from AwsServices::StackStatus

#lookup, #stack_exists?, #stack_in_progress?

Methods included from AwsServices::GlobalMemoist

included

Constructor Details

#initialize(path) ⇒ App

Allow user to specify relative or full path. The right path gets used internally. Example paths:

app/controllers/posts_controller.rb
app/jobs/hard_job.rb
/tmp/jets/build/app_root/app/jobs/hard_job.rb
/tmp/jets/build/app_root/app/functions/hello.rb


21
22
23
24
# File 'lib/jets/builders/shim_vars/app.rb', line 21

def initialize(path)
  @full_path = full(path)
  @relative_path = relative(path)
end

Instance Method Details

#dest_pathObject

Example return: “handlers/controllers/posts.js” TODO: rename this to dest_path or something better now since using native ruby



73
74
75
76
# File 'lib/jets/builders/shim_vars/app.rb', line 73

def dest_path
  @relative_path
    .sub("app", "handlers")
end

#full(path) ⇒ Object



26
27
28
29
# File 'lib/jets/builders/shim_vars/app.rb', line 26

def full(path)
  path = "#{Jets.root}/#{path}" unless path.starts_with?("/")
  path
end

#functionsObject

Returns the public methods of the child_class. Example: [:create, :update]



50
51
52
# File 'lib/jets/builders/shim_vars/app.rb', line 50

def functions
  klass.lambda_functions
end

#handler_for(meth) ⇒ Object

This gets called in the node shim js template IE handlers/controllers/posts_controller.index



65
66
67
68
69
# File 'lib/jets/builders/shim_vars/app.rb', line 65

def handler_for(meth)
  # possibly not include _function
  underscored_name = @relative_path.sub(%r{app/(\w+)/},'').sub('.rb','')
  "handlers/#{process_type.pluralize}/#{underscored_name}.#{meth}"
end

#klassObject

Examples: PostsController, HardJob, Hello, HelloFunction



55
56
57
# File 'lib/jets/builders/shim_vars/app.rb', line 55

def klass
  @klass ||= Jets::Klass.from_path(@relative_path)
end

#lang(meth) ⇒ Object



59
60
61
# File 'lib/jets/builders/shim_vars/app.rb', line 59

def lang(meth)
  klass.tasks.find
end

#process_typeObject

process_type is key, it will either “controller” or “job”. It is used to deduce klass, etc. We get the process_type from the path. Example paths:

app/controllers/posts_controller.rb
app/jobs/hard_job.rb


44
45
46
# File 'lib/jets/builders/shim_vars/app.rb', line 44

def process_type
  @relative_path.split('/')[1].singularize # controller or job
end

#relative(path) ⇒ Object



31
32
33
34
35
36
# File 'lib/jets/builders/shim_vars/app.rb', line 31

def relative(path)
  full_path = full(path)
  full_path.sub("#{Jets.root}/", "")
           .sub(/.*internal\/app/, "app")

end