Class: Respo::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Helpers
Defined in:
lib/respo/response.rb

Direct Known Subclasses

Errors::Base, Successes::Base

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#action_name, #camelize, pluralize, singularize

Constructor Details

#initialize(record, **args) ⇒ Response



20
21
22
23
24
25
26
27
# File 'lib/respo/response.rb', line 20

def initialize(record, **args)
  @record = record

  # NOTE: dynamically define instance variables
  args.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



10
11
12
# File 'lib/respo/response.rb', line 10

def record
  @record
end

#rootObject (readonly)

Returns the value of attribute root.



10
11
12
# File 'lib/respo/response.rb', line 10

def root
  @root
end

#viewObject (readonly)

Returns the value of attribute view.



10
11
12
# File 'lib/respo/response.rb', line 10

def view
  @view
end

Class Method Details

.call(record, **args) ⇒ Object



15
16
17
# File 'lib/respo/response.rb', line 15

def call(record, **args)
  new(record, **args).call
end

Instance Method Details

#serializerObject



29
30
31
32
# File 'lib/respo/response.rb', line 29

def serializer
  name = camelize(Respo.configuration.serializer.to_s)
  @serializer ||= Object.const_get("Respo::Serializers::#{name}")
end