Class: RailsDrips::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_drips/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rails_drips/configuration.rb', line 22

def initialize
  @delivery_queue_name = :default
  @delivery_job_class = -> { RailsDrips::DeliveryJob }
  @eligibility_evaluator = ->(**) { true }
  @logger = defined?(Rails) ? Rails.logger : nil
  @admin_enabled = false
  @admin_authenticator = nil
  @admin_authorizer = nil
  @preference_evaluator = ->(**) { true }
  @queue_inventory = nil
  @recipient_email_resolver = method(:default_recipient_email)
  @recipient_label_resolver = ->(recipient) { recipient.respond_to?(:name) ? recipient.name : "#{recipient.class.name} ##{recipient.id}" }
  @current_actor_resolver = ->(_controller) { nil }
  @snapshot_authorizer = ->(**) { false }
  @time_source = -> { Time.current }
  @transport_metadata_hook = ->(message:, **) { message }
  @mailers = MailRegistry.new
end

Instance Attribute Details

#admin_authenticatorObject

Returns the value of attribute admin_authenticator.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def admin_authenticator
  @admin_authenticator
end

#admin_authorizerObject

Returns the value of attribute admin_authorizer.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def admin_authorizer
  @admin_authorizer
end

#admin_enabledObject

Returns the value of attribute admin_enabled.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def admin_enabled
  @admin_enabled
end

#current_actor_resolverObject

Returns the value of attribute current_actor_resolver.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def current_actor_resolver
  @current_actor_resolver
end

#delivery_job_classObject

Returns the value of attribute delivery_job_class.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def delivery_job_class
  @delivery_job_class
end

#delivery_queue_nameObject

Returns the value of attribute delivery_queue_name.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def delivery_queue_name
  @delivery_queue_name
end

#eligibility_evaluatorObject

Returns the value of attribute eligibility_evaluator.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def eligibility_evaluator
  @eligibility_evaluator
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def logger
  @logger
end

#mailersObject (readonly)

Returns the value of attribute mailers.



20
21
22
# File 'lib/rails_drips/configuration.rb', line 20

def mailers
  @mailers
end

#preference_evaluatorObject

Returns the value of attribute preference_evaluator.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def preference_evaluator
  @preference_evaluator
end

#queue_inventoryObject

Returns the value of attribute queue_inventory.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def queue_inventory
  @queue_inventory
end

#recipient_email_resolverObject

Returns the value of attribute recipient_email_resolver.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def recipient_email_resolver
  @recipient_email_resolver
end

#recipient_label_resolverObject

Returns the value of attribute recipient_label_resolver.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def recipient_label_resolver
  @recipient_label_resolver
end

#snapshot_authorizerObject

Returns the value of attribute snapshot_authorizer.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def snapshot_authorizer
  @snapshot_authorizer
end

#time_sourceObject

Returns the value of attribute time_source.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def time_source
  @time_source
end

#transport_metadata_hookObject

Returns the value of attribute transport_metadata_hook.



5
6
7
# File 'lib/rails_drips/configuration.rb', line 5

def 
  @transport_metadata_hook
end

Instance Method Details

#current_timeObject



45
46
47
# File 'lib/rails_drips/configuration.rb', line 45

def current_time
  time_source.call
end

#delivery_jobObject



41
42
43
# File 'lib/rails_drips/configuration.rb', line 41

def delivery_job
  delivery_job_class.respond_to?(:call) ? delivery_job_class.call : delivery_job_class
end

#recipient_email(recipient) ⇒ Object



49
50
51
52
53
54
# File 'lib/rails_drips/configuration.rb', line 49

def recipient_email(recipient)
  value = recipient_email_resolver.call(recipient).to_s.strip
  return value unless value.empty?

  raise RecipientEmailMissing, "No email address could be resolved for #{recipient.class.name}"
end