Skip to content

Commit

Permalink
replace case statement with dictionary hash
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdougwright committed Dec 9, 2014
1 parent f918900 commit 73c9699
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions replace-type-code-with-state-strategy/lib/after.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
STRATEGIES = {
:password => 'Auth::Password',
:public_key => 'Auth::PublicKey',
:oauth => 'Auth::OAuth'
}

class User
attr_reader :name, :type, :options

Expand All @@ -6,14 +12,7 @@ def initialize name, type, options = {}
@type = type
@options = options

@strategy = case @type
when :password
Auth::Password.new self
when :public_key
Auth::PublicKey.new self
when :oauth
Auth::OAuth.new self
end
@strategy = Class.const_get(STRATEGIES[type]).new(self)
end

def auth! options
Expand Down

0 comments on commit 73c9699

Please sign in to comment.