Module: OmniAuth::Identity::Models::Rom::ClassMethods

Defined in:
lib/omniauth/identity/models/rom.rb

Constant Summary collapse

DEFAULT_RELATION_NAME =

Default ROM relation name when none is configured

:identities

Instance Method Summary collapse

Instance Method Details

#auth_key_symbolObject

Align with other adapters: use Model.auth_key (getter/setter) for the login attribute
Model.auth_key returns a String; convert to Symbol for ROM queries when needed.



82
83
84
# File 'lib/omniauth/identity/models/rom.rb', line 82

def auth_key_symbol
  (auth_key || "email").to_sym
end

#locate(conditions) ⇒ Object

Locate an identity given conditions (Hash) or a raw key value.
Mirrors other adapters by accepting a conditions hash.
Returns an instance or nil.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/omniauth/identity/models/rom.rb', line 89

def locate(conditions)
  key_value = if conditions.is_a?(Hash)
    conditions[auth_key_symbol] || conditions[auth_key.to_s]
  else
    conditions
  end
  return if key_value.nil?

  relation = rom_container.relations[rom_relation_name]
  identity_data = relation.where(auth_key_symbol => key_value).one
  return unless identity_data

  if owner_relation_name && identity_data[:owner_id]
    owner_data = rom_container.relations[owner_relation_name].where(id: identity_data[:owner_id]).one
    new(identity_data, owner_data)
  else
    new(identity_data)
  end
end

#owner_relation_name(value = false) ⇒ Object



70
71
72
73
# File 'lib/omniauth/identity/models/rom.rb', line 70

def owner_relation_name(value = false)
  @owner_relation_name = value unless value == false
  @owner_relation_name
end

#password_field(value = false) ⇒ Object



75
76
77
78
# File 'lib/omniauth/identity/models/rom.rb', line 75

def password_field(value = false)
  @password_field = value unless value == false
  (@password_field || :password_digest).to_sym
end

#rom_container(value = false) ⇒ Object

Configuration DSL
These methods act like the DSL on OmniAuth::Identity::Model (e.g. auth_key) —
when called with an argument they set the configuration, and when called
without an argument they return the current value (with sensible defaults).



59
60
61
62
63
# File 'lib/omniauth/identity/models/rom.rb', line 59

def rom_container(value = false)
  @rom_container = value unless value == false
  container = @rom_container
  container.respond_to?(:call) ? container.call : container
end

#rom_relation_name(value = false) ⇒ Object



65
66
67
68
# File 'lib/omniauth/identity/models/rom.rb', line 65

def rom_relation_name(value = false)
  @rom_relation_name = value unless value == false
  @rom_relation_name || DEFAULT_RELATION_NAME
end