Class: RaketaAdmin::RaketaContext
- Inherits:
-
Object
- Object
- RaketaAdmin::RaketaContext
- Defined in:
- lib/raketa_admin/raketa_context.rb
Instance Attribute Summary collapse
-
#assigns ⇒ Object
readonly
Returns the value of attribute assigns.
-
#halted ⇒ Object
readonly
Returns the value of attribute halted.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#parent_resource ⇒ Object
readonly
Returns the value of attribute parent_resource.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#resource_name ⇒ Object
readonly
Returns the value of attribute resource_name.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #cookies ⇒ Object
-
#get_params ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #halt ⇒ Object
- #headers ⇒ Object
-
#initialize(resource_name, params, request, response, parent_resource = nil) ⇒ RaketaContext
constructor
A new instance of RaketaContext.
- #paths ⇒ Object
- #raw_request ⇒ Object
- #raw_response ⇒ Object
-
#raw_router ⇒ Object
Raw router library access.
- #redirect(url) ⇒ Object
- #redirected? ⇒ Boolean
-
#request_body ⇒ Object
rubocop:enable Naming/AccessorMethodName.
- #request_method ⇒ Object
-
#to_h ⇒ Object
This is just for easy view of the context!.
- #url_params ⇒ Object
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
#assigns ⇒ Object (readonly)
Returns the value of attribute assigns.
8 9 10 |
# File 'lib/raketa_admin/raketa_context.rb', line 8 def assigns @assigns end |
#halted ⇒ Object (readonly)
Returns the value of attribute halted.
8 9 10 |
# File 'lib/raketa_admin/raketa_context.rb', line 8 def halted @halted end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/raketa_admin/raketa_context.rb', line 8 def params @params end |
#parent_resource ⇒ Object (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 |
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/raketa_admin/raketa_context.rb', line 8 def request @request end |
#resource_name ⇒ Object (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 |
#response ⇒ Object (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
#cookies ⇒ Object
60 61 62 |
# File 'lib/raketa_admin/raketa_context.rb', line 60 def request. end |
#get_params ⇒ Object
rubocop:disable Naming/AccessorMethodName
47 48 49 |
# File 'lib/raketa_admin/raketa_context.rb', line 47 def get_params request.GET end |
#halt ⇒ Object
20 21 22 |
# File 'lib/raketa_admin/raketa_context.rb', line 20 def halt @halted = true end |
#headers ⇒ Object
56 57 58 |
# File 'lib/raketa_admin/raketa_context.rb', line 56 def headers request.env.select { |k, _v| k.start_with?('HTTP_') } end |
#paths ⇒ Object
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_request ⇒ Object
64 65 66 |
# File 'lib/raketa_admin/raketa_context.rb', line 64 def raw_request request end |
#raw_response ⇒ Object
68 69 70 |
# File 'lib/raketa_admin/raketa_context.rb', line 68 def raw_response response end |
#raw_router ⇒ Object
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
29 30 31 |
# File 'lib/raketa_admin/raketa_context.rb', line 29 def redirected? !!@redirect_url end |
#request_body ⇒ Object
rubocop:enable Naming/AccessorMethodName
52 53 54 |
# File 'lib/raketa_admin/raketa_context.rb', line 52 def request_body request.body&.read || '' end |
#request_method ⇒ Object
38 39 40 |
# File 'lib/raketa_admin/raketa_context.rb', line 38 def request_method request.request_method end |
#to_h ⇒ Object
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_params ⇒ Object
42 43 44 |
# File 'lib/raketa_admin/raketa_context.rb', line 42 def url_params params.reject { |k, v| get_params[k] == v } end |