Class: Jets::Commands::Call::BaseGuesser

Inherits:
Object
  • Object
show all
Includes:
AwsServices
Defined in:
lib/jets/commands/call/base_guesser.rb

Direct Known Subclasses

AnonymousGuesser, AutoloadGuesser

Constant Summary collapse

@@stack_resources =

Class variable caches

{}
@@parent_stack =
nil

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_lambda, #aws_options, #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(provided_function_name) ⇒ BaseGuesser

provided_function_name:

admin/related_pages_controller-list_all
admin-related-pages-controller-list-all


13
14
15
# File 'lib/jets/commands/call/base_guesser.rb', line 13

def initialize(provided_function_name)
  @provided_function_name = provided_function_name
end

Instance Method Details

#class_nameObject



17
18
19
20
21
22
23
# File 'lib/jets/commands/call/base_guesser.rb', line 17

def class_name
  return @class_name if @detection_ran

  @class_name = detect_class_name
  @detection_ran = true
  @class_name
end

#function_nameObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/jets/commands/call/base_guesser.rb', line 25

def function_name
  # Strip the project namespace if the user has accidentally added it
  # Since we're going to automatically add it no matter what at the end
  # and dont want the namespace to be included twice
  @provided_function_name = @provided_function_name.sub("#{Jets.config.project_namespace}-", "")

  code_path = class_name.underscore.gsub('/','-')
  function_name = [Jets.config.project_namespace, code_path, method_name].join('-')
  generated_function_name(function_name)
end

#generated_function_name(function_name) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jets/commands/call/base_guesser.rb', line 36

def generated_function_name(function_name)
  if function_name.size > Jets::MAX_FUNCTION_NAME_SIZE # name generated by CloudFormation
    logical_id = @class_name.gsub('::','')

    parent_resources = stack_resources(parent_stack.stack_id)
    app_stack = parent_resources.find { |s| s.logical_resource_id == logical_id }

    resources = stack_resources(app_stack.physical_resource_id)
    resource = resources.find { |r| r.logical_resource_id == method_name.camelize + "LambdaFunction" } # method_name only contains the method
    resource.physical_resource_id # actual function name
  else
    function_name
  end
end

#parent_stackObject



58
59
60
# File 'lib/jets/commands/call/base_guesser.rb', line 58

def parent_stack
  @@parent_stack ||= cfn.describe_stacks(stack_name: Jets::Naming.parent_stack_name).stacks.first
end

#stack_resources(stack_name) ⇒ Object



53
54
55
# File 'lib/jets/commands/call/base_guesser.rb', line 53

def stack_resources(stack_name)
  @@stack_resources[stack_name] ||= cfn.describe_stack_resources(stack_name: stack_name).stack_resources
end