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?(time = Time.current) ⇒ Boolean

Determines if this record is already public for given time

Parameters:

  • time (DateTime) (defaults to: Time.current)

    (Time.current)

Returns:

  • (Boolean)


43
44
45
# File 'app/models/concerns/alchemy/publishable.rb', line 43

def already_public_for?(time = Time.current)
  !public_on.nil? && public_on <= time
end

#public?(time = Time.current) ⇒ 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:

  • time (DateTime) (defaults to: Time.current)

    (Time.current)

Returns:

  • (Boolean)


26
27
28
# File 'app/models/concerns/alchemy/publishable.rb', line 26

def public?(time = Time.current)
  already_public_for?(time) && still_public_for?(time)
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)


36
37
38
# File 'app/models/concerns/alchemy/publishable.rb', line 36

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

#still_public_for?(time = Time.current) ⇒ Boolean

Determines if this record is still public for given time

Parameters:

  • time (DateTime) (defaults to: Time.current)

    (Time.current)

Returns:

  • (Boolean)


50
51
52
# File 'app/models/concerns/alchemy/publishable.rb', line 50

def still_public_for?(time = Time.current)
  public_until.nil? || public_until >= time
end