Module: AuthTrail

Defined in:
lib/authtrail.rb,
lib/auth_trail/manager.rb,
lib/auth_trail/version.rb,
lib/auth_trail/geocode_job.rb

Defined Under Namespace

Modules: Manager Classes: GeocodeJob

Constant Summary collapse

VERSION =
"0.6.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.exclude_methodObject

Returns the value of attribute exclude_method.



12
13
14
# File 'lib/authtrail.rb', line 12

def exclude_method
  @exclude_method
end

.geocodeObject

Returns the value of attribute geocode.



12
13
14
# File 'lib/authtrail.rb', line 12

def geocode
  @geocode
end

.identity_methodObject

Returns the value of attribute identity_method.



12
13
14
# File 'lib/authtrail.rb', line 12

def identity_method
  @identity_method
end

.job_queueObject

Returns the value of attribute job_queue.



12
13
14
# File 'lib/authtrail.rb', line 12

def job_queue
  @job_queue
end

.track_methodObject

Returns the value of attribute track_method.



12
13
14
# File 'lib/authtrail.rb', line 12

def track_method
  @track_method
end

.transform_methodObject

Returns the value of attribute transform_method.



12
13
14
# File 'lib/authtrail.rb', line 12

def transform_method
  @transform_method
end

Class Method Details

.safely(default: nil) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/authtrail.rb', line 61

def self.safely(default: nil)
  begin
    yield
  rescue => e
    warn "[authtrail] #{e.class.name}: #{e.message}"
    default
  end
end

.track(strategy:, scope:, identity:, success:, request:, user: nil, failure_reason: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/authtrail.rb', line 32

def self.track(strategy:, scope:, identity:, success:, request:, user: nil, failure_reason: nil)
  data = {
    strategy: strategy,
    scope: scope,
    identity: identity,
    success: success,
    failure_reason: failure_reason,
    user: user,
    ip: request.remote_ip,
    user_agent: request.user_agent,
    referrer: request.referrer
  }

  if request.params[:controller]
    data[:context] = "#{request.params[:controller]}##{request.params[:action]}"
  end

  # add request data before exclude_method since exclude_method doesn't have access to request
  # could also add 2nd argument to exclude_method when arity > 1
  AuthTrail.transform_method.call(data, request) if AuthTrail.transform_method

  # if exclude_method throws an exception, default to not excluding
  exclude = AuthTrail.exclude_method && AuthTrail.safely(default: false) { AuthTrail.exclude_method.call(data) }

  unless exclude
    AuthTrail.track_method.call(data)
  end
end