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
- 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.
-
#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.
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/upkeep/rails/configuration.rb', line 110 def initialize @enabled = true @subscription_store = :active_record @deliver_inline = false @delivery_batch_window = 0.01 @refused_boundary_behavior = nil @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.
99 100 101 |
# File 'lib/upkeep/rails/configuration.rb', line 99 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.
107 108 109 |
# File 'lib/upkeep/rails/configuration.rb', line 107 def deliver_inline @deliver_inline end |
#delivery_batch_window ⇒ Object
Returns the value of attribute delivery_batch_window.
100 101 102 |
# File 'lib/upkeep/rails/configuration.rb', line 100 def delivery_batch_window @delivery_batch_window end |
#enabled ⇒ Object
Returns the value of attribute enabled.
98 99 100 |
# File 'lib/upkeep/rails/configuration.rb', line 98 def enabled @enabled end |
#subscription_store ⇒ Object
Returns the value of attribute subscription_store.
108 109 110 |
# File 'lib/upkeep/rails/configuration.rb', line 108 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.
104 105 106 |
# File 'lib/upkeep/rails/configuration.rb', line 104 def subscription_ttl @subscription_ttl end |
Instance Method Details
#clear_identities! ⇒ Object
191 192 193 |
# File 'lib/upkeep/rails/configuration.rb', line 191 def clear_identities! @identity_definitions.clear end |
#identify(name, current: nil, session: nil, cookie: nil, warden: nil, &block) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/upkeep/rails/configuration.rb', line 147 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
187 188 189 |
# File 'lib/upkeep/rails/configuration.rb', line 187 def identity_definition(name) @identity_definitions.fetch(name.to_sym) end |
#identity_definitions ⇒ Object
183 184 185 |
# File 'lib/upkeep/rails/configuration.rb', line 183 def identity_definitions @identity_definitions.values end |
#identity_presence_metadata(source:, key:, value:) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/upkeep/rails/configuration.rb', line 167 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
132 133 134 |
# File 'lib/upkeep/rails/configuration.rb', line 132 def refused_boundary_behavior @refused_boundary_behavior || default_refused_boundary_behavior end |
#refused_boundary_behavior=(value) ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/upkeep/rails/configuration.rb', line 136 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 |