# Sometimes complex read operations might deserve their own objects, Policy Object is the right solution. # Policy Objects are similar to Service Objects, but it is conventional to use services for write operations # and policies for read. # They are also similar to Query Objects, but Query Objects focus on executing SQL to return a result set, # whereas Policy Objects operate on domain models already loaded into memory. # app/policies/twitter_policy.rb class TwitterPolicy < Struct.new(:auth) def first_name auth['info']['name'].split(' ').first end def last_name ..... end .... end # app/policies/facebook_policy.rb class FacebookPolicy < Struct.new(:auth) def first_name auth['info']['first_name'] end def last_name ..... end .... end # app/models/user.rb def self.from_oauth(auth) policy = "#{auth['provider']}_policy".classify.constantize.new(auth) create_user_from_policy(policy) end # Check https://github.com/elabs/pundit for maximum usage of policies and OO design # Pundit: Minimal authorization through OO design and pure Ruby classes