Class: Cyrax::Base

Inherits:
Object
  • Object
show all
Includes:
Extensions::HasResponse, HasActiveLogger::Mixin
Defined in:
lib/cyrax/base.rb

Direct Known Subclasses

Resource

Constant Summary

Constants included from Extensions::HasResponse

Extensions::HasResponse::STATUS_VALUES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Extensions::HasResponse

#add_error, #add_error_unless, #assign_resource, #assignment, #reset_errors, #respond_with, #response_name, #set_message, #set_status, #sync_errors_with, #sync_errors_with?

Constructor Details

#initialize(options = {}) ⇒ Base

Creates a new Cyrax resource

Examples:

Instantiating a new resource

Products::UserResource.new(as: current_user, params: params)

Parameters:

  • options (Hash) (defaults to: {})

    Options to pass in. You need ‘:as` and `:params` :as defines the accessor :params are parameters passed by the controller usually :serializer overrides resource serializer :decorator overrides resource serializer



18
19
20
21
22
# File 'lib/cyrax/base.rb', line 18

def initialize(options = {})
  @accessor = options[:as]
  @params = wrap_params(options[:params])
  @options = options
end

Instance Attribute Details

#accessorObject

Returns the value of attribute accessor.



6
7
8
# File 'lib/cyrax/base.rb', line 6

def accessor
  @accessor
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/cyrax/base.rb', line 6

def options
  @options
end

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/cyrax/base.rb', line 6

def params
  @params
end

Instance Method Details

#wrap_params(params) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/cyrax/base.rb', line 24

def wrap_params(params)
  if Cyrax.strong_parameters && defined?(ActionController) &&
    !params.is_a?(ActionController::Parameters)
    ActionController::Parameters.new(params)
  else
    params
  end
end