Class: SinatraServiceController
- Inherits:
-
Object
- Object
- SinatraServiceController
- Extended by:
- Forwardable
- Includes:
- Sinatra::Helpers
- Defined in:
- lib/framework_ext/sinatra_controller.rb
Overview
Base code shared by all service controllers This allows us to share code between controllers more precisely to render templates and in general to use sinatra helpers
Defined Under Namespace
Classes: AuthenticationFailed
Instance Attribute Summary collapse
- #app ⇒ Sinatra::Application readonly
- #env ⇒ Hash readonly
- #params ⇒ Hash
- #request ⇒ Sinatra::Request readonly
- #response ⇒ Sinatra::Response readonly
-
#service ⇒ WSDSL
readonly
The service served by this controller.
Instance Method Summary collapse
-
#initialize(app, service) ⇒ SinatraServiceController
constructor
A new instance of SinatraServiceController.
-
#logged_in? ⇒ Boolean
Returns true or false if the player is logged in.
Constructor Details
#initialize(app, service) ⇒ SinatraServiceController
Returns a new instance of SinatraServiceController.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/framework_ext/sinatra_controller.rb', line 53 def initialize(app, service) @app = app @env = app.env @request = app.request @response = app.response @service = service # raises an exception if the params are not valid # otherwise update the app params with potentially new params (using default values) # note that if a type if mentioned for a params, the object will be cast to this object type @params = app.params = ParamsVerification.validate!(app.params, service.defined_params) # Authentication check if service.auth_required raise AuthenticationFailed unless logged_in? end end |
Instance Attribute Details
#app ⇒ Sinatra::Application (readonly)
28 29 30 |
# File 'lib/framework_ext/sinatra_controller.rb', line 28 def app @app end |
#env ⇒ Hash (readonly)
32 33 34 |
# File 'lib/framework_ext/sinatra_controller.rb', line 32 def env @env end |
#params ⇒ Hash
46 47 48 |
# File 'lib/framework_ext/sinatra_controller.rb', line 46 def params @params end |
#request ⇒ Sinatra::Request (readonly)
37 38 39 |
# File 'lib/framework_ext/sinatra_controller.rb', line 37 def request @request end |
#response ⇒ Sinatra::Response (readonly)
42 43 44 |
# File 'lib/framework_ext/sinatra_controller.rb', line 42 def response @response end |
#service ⇒ WSDSL (readonly)
Returns The service served by this controller.
24 25 26 |
# File 'lib/framework_ext/sinatra_controller.rb', line 24 def service @service end |
Instance Method Details
#logged_in? ⇒ Boolean
Returns true or false if the player is logged in.
76 77 78 |
# File 'lib/framework_ext/sinatra_controller.rb', line 76 def logged_in? !session[:player_id].nil? end |