Class: HollaBack::Response

Inherits:
Object
  • Object
show all
Includes:
OptionLoader
Defined in:
lib/holla_back/response.rb

Overview

The main class for providing response objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionLoader

load_option, load_options

Constructor Details

#initialize(responding_obj = nil, options) ⇒ Response

A new instance of HollaBack::Response

Examples:

response = HollaBack::Response.new({responding_object: SomeObject.new, status_message: 'valid?'})

Parameters:

  • options (Hash)
    • a hash of options

  • responding_obj (Object) (defaults to: nil)
    • the object responsible for determining a response



23
24
25
26
27
28
29
30
31
32
# File 'lib/holla_back/response.rb', line 23

def initialize(responding_obj=nil, options)
  options = {
    responding_methods: [],
    success_message: nil,
    failure_message: nil
  }.merge(options)
  load_options(options, :responding_methods, :status_method, :success_message, :failure_message)
  self.responding_object = responding_obj
  set_response!
end

Instance Attribute Details

#responding_methodsHash

Returns responding_methods - The hash of key (method) value (return) pairs.

Returns:

  • (Hash)

    responding_methods - The hash of key (method) value (return) pairs



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

def responding_methods
  @responding_methods
end

#responding_objectObject

Returns responding_object - The responding object.

Returns:

  • (Object)

    responding_object - The responding object



8
9
10
# File 'lib/holla_back/response.rb', line 8

def responding_object
  @responding_object
end

#status_messageString

Returns status_message - The status message for the response.

Returns:

  • (String)

    status_message - The status message for the response



12
13
14
# File 'lib/holla_back/response.rb', line 12

def status_message
  @status_message
end

Instance Method Details

#successful?Boolean

The status of success

Examples:

response.success? #=> true

Returns:

  • (Boolean)

    true - if the status method is not nil or false

  • (Boolean)

    false - if the status method is nil or false



42
43
44
# File 'lib/holla_back/response.rb', line 42

def successful?
  !!get_status_method
end