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.



95
96
97
# File 'lib/omniauth/identity/models/rom.rb', line 95

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.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/omniauth/identity/models/rom.rb', line 102

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



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

def owner_relation_name(value = false)
  ROM_CONFIG_MUTEX.synchronize do
    @owner_relation_name = value unless value == false
    @owner_relation_name
  end
end

#password_field(value = false) ⇒ Object



86
87
88
89
90
91
# File 'lib/omniauth/identity/models/rom.rb', line 86

def password_field(value = false)
  ROM_CONFIG_MUTEX.synchronize do
    @password_field = value unless value == false
    (@password_field || :password_digest).to_sym
  end
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).



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

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

#rom_relation_name(value = false) ⇒ Object



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

def rom_relation_name(value = false)
  ROM_CONFIG_MUTEX.synchronize do
    @rom_relation_name = value unless value == false
    @rom_relation_name || DEFAULT_RELATION_NAME
  end
end