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)


48
49
50
# File 'lib/pragma/rails/resource_controller.rb', line 48

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:



37
38
39
40
41
# File 'lib/pragma/rails/resource_controller.rb', line 37

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

#resource_nameString

Returns the name of the resource this controller refers to.

Examples:

API::V1::PostsController.resource_name => 'Post'

Returns:

  • (String)


20
21
22
# File 'lib/pragma/rails/resource_controller.rb', line 20

def resource_name
  name.demodulize.chomp('Controller').singularize
end