Module: Alchemy::Publishable

Extended by:
ActiveSupport::Concern
Included in:
Element, PageVersion
Defined in:
app/models/concerns/alchemy/publishable.rb

Instance Method Summary collapse

Instance Method Details

#already_public_for?(at: Current.preview_time) ⇒ Boolean

Determines if this record is already public for given time

Parameters:

  • at (DateTime) (defaults to: Current.preview_time)

    (Time.current)

Returns:

  • (Boolean)


55
56
57
# File 'app/models/concerns/alchemy/publishable.rb', line 55

def already_public_for?(at: Current.preview_time)
  !public_on.nil? && public_on <= at
end

#public?(at: Current.preview_time) ⇒ Boolean Also known as: public

Determines if this record is public

Takes the two timestamps public_on and public_until and returns true if the time given (Time.current per default) is in this timespan.

Parameters:

  • at (DateTime) (defaults to: Current.preview_time)

    (Time.current)

Returns:

  • (Boolean)


34
35
36
# File 'app/models/concerns/alchemy/publishable.rb', line 34

def public?(at: Current.preview_time)
  already_public_for?(at:) && still_public_for?(at:)
end

#publishable?Boolean

Determines if this record is publishable

A record is publishable if a public_on timestamp is set and not expired yet.

Returns:

  • (Boolean)


48
49
50
# File 'app/models/concerns/alchemy/publishable.rb', line 48

def publishable?
  !public_on.nil? && still_public_for?
end

#scheduled?(at: Current.preview_time) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/concerns/alchemy/publishable.rb', line 39

def scheduled?(at: Current.preview_time)
  (public_on.present? && public_on > at) || (public_until.present? && public_until > at)
end

#still_public_for?(at: Current.preview_time) ⇒ Boolean

Determines if this record is still public for given time

Parameters:

  • at (DateTime) (defaults to: Current.preview_time)

    (Time.current)

Returns:

  • (Boolean)


62
63
64
# File 'app/models/concerns/alchemy/publishable.rb', line 62

def still_public_for?(at: Current.preview_time)
  public_until.nil? || public_until > at
end