Class: RaketaAdmin::RaketaContext

Inherits:
Object
  • Object
show all
Defined in:
lib/raketa_admin/raketa_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_name, params, request, response, parent_resource = nil) ⇒ RaketaContext

Returns a new instance of RaketaContext.



10
11
12
13
14
15
16
17
18
# File 'lib/raketa_admin/raketa_context.rb', line 10

def initialize(resource_name, params, request, response, parent_resource = nil)
  @resource_name = resource_name
  @params = params
  @request = request
  @response = response
  @parent_resource = parent_resource
  @halted = false
  @assigns = {}
end

Instance Attribute Details

#assignsObject (readonly)

Returns the value of attribute assigns.



8
9
10
# File 'lib/raketa_admin/raketa_context.rb', line 8

def assigns
  @assigns
end

#haltedObject (readonly)

Returns the value of attribute halted.



8
9
10
# File 'lib/raketa_admin/raketa_context.rb', line 8

def halted
  @halted
end

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/raketa_admin/raketa_context.rb', line 8

def params
  @params
end

#parent_resourceObject (readonly)

Returns the value of attribute parent_resource.



8
9
10
# File 'lib/raketa_admin/raketa_context.rb', line 8

def parent_resource
  @parent_resource
end

#requestObject (readonly)

Returns the value of attribute request.



8
9
10
# File 'lib/raketa_admin/raketa_context.rb', line 8

def request
  @request
end

#resource_nameObject (readonly)

Returns the value of attribute resource_name.



8
9
10
# File 'lib/raketa_admin/raketa_context.rb', line 8

def resource_name
  @resource_name
end

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/raketa_admin/raketa_context.rb', line 8

def response
  @response
end

Instance Method Details

#cookiesObject



60
61
62
# File 'lib/raketa_admin/raketa_context.rb', line 60

def cookies
  request.cookies
end

#get_paramsObject

rubocop:disable Naming/AccessorMethodName



47
48
49
# File 'lib/raketa_admin/raketa_context.rb', line 47

def get_params
  request.GET
end

#haltObject



20
21
22
# File 'lib/raketa_admin/raketa_context.rb', line 20

def halt
  @halted = true
end

#headersObject



56
57
58
# File 'lib/raketa_admin/raketa_context.rb', line 56

def headers
  request.env.select { |k, _v| k.start_with?('HTTP_') }
end

#pathsObject



33
34
35
36
# File 'lib/raketa_admin/raketa_context.rb', line 33

def paths
  # TBD: An interface to get link to resource and method
  RaketaAdmin::Helpers::LinkHelper
end

#raw_requestObject



64
65
66
# File 'lib/raketa_admin/raketa_context.rb', line 64

def raw_request
  request
end

#raw_responseObject



68
69
70
# File 'lib/raketa_admin/raketa_context.rb', line 68

def raw_response
  response
end

#raw_routerObject

Raw router library access



73
74
75
# File 'lib/raketa_admin/raketa_context.rb', line 73

def raw_router
  Sinatra::Base
end

#redirect(url) ⇒ Object



24
25
26
27
# File 'lib/raketa_admin/raketa_context.rb', line 24

def redirect(url)
  @redirect_url = url
  halt
end

#redirected?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/raketa_admin/raketa_context.rb', line 29

def redirected?
  !!@redirect_url
end

#request_bodyObject

rubocop:enable Naming/AccessorMethodName



52
53
54
# File 'lib/raketa_admin/raketa_context.rb', line 52

def request_body
  request.body&.read || ''
end

#request_methodObject



38
39
40
# File 'lib/raketa_admin/raketa_context.rb', line 38

def request_method
  request.request_method
end

#to_hObject

This is just for easy view of the context!



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/raketa_admin/raketa_context.rb', line 78

def to_h
  {
    resource_name:,
    params:,
    request_method:,
    url_params:,
    get_params:,
    request_body:,
    parent_resource:,
    halted:,
    assigns:,
    paths:,
    headers:,
    cookies:
  }
end

#url_paramsObject



42
43
44
# File 'lib/raketa_admin/raketa_context.rb', line 42

def url_params
  params.reject { |k, v| get_params[k] == v }
end