Class: SinatraServiceController

Inherits:
Object
  • Object
show all
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

See Also:

  • and Sinatra::Helpers

Author:

  • Matt Aimonetti

API:

  • public

Defined Under Namespace

Classes: AuthenticationFailed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, service) ⇒ SinatraServiceController

Returns a new instance of SinatraServiceController.

Parameters:

  • The Sinatra app used as a reference and to access request params

  • The service served by this controller

Raises:

API:

  • public



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)

Returns:

API:

  • public



28
29
30
# File 'lib/framework_ext/sinatra_controller.rb', line 28

def app
  @app
end

#env ⇒ Hash (readonly)

Returns:

API:

  • public



32
33
34
# File 'lib/framework_ext/sinatra_controller.rb', line 32

def env
  @env
end

#params ⇒ Hash

Returns:

API:

  • public



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.

Returns:

  • The service served by this controller

API:

  • public



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.

Returns:

API:

  • public



76
77
78
# File 'lib/framework_ext/sinatra_controller.rb', line 76

def logged_in?
  !session[:player_id].nil?
end