Class: Cuprum::Rails::Controllers::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cuprum/rails/controllers/configuration.rb

Overview

Data object that stores a controller’s configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:



14
15
16
# File 'lib/cuprum/rails/controllers/configuration.rb', line 14

def initialize(controller)
  @controller = controller
end

Instance Attribute Details

#controller#resource, #responders (readonly)

Returns the controller to delegate configuration.

Returns:



19
20
21
# File 'lib/cuprum/rails/controllers/configuration.rb', line 19

def controller
  @controller
end

Instance Method Details

#controller_nameString

Returns the name of the controller.

Returns:

  • (String)

    the name of the controller.



# File 'lib/cuprum/rails/controllers/configuration.rb', line 21

#default_formatSymbol

Returns the default format for controller requests.

Returns:

  • (Symbol)

    the default format for controller requests.



# File 'lib/cuprum/rails/controllers/configuration.rb', line 24

#middlewareArray<Cuprum::Rails::Controllers::Middleware>

Returns the middleware defined for the controller.

Returns:



# File 'lib/cuprum/rails/controllers/configuration.rb', line 27

#middleware_for(action_name) ⇒ Array<Cuprum::Rails::Controllers::Middleware>

Finds the configured middleware for the requested action name.

Parameters:

  • action_name (Symbol)

    The name of the action.

Returns:



62
63
64
# File 'lib/cuprum/rails/controllers/configuration.rb', line 62

def middleware_for(action_name)
  middleware.select { |item| item.matches?(action_name) }
end

#repositoryCuprum::Collections::Repository

Returns the repository containing the data collections for the application or scope.

Returns:

  • (Cuprum::Collections::Repository)

    the repository containing the data collections for the application or scope.



# File 'lib/cuprum/rails/controllers/configuration.rb', line 31

#resourceCuprum::Rails::Resource

Returns the resource defined for the controller.

Returns:



# File 'lib/cuprum/rails/controllers/configuration.rb', line 35

#responder_for(format) ⇒ Class

Finds the configured responder for the requested format.

Parameters:

  • format (Symbol)

    the format to respond to.

Returns:

  • (Class)

    the responder class defined for the format.

Raises:



74
75
76
77
78
79
# File 'lib/cuprum/rails/controllers/configuration.rb', line 74

def responder_for(format)
  responders.fetch(format) do
    raise Cuprum::Rails::Controller::UnknownFormatError,
      "no responder registered for format #{format.inspect}"
  end
end

#respondersHash<Symbol, Class>

Returns the responder classes defined for the controller, by format.

Returns:

  • (Hash<Symbol, Class>)

    the responder classes defined for the controller, by format.



# File 'lib/cuprum/rails/controllers/configuration.rb', line 39

#serializersHash<Class, Object>, Hash<Symbol, Hash<Class, Object>>

Returns the serializers for converting result values into serialized data.

Returns:

  • (Hash<Class, Object>, Hash<Symbol, Hash<Class, Object>>)

    the serializers for converting result values into serialized data.



47
48
49
50
51
52
53
54
# File 'lib/cuprum/rails/controllers/configuration.rb', line 47

def_delegators :@controller,
:controller_name,
:default_format,
:middleware,
:repository,
:resource,
:responders,
:serializers

#serializers_for(format) ⇒ Hash<Class, Object>

Finds the configured serializers for the requested format.

Parameters:

  • format (Symbol)

    the format to respond to.

Returns:

  • (Hash<Class, Object>)

    the serializers for converting result values into serialized data.



87
88
89
90
91
# File 'lib/cuprum/rails/controllers/configuration.rb', line 87

def serializers_for(format)
  serializers
    .select { |key, _| key.is_a?(Class) }
    .merge(serializers.fetch(format, {}))
end