Module: Pragma::Rails::ResourceController::ClassMethods

Defined in:
lib/pragma/rails/resource_controller.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#operation?(operation_name) ⇒ Boolean

Returns whether the provided operation is supported on this resource.

Parameters:

  • operation_name (Symbol)

    name of the operation

Returns:

  • (Boolean)


40
41
42
# File 'lib/pragma/rails/resource_controller.rb', line 40

def operation?(operation_name)
  class_exists? operation_klass(operation_name)
end

#operation_klass(operation_name) ⇒ String

Returns the expected class of the provided operation on this resource.

Note that this does not mean the operation is actually supported. Use #operation? for that.

Examples:

API::V1::PostsController.operation_klass(:create) => 'API::V1::Post::Operation::Create'

Parameters:

  • operation_name (Symbol)

    name of the operation

Returns:

  • (String)

See Also:



28
29
30
31
32
33
# File 'lib/pragma/rails/resource_controller.rb', line 28

def operation_klass(operation_name)
  [name.deconstantize].tap do |klass|
    klass << name.demodulize.chomp('Controller').singularize
    klass << "Operation::#{operation_name.to_s.camelize}"
  end.join('::')
end