Skip to content

Commit

Permalink
Merge pull request tutsplus#1 from mrdougwright/update-strategy
Browse files Browse the repository at this point in the history
replace case statement with dictionary hash
  • Loading branch information
amanda08 committed Dec 10, 2014
2 parents f918900 + 73c9699 commit 6364b7a
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 6364b7a

Please sign in to comment.