Class: Alchemy::PageVersion

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

Constant Summary

Constants included from SearchableResource

SearchableResource::SEARCHABLE_COLUMN_TYPES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SearchableResource

#ransackable_associations, #ransackable_attributes, #ransortable_attributes

Class Method Details

.public_on(time = Time.current) ⇒ Object



14
15
16
17
18
# File 'app/models/alchemy/page_version.rb', line 14

def self.public_on(time = Time.current)
  where("#{table_name}.public_on <= :time AND " \
        "(#{table_name}.public_until IS NULL " \
        "OR #{table_name}.public_until >= :time)", time: time)
end

Instance Method Details

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

Determines if this version is already public for given time

Parameters:

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

    (Time.current)

Returns:

  • (Boolean)


37
38
39
# File 'app/models/alchemy/page_version.rb', line 37

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

#element_repositoryObject



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

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:

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

    (Time.current)

Returns:

  • (Boolean)


30
31
32
# File 'app/models/alchemy/page_version.rb', line 30

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:

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

    (Time.current)

Returns:

  • (Boolean)


44
45
46
# File 'app/models/alchemy/page_version.rb', line 44

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