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-1.5.0 lib/jets/commands/call/guesser.rb
jets-1.4.11 lib/jets/commands/call/guesser.rb
jets-1.4.10 lib/jets/commands/call/guesser.rb
jets-1.4.9 lib/jets/commands/call/guesser.rb
jets-1.4.8 lib/jets/commands/call/guesser.rb
jets-1.4.7 lib/jets/commands/call/guesser.rb
jets-1.4.6 lib/jets/commands/call/guesser.rb
jets-1.4.5 lib/jets/commands/call/guesser.rb
jets-1.4.4 lib/jets/commands/call/guesser.rb
jets-1.4.3 lib/jets/commands/call/guesser.rb
jets-1.4.2 lib/jets/commands/call/guesser.rb
jets-1.4.1 lib/jets/commands/call/guesser.rb
jets-1.4.0 lib/jets/commands/call/guesser.rb
jets-1.3.9 lib/jets/commands/call/guesser.rb
jets-1.3.8 lib/jets/commands/call/guesser.rb
jets-1.3.7 lib/jets/commands/call/guesser.rb
jets-1.3.6 lib/jets/commands/call/guesser.rb
jets-1.3.5 lib/jets/commands/call/guesser.rb
jets-1.3.4 lib/jets/commands/call/guesser.rb
jets-1.3.3 lib/jets/commands/call/guesser.rb