Class: Upkeep::Rails::Configuration
- Inherits:
-
Object
- Object
- Upkeep::Rails::Configuration
- Defined in:
- lib/upkeep/rails/configuration.rb
Defined Under Namespace
Classes: IdentityBuilder, IdentityDefinition
Constant Summary collapse
- SUBSCRIPTION_STORES =
[:active_record, :memory].freeze
- REFUSED_BOUNDARY_BEHAVIORS =
[:raise, :warn].freeze
- REQUEST_ACTIVATIONS =
[:all, :opt_in].freeze
- IDENTITY_SOURCES =
[:current, :session, :cookie, :warden].freeze
Instance Attribute Summary collapse
-
#activation_token_expires_in ⇒ Object
Returns the value of attribute activation_token_expires_in.
-
#deliver_inline ⇒ Object
Test/console hook: deliver changes synchronously in the caller instead of on the in-process background dispatcher.
-
#delivery_batch_window ⇒ Object
Returns the value of attribute delivery_batch_window.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#request_activation ⇒ Object
Returns the value of attribute request_activation.
-
#subscription_store ⇒ Object
Returns the value of attribute subscription_store.
-
#subscription_ttl ⇒ Object
Seconds a subscription may go untouched before it counts as abandoned and becomes eligible for pruning.
Instance Method Summary collapse
- #clear_identities! ⇒ Object
- #identify(name, current: nil, session: nil, cookie: nil, warden: nil, &block) ⇒ Object
- #identity_definition(name) ⇒ Object
- #identity_definitions ⇒ Object
- #identity_presence_metadata(source:, key:, value:) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #refused_boundary_behavior ⇒ Object
- #refused_boundary_behavior=(value) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/upkeep/rails/configuration.rb', line 112 def initialize @enabled = true @subscription_store = :active_record @deliver_inline = false @delivery_batch_window = 0.01 @refused_boundary_behavior = nil @request_activation = :all @activation_token_expires_in = 24 * 60 * 60 @subscription_ttl = 24 * 60 * 60 @identity_definitions = {} end |
Instance Attribute Details
#activation_token_expires_in ⇒ Object
Returns the value of attribute activation_token_expires_in.
100 101 102 |
# File 'lib/upkeep/rails/configuration.rb', line 100 def activation_token_expires_in @activation_token_expires_in end |
#deliver_inline ⇒ Object
Test/console hook: deliver changes synchronously in the caller instead of on the in-process background dispatcher.
108 109 110 |
# File 'lib/upkeep/rails/configuration.rb', line 108 def deliver_inline @deliver_inline end |
#delivery_batch_window ⇒ Object
Returns the value of attribute delivery_batch_window.
101 102 103 |
# File 'lib/upkeep/rails/configuration.rb', line 101 def delivery_batch_window @delivery_batch_window end |
#enabled ⇒ Object
Returns the value of attribute enabled.
99 100 101 |
# File 'lib/upkeep/rails/configuration.rb', line 99 def enabled @enabled end |
#request_activation ⇒ Object
Returns the value of attribute request_activation.
110 111 112 |
# File 'lib/upkeep/rails/configuration.rb', line 110 def request_activation @request_activation end |
#subscription_store ⇒ Object
Returns the value of attribute subscription_store.
109 110 111 |
# File 'lib/upkeep/rails/configuration.rb', line 109 def subscription_store @subscription_store end |
#subscription_ttl ⇒ Object
Seconds a subscription may go untouched before it counts as abandoned and becomes eligible for pruning. Connected pages are kept alive by the cable channel heartbeat, which fires far more often than this TTL.
105 106 107 |
# File 'lib/upkeep/rails/configuration.rb', line 105 def subscription_ttl @subscription_ttl end |
Instance Method Details
#clear_identities! ⇒ Object
205 206 207 |
# File 'lib/upkeep/rails/configuration.rb', line 205 def clear_identities! @identity_definitions.clear end |
#identify(name, current: nil, session: nil, cookie: nil, warden: nil, &block) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/upkeep/rails/configuration.rb', line 161 def identify(name, current: nil, session: nil, cookie: nil, warden: nil, &block) source, source_key = identity_source(current: current, session: session, cookie: , warden: warden) builder = IdentityBuilder.new if block block.arity == 1 ? block.call(builder) : builder.instance_eval(&block) end unless builder.subscribe_block raise ConfigurationError, "config.identify :#{name} requires a subscribe block" end @identity_definitions[name.to_sym] = IdentityDefinition.new( name: name, source: source, source_key: source_key, subscribe_block: builder.subscribe_block, absent_block: builder.absent_block ) end |
#identity_definition(name) ⇒ Object
201 202 203 |
# File 'lib/upkeep/rails/configuration.rb', line 201 def identity_definition(name) @identity_definitions.fetch(name.to_sym) end |
#identity_definitions ⇒ Object
197 198 199 |
# File 'lib/upkeep/rails/configuration.rb', line 197 def identity_definitions @identity_definitions.values end |
#identity_presence_metadata(source:, key:, value:) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/upkeep/rails/configuration.rb', line 181 def (source:, key:, value:) definitions = identity_definitions.select { |definition| definition.matches_source?(source, key) } absent_by_name = definitions.to_h do |definition| [definition.name.to_s, definition.absent?(value)] end { partitioning: if definitions.any? absent_by_name.values.any? { |absent| !absent } else !value.nil? end, absent_by_name: absent_by_name } end |
#refused_boundary_behavior ⇒ Object
135 136 137 |
# File 'lib/upkeep/rails/configuration.rb', line 135 def refused_boundary_behavior @refused_boundary_behavior || default_refused_boundary_behavior end |
#refused_boundary_behavior=(value) ⇒ Object
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/upkeep/rails/configuration.rb', line 139 def refused_boundary_behavior=(value) value = value.to_sym if value.respond_to?(:to_sym) unless REFUSED_BOUNDARY_BEHAVIORS.include?(value) raise ConfigurationError, "Unknown Upkeep refused_boundary_behavior #{value.inspect}; expected one of #{REFUSED_BOUNDARY_BEHAVIORS.join(", ")}" end @refused_boundary_behavior = value end |