Class: Pageflow::CutoffModes

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/cutoff_modes.rb

Overview

Register strategies to determine whether only the part of an entry before some cutoff point should be rendered (e.g., to preview paywalled premium content).

Since:

  • edge

Defined Under Namespace

Classes: Mode

Instance Method Summary collapse

Constructor Details

#initializeCutoffModes

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CutoffModes.

Since:

  • edge



8
9
10
# File 'lib/pageflow/cutoff_modes.rb', line 8

def initialize
  @modes = {}
end

Instance Method Details

#enabled_for?(entry, request) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • edge



27
28
29
# File 'lib/pageflow/cutoff_modes.rb', line 27

def enabled_for?(entry, request)
  !!@modes[entry.site.cutoff_mode_name]&.enabled&.call(entry, request)
end

#namesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • edge



32
33
34
# File 'lib/pageflow/cutoff_modes.rb', line 32

def names
  @modes.keys
end

#register(name, enabled) ⇒ Object

Register callable to determine whether only the part of an entry before some cutoff point should be rendered (e.g., to preview paywalled premium content). Cutoff modes can then be enabled per site.

Parameters:

  • name (String)

    Referenced in sites.

  • enabled (#call)

    Take EntryAtRevision and ActionDispatch::Request and return true if the entry shall be cut off.

Since:

  • edge



22
23
24
# File 'lib/pageflow/cutoff_modes.rb', line 22

def register(name, enabled)
  @modes[name.to_s] = Mode.new(name, enabled)
end