Class: Alchemy::PageVersion

Inherits:
BaseRecord
  • Object
show all
Includes:
Publishable
Defined in:
app/models/alchemy/page_version.rb

Constant Summary collapse

METADATA_ATTRIBUTES =

Metadata attributes that are versioned (moved from Page)

%w[
  title
  meta_description
  meta_keywords
].freeze

Constants included from SearchableResource

SearchableResource::SEARCHABLE_COLUMN_TYPES

Instance Method Summary collapse

Methods included from Publishable

#publishable?

Methods included from ConfigMissing

#const_missing

Methods included from SearchableResource

#ransackable_associations, #ransackable_attributes, #ransackable_scopes, #ransortable_attributes

Instance Method Details

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

Determines if this version is already public for given time

Parameters:

  • (defaults to: Time.current)

    (Time.current)

Returns:



47
48
49
# File 'app/models/alchemy/page_version.rb', line 47

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

#element_repositoryObject



58
59
60
# File 'app/models/alchemy/page_version.rb', line 58

def element_repository
  ElementsRepository.new(elements)
end

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

Determines if this version 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:

  • (defaults to: Time.current)

    (Time.current)

Returns:



40
41
42
# File 'app/models/alchemy/page_version.rb', line 40

def public?(time = Time.current)
  already_public_for?(time) && still_public_for?(time)
end

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

Determines if this version is still public for given time

Parameters:

  • (defaults to: Time.current)

    (Time.current)

Returns:



54
55
56
# File 'app/models/alchemy/page_version.rb', line 54

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