diff --git a/replace-type-code-with-state-strategy/lib/after.rb b/replace-type-code-with-state-strategy/lib/after.rb index 2edd04e..07f8bc8 100644 --- a/replace-type-code-with-state-strategy/lib/after.rb +++ b/replace-type-code-with-state-strategy/lib/after.rb @@ -1,3 +1,9 @@ +STRATEGIES = { + :password => 'Auth::Password', + :public_key => 'Auth::PublicKey', + :oauth => 'Auth::OAuth' +} + class User attr_reader :name, :type, :options @@ -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