Class: JsendWrapper::SuccessRenderer

Inherits:
Renderer
  • Object
show all
Defined in:
lib/jsend_wrapper/renderers/success_renderer.rb

Overview

Wraps the given message in a JSend Success. JSend Successes have two required elements (status, data).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ SuccessRenderer

Returns a new instance of SuccessRenderer.



24
25
26
# File 'lib/jsend_wrapper/renderers/success_renderer.rb', line 24

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



22
23
24
# File 'lib/jsend_wrapper/renderers/success_renderer.rb', line 22

def data
  @data
end

Instance Method Details

#to_hObject



32
33
34
# File 'lib/jsend_wrapper/renderers/success_renderer.rb', line 32

def to_h
  { status: 'success', data: data }
end

#to_sObject



28
29
30
# File 'lib/jsend_wrapper/renderers/success_renderer.rb', line 28

def to_s
  %[{"status":"success","data":#{json_string data}}]
end