Class: RestPack::Web::Context
- Inherits:
-
Object
- Object
- RestPack::Web::Context
- Defined in:
- lib/restpack_web/context.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#application ⇒ Object
Returns the value of attribute application.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #account_id ⇒ Object
- #application_id ⇒ Object
- #auth_domain ⇒ Object
- #authenticated? ⇒ Boolean
- #debug_info ⇒ Object
- #domain_id ⇒ Object
- #home_domain ⇒ Object
-
#initialize(env) ⇒ Context
constructor
A new instance of Context.
- #login_url(provider = :twitter, next_url = nil) ⇒ Object
- #logout_url(next_url = nil) ⇒ Object
- #user_id ⇒ Object
Constructor Details
#initialize(env) ⇒ Context
Returns a new instance of Context.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/restpack_web/context.rb', line 5 def initialize(env) restpack = env['restpack'] if restpack @domain = restpack[:domain] @application = restpack[:application] @user = restpack[:user] @account = restpack[:account] end end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
3 4 5 |
# File 'lib/restpack_web/context.rb', line 3 def account @account end |
#application ⇒ Object
Returns the value of attribute application.
3 4 5 |
# File 'lib/restpack_web/context.rb', line 3 def application @application end |
#domain ⇒ Object
Returns the value of attribute domain.
3 4 5 |
# File 'lib/restpack_web/context.rb', line 3 def domain @domain end |
#user ⇒ Object
Returns the value of attribute user.
3 4 5 |
# File 'lib/restpack_web/context.rb', line 3 def user @user end |
Instance Method Details
#account_id ⇒ Object
24 25 26 |
# File 'lib/restpack_web/context.rb', line 24 def account_id authenticated? ? @account[:id] : nil end |
#application_id ⇒ Object
28 29 30 |
# File 'lib/restpack_web/context.rb', line 28 def application_id @application[:id] end |
#auth_domain ⇒ Object
40 41 42 |
# File 'lib/restpack_web/context.rb', line 40 def auth_domain "auth.#{@domain[:identifier]}" end |
#authenticated? ⇒ Boolean
16 17 18 |
# File 'lib/restpack_web/context.rb', line 16 def authenticated? !@user.nil? end |
#debug_info ⇒ Object
53 54 55 |
# File 'lib/restpack_web/context.rb', line 53 def debug_info "todo" end |
#domain_id ⇒ Object
32 33 34 |
# File 'lib/restpack_web/context.rb', line 32 def domain_id @domain[:id] end |
#home_domain ⇒ Object
36 37 38 |
# File 'lib/restpack_web/context.rb', line 36 def home_domain "www.#{@domain[:identifier]}" end |
#login_url(provider = :twitter, next_url = nil) ⇒ Object
49 50 51 |
# File 'lib/restpack_web/context.rb', line 49 def login_url(provider = :twitter, next_url = nil) auth_url("/auth/#{provider}", next_url) end |
#logout_url(next_url = nil) ⇒ Object
44 45 46 47 |
# File 'lib/restpack_web/context.rb', line 44 def logout_url(next_url = nil) next_url ||= "http://#{home_domain}/" auth_url('/auth/logout', next_url) end |
#user_id ⇒ Object
20 21 22 |
# File 'lib/restpack_web/context.rb', line 20 def user_id authenticated? ? @user[:id] : nil end |