Sha256: f6f0b8934ca666faad41bbfd30ec94dc14b9539cce1e98f41ef288461258183a

Contents?: true

Size: 1.7 KB

Versions: 185

Compression:

Stored size: 1.7 KB

Contents

# Guesser transforms the user provided function name to the actual lambda
# function name.
#
# Allow for variety of different inputs to work:
# Simple:
#   admin/pages_controller-index => admin-pages_controller-index
#   admin-pages_controller-index => admin-pages_controller-index
#
# Complex, requires detecting the right class name:
#   admin/related_pages_controller-list_all
#   admin-related-pages-controller-list-all
#
# All still result in: admin-related_pages_controller-index
#
# The detection process follows. Given worse case:
#   admin-related-pages-controller-list-all
#
# Know that the action comes after controller, try:
#   AdminRelatedPagesController
#   Admin::RelatedPagesController <= found stop guessing
#
# admin/related_pages_controller <= underscored
# admin/related_pages_controller-list_all <= add action back on
# admin-related_pages_controller-list_all <= gsub / - DONE
#
# Now we're at a point where we can start guessing
# function_name = detect_function_name(function_name)
class Jets::Commands::Call
  class Guesser
    delegate :class_name, :method_name, :error_message, :function_name,
      to: :delegate_guesser

    # Example of 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 delegate_guesser
      @delegate_guesser ||= if @provided_function_name =~ /[-_](controller|job|rule)/
                              AutoloadGuesser.new(@provided_function_name)
                            else
                              AnonymousGuesser.new(@provided_function_name)
                            end
    end
  end
end

Version data entries

185 entries across 185 versions & 4 rubygems

Version Path
jets-3.0.6 lib/jets/commands/call/guesser.rb
jets-3.0.5 lib/jets/commands/call/guesser.rb
jets-3.0.4 lib/jets/commands/call/guesser.rb
jets-3.0.3 lib/jets/commands/call/guesser.rb
jets-2.3.19 lib/jets/commands/call/guesser.rb
jets-3.0.2 lib/jets/commands/call/guesser.rb
jets-3.0.1 lib/jets/commands/call/guesser.rb
jets-3.0.0 lib/jets/commands/call/guesser.rb
jets-2.3.18 lib/jets/commands/call/guesser.rb
jets-2.3.17 lib/jets/commands/call/guesser.rb
jets-2.3.16 lib/jets/commands/call/guesser.rb
jets-2.3.15 lib/jets/commands/call/guesser.rb
jets-2.3.14 lib/jets/commands/call/guesser.rb
jets-2.3.13 lib/jets/commands/call/guesser.rb
jets-2.3.12 lib/jets/commands/call/guesser.rb
jets-2.3.11 lib/jets/commands/call/guesser.rb
jets-2.3.10 lib/jets/commands/call/guesser.rb
jets-2.3.9 lib/jets/commands/call/guesser.rb
jets-2.3.8 lib/jets/commands/call/guesser.rb
jets-2.3.7 lib/jets/commands/call/guesser.rb