Module: Adauth::Rails::ModelBridge::ClassMethods

Defined in:
lib/adauth/rails/model_bridge.rb

Overview

Class Methods for ModelBridge

Instance Method Summary collapse

Instance Method Details

#create_from_adauth(adauth_model) ⇒ Object

Creates a new RailsModel from the adauth_model



46
47
48
49
# File 'lib/adauth/rails/model_bridge.rb', line 46

def create_from_adauth(adauth_model)
    rails_model = self.new
    rails_model.update_from_adauth(adauth_model)
end

#return_and_create_from_adauth(adauth_model) ⇒ Object

Used to create the RailsModel if it doesn’t exist and update it if it does



52
53
54
55
56
57
58
59
60
# File 'lib/adauth/rails/model_bridge.rb', line 52

def return_and_create_from_adauth(adauth_model)
    adauth_field = self::AdauthSearchField.first
    adauth_search_value = adauth_model.send(adauth_field)
    rails_search_field = self::AdauthSearchField.second
    # Model#where({}).first_or_initialize is also compatible with Mongoid (3.1.0+)
    rails_model = self.send(:where, { rails_search_field => adauth_search_value }).first_or_initialize
    rails_model.update_from_adauth(adauth_model)
    rails_model
end