Sha256: db0a2ace70e453684e6a52f062e7b5157ad6025874937f8a2d1a950f47c86276

Contents?: true

Size: 833 Bytes

Versions: 2

Compression:

Stored size: 833 Bytes

Contents

<% module_namespacing do -%>
class <%= class_name %>Authentication < ActiveRecord::Base
  belongs_to :<%= class_name.downcase %>
  belongs_to :authentication_provider

  serialize :params

<% if Rails::VERSION::MAJOR < 4 -%>
  attr_accessible "#{class_name.downcase}_id", :authentication_provider_id, :uid, :token, :token_expires_at, :params

<% end -%>
  def self.create_from_omniauth(params, <%= class_name.downcase %>, provider)
    token_expires_at = params['credentials']['expires_at'] ? Time.at(params['credentials']['expires_at']).to_datetime : nil

    create(
      <%= class_name.downcase %>: <%= class_name.downcase %>,
      authentication_provider: provider,
      uid: params['uid'],
      token: params['credentials']['token'],
      token_expires_at: token_expires_at,
      params: params,
    )
  end
end
<% end -%>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
domp-0.0.6 lib/generators/domp/templates/model_authentication.rb
domp-0.0.5 lib/generators/domp/templates/model_authentication.rb