Sha256: 9936bc16dcea35d696bfdd56c8252094c48333bf94fbb3251484ba1a2be59693

Contents?: true

Size: 2 KB

Versions: 45

Compression:

Stored size: 2 KB

Contents

# Subclasses of BaseGuessor must implement interface:
#   detect_class_name
#   method_name
#   error_message
#
class Jets::Commands::Call
  class BaseGuesser
    include Jets::AwsServices

    # provided_function_name:
    #   admin/related_pages_controller-list_all
    #   admin-related-pages-controller-list-all
    def initialize(provided_function_name)
      @provided_function_name = provided_function_name
    end

    def class_name
      return @class_name if @detection_ran

      @class_name = detect_class_name
      @detection_ran = true
      @class_name
    end

    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

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

        resources = stack_resources(app_stack_arn)
        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

    # Class variable caches
    @@stack_resources = {}
    def stack_resources(stack_name)
      @@stack_resources[stack_name] ||= cfn.describe_stack_resources(stack_name: stack_name).stack_resources
    end

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

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
jets-2.3.14 lib/jets/commands/call/base_guesser.rb
jets-2.3.13 lib/jets/commands/call/base_guesser.rb
jets-2.3.12 lib/jets/commands/call/base_guesser.rb
jets-2.3.11 lib/jets/commands/call/base_guesser.rb
jets-2.3.10 lib/jets/commands/call/base_guesser.rb
jets-2.3.9 lib/jets/commands/call/base_guesser.rb
jets-2.3.8 lib/jets/commands/call/base_guesser.rb
jets-2.3.7 lib/jets/commands/call/base_guesser.rb
jets-2.3.6 lib/jets/commands/call/base_guesser.rb
jets-2.3.5 lib/jets/commands/call/base_guesser.rb
jets-2.3.4 lib/jets/commands/call/base_guesser.rb
jets-2.3.3 lib/jets/commands/call/base_guesser.rb
jets-2.3.2 lib/jets/commands/call/base_guesser.rb
jets-2.3.1 lib/jets/commands/call/base_guesser.rb
jets-2.3.0 lib/jets/commands/call/base_guesser.rb
jets-2.2.5 lib/jets/commands/call/base_guesser.rb
jets-2.2.4 lib/jets/commands/call/base_guesser.rb
jets-2.2.3 lib/jets/commands/call/base_guesser.rb
jets-2.2.2 lib/jets/commands/call/base_guesser.rb
jets-2.2.1 lib/jets/commands/call/base_guesser.rb