Skip to content

Commit

Permalink
Replace custom strategy initializers with delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
reidab committed Oct 27, 2015
1 parent 4b0e5ef commit 6c0a159
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 38 deletions.
9 changes: 2 additions & 7 deletions lib/doorkeeper/request/authorization_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
module Doorkeeper
module Request
class AuthorizationCode < Strategy
attr_accessor :grant, :client

def initialize(server)
super
@grant, @client = server.grant, server.client
end
delegate :grant, :client, :parameters, to: :server

def request
@request ||= OAuth::AuthorizationCodeRequest.new(Doorkeeper.configuration, grant, client, server.parameters)
@request ||= OAuth::AuthorizationCodeRequest.new(Doorkeeper.configuration, grant, client, parameters)
end
end
end
Expand Down
9 changes: 2 additions & 7 deletions lib/doorkeeper/request/client_credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
module Doorkeeper
module Request
class ClientCredentials < Strategy
attr_accessor :client

def initialize(server)
super
@client = server.client
end
delegate :client, :parameters, to: :server

def request
@request ||= OAuth::ClientCredentialsRequest.new(Doorkeeper.configuration, client, server.parameters)
@request ||= OAuth::ClientCredentialsRequest.new(Doorkeeper.configuration, client, parameters)
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions lib/doorkeeper/request/code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
module Doorkeeper
module Request
class Code < Strategy
attr_accessor :pre_auth
delegate :current_resource_owner, to: :server

def initialize(server)
super
@pre_auth = server.context.send(:pre_auth)
def pre_auth
server.context.send(:pre_auth)
end

def request
@request ||= OAuth::CodeRequest.new(pre_auth, server.current_resource_owner)
@request ||= OAuth::CodeRequest.new(pre_auth, current_resource_owner)
end
end
end
Expand Down
10 changes: 2 additions & 8 deletions lib/doorkeeper/request/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
module Doorkeeper
module Request
class Password < Strategy
attr_accessor :credentials, :resource_owner

def initialize(server)
super
@credentials = server.credentials
@resource_owner = server.resource_owner
end
delegate :credentials, :resource_owner, :parameters, to: :server

def request
@request ||= OAuth::PasswordAccessTokenRequest.new(Doorkeeper.configuration, credentials, resource_owner, server.parameters)
@request ||= OAuth::PasswordAccessTokenRequest.new(Doorkeeper.configuration, credentials, resource_owner, parameters)
end
end
end
Expand Down
10 changes: 4 additions & 6 deletions lib/doorkeeper/request/refresh_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
module Doorkeeper
module Request
class RefreshToken < Strategy
attr_accessor :refresh_token, :credentials
delegate :credentials, :parameters, to: :server

def initialize(server)
super
@refresh_token = server.current_refresh_token
@credentials = server.credentials
def refresh_token
server.current_refresh_token
end

def request
@request ||= OAuth::RefreshTokenRequest.new(Doorkeeper.configuration, refresh_token, credentials, server.parameters)
@request ||= OAuth::RefreshTokenRequest.new(Doorkeeper.configuration, refresh_token, credentials, parameters)
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions lib/doorkeeper/request/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
module Doorkeeper
module Request
class Token < Strategy
attr_accessor :pre_auth
delegate :current_resource_owner, to: :server

def initialize(server)
super
@pre_auth = server.context.send(:pre_auth)
def pre_auth
server.context.send(:pre_auth)
end

def request
@request ||= OAuth::TokenRequest.new(pre_auth, server.current_resource_owner)
@request ||= OAuth::TokenRequest.new(pre_auth, current_resource_owner)
end
end
end
Expand Down

0 comments on commit 6c0a159

Please sign in to comment.