Module: CopiesOmniauth::ClassMethods

Defined in:
lib/copies_omniauth.rb

Instance Method Summary collapse

Instance Method Details

#copies_omniauth(args = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/copies_omniauth.rb', line 25

def copies_omniauth(args={})
  options = self.class_variable_set( :@@copies_omniauth_options,
                                       { :overwrite        => true,
                                         :provider_name => self.name.sub("Profile","").downcase,
                                         :secret_attribute => :secret,
                                         :skip_provider_check => false,
                                         :token_attribute  => :token,
                                         :uid_attribute    => :uid
                                       })
  unless args[:options].nil?
    options.merge!(args[:options])
  end

  attributes = self.class_variable_set( :@@copies_omniauth_attributes,
                                   { options[:secret_attribute] => SECRET_KEY,
                                     options[:token_attribute] => TOKEN_KEY,
                                     options[:uid_attribute]   => UID_KEY
                                   })
  unless args[:attributes].nil?
    attributes.merge!(args[:attributes])
  end

  [ options[:secret_attribute],
    options[:token_attribute],
    options[:uid_attribute] ].each do |attr|
    attributes.delete(attr) unless instance_has_setter_for?(attr)
  end

  attributes.each do |attr,omniauth_key|
    case omniauth_key
    when Array, String, Symbol
    else
      raise ArgumentError, "Don't know how to traverse OmniAuth with #{omniauth_key}"
    end
  end
  include CopiesOmniauth::InstanceMethods
end

#create_from_omniauth(omniauth) ⇒ Object



64
65
66
# File 'lib/copies_omniauth.rb', line 64

def create_from_omniauth(omniauth)
  new_from_omniauth(omniauth).save
end

#new_from_omniauth(omniauth) ⇒ Object



69
70
71
# File 'lib/copies_omniauth.rb', line 69

def new_from_omniauth(omniauth)
  new().copy_from_omniauth(omniauth)
end