Module: Cuprum::Rails::Controllers::ClassMethods::Configuration

Defined in:
lib/cuprum/rails/controllers/class_methods/configuration.rb

Overview

Provides a DSL for defining controller configuration.

Instance Method Summary collapse

Instance Method Details

#configurationCuprum::Rails::Controllers::Configuration

Returns the configured options for the controller.

Returns:



12
13
14
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 12

def configuration
  Cuprum::Rails::Controllers::Configuration.new(self)
end

#default_formatSymbol #default_format(format) ⇒ Object

Overloads:

  • #default_formatSymbol

    Returns the default format for controller requests.

    Returns:

    • (Symbol)

      the default format for controller requests.

  • #default_format(format) ⇒ Object

    Sets the default format for controller requests.

    Parameters:

    • format (String, Symbol)

      The format to set as default.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 23

def default_format(format = nil)
  if format.nil?
    return @default_format if @default_format

    return superclass.default_format if controller_class?(superclass)

    return nil
  end

  validate_name(format, as: 'format')

  @default_format = format.intern
end

#own_respondersObject



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

def own_responders
  @own_responders ||= {}
end

#repositoryCuprum::Collections::Repository

Returns the repository defined for the controller.

Returns:

  • (Cuprum::Collections::Repository)

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



46
47
48
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 46

def repository
  nil
end

#resourceCuprum::Rails::Resource

Returns the resource defined for the controller.

Controller subclasses must override this method.

Returns:

Raises:



59
60
61
62
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 59

def resource
  raise Cuprum::Rails::Controller::UndefinedResourceError,
    "no resource defined for #{name}"
end

#responder(format, responder_class) ⇒ Object

Assigns a responder class to handle requests of the specified format.

Parameters:

  • format (String, Symbol)

    The request format to handle.

  • responder_class (Class)

    The class of responder.



68
69
70
71
72
73
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 68

def responder(format, responder_class)
  validate_name(format, as: 'format')
  validate_class(responder_class, as: 'responder')

  own_responders[format.intern] = responder_class
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.



77
78
79
80
81
82
83
# File 'lib/cuprum/rails/controllers/class_methods/configuration.rb', line 77

def responders
  ancestors
    .select { |ancestor| ancestor.respond_to?(:own_responders) }
    .reverse_each
    .map(&:own_responders)
    .reduce(&:merge)
end

#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.



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

def serializers
  {
    json: Cuprum::Rails::Serializers::Json.default_serializers
  }
end