Module: Adauth::Rails::ModelBridge
- Defined in:
- lib/adauth/rails/model_bridge.rb
Overview
Included into Models in Rails
Requires you to set 2 Constants
AdauthMappings
A hash which controls how Adauth maps its values to rails e.g.
AdauthMappings =
:name => :login
This will store Adauths ‘login’ value in the ‘name’ field.
AdauthSearchField
This is an array which contains 2 values and is used to find the objects record e.g.
AdauthSearchField = [:login, :name]
This will cause RailsModel.where(:name => AdauthObject.login).first_or_initialize
The Order is [adauth_field, rails_field]
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Registers the class methods when ModelBridge is included.
Instance Method Summary collapse
-
#update_from_adauth(adauth_model) ⇒ Object
Uses AdauthMappings to update the values on the model using the ones from Adauth.
Class Method Details
.included(base) ⇒ Object
Registers the class methods when ModelBridge is included
28 29 30 |
# File 'lib/adauth/rails/model_bridge.rb', line 28 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#update_from_adauth(adauth_model) ⇒ Object
Uses AdauthMappings to update the values on the model using the ones from Adauth
33 34 35 36 37 38 39 40 41 |
# File 'lib/adauth/rails/model_bridge.rb', line 33 def update_from_adauth(adauth_model) self.class::AdauthMappings.each do |k, v| setter = "#{k.to_s}=".to_sym value = v.is_a?(Array) ? v.join(", ") : v self.send(setter, adauth_model.send(value)) end self.save self end |