Class: Gizmo::BaseOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/gizmo/base_operation.rb

Direct Known Subclasses

Delete, Find, FindAll, Make, Modify, Search

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ BaseOperation

Creates a new Find and sets its context

Parameters:



9
10
11
# File 'lib/gizmo/base_operation.rb', line 9

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/gizmo/base_operation.rb', line 4

def context
  @context
end

Instance Method Details

#create_responseObject



13
14
15
# File 'lib/gizmo/base_operation.rb', line 13

def create_response
  Response.new(format: context.format, callback: context.callback, status: default_status)
end

#default_statusObject



17
18
19
# File 'lib/gizmo/base_operation.rb', line 17

def default_status
  200
end

#set_response_headers(gizmo_response) ⇒ Object

Set headers on the response

Parameters:

  • gizmo_response (Gizmo::Response)

    a response used to set headers on the HTTP response



24
25
26
27
28
29
30
# File 'lib/gizmo/base_operation.rb', line 24

def set_response_headers(gizmo_response)
  if context.gizmo.respond_to?(:headers) && gizmo_response.headers
    gizmo_response.headers.each do |name, value|
      context.gizmo.headers[name] = value
    end
  end
end