Class: RestPack::Web::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/restpack_web/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#accountObject

Returns the value of attribute account.



3
4
5
# File 'lib/restpack_web/context.rb', line 3

def 
  @account
end

#applicationObject

Returns the value of attribute application.



3
4
5
# File 'lib/restpack_web/context.rb', line 3

def application
  @application
end

#domainObject

Returns the value of attribute domain.



3
4
5
# File 'lib/restpack_web/context.rb', line 3

def domain
  @domain
end

#userObject

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_idObject



24
25
26
# File 'lib/restpack_web/context.rb', line 24

def 
  authenticated? ? @account[:id] : nil
end

#application_idObject



28
29
30
# File 'lib/restpack_web/context.rb', line 28

def application_id
  @application[:id]
end

#auth_domainObject



40
41
42
# File 'lib/restpack_web/context.rb', line 40

def auth_domain
  "auth.#{@domain[:identifier]}"
end

#authenticated?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/restpack_web/context.rb', line 16

def authenticated?
  !@user.nil?
end

#debug_infoObject



53
54
55
# File 'lib/restpack_web/context.rb', line 53

def debug_info
  "todo"
end

#domain_idObject



32
33
34
# File 'lib/restpack_web/context.rb', line 32

def domain_id
  @domain[:id]
end

#home_domainObject



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 (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_idObject



20
21
22
# File 'lib/restpack_web/context.rb', line 20

def user_id
  authenticated? ? @user[:id] : nil
end