Sha256: 5ad2491417633e70b20601fa23a9b4a46816ccdde62c7f2319fd4f8bf82249a9
Contents?: true
Size: 910 Bytes
Versions: 23
Compression:
Stored size: 910 Bytes
Contents
module TypeStation class Page < Entity include ::TypeStation::Concerns::PathGenerator include ::TypeStation::Concerns::Templatable STATUS = [:hidden, :draft, :published] field :redirect_to, type: String, default: nil field :status, type: Symbol, default: STATUS.last # always published unless stated # Validate that they is only one root page validates_each :parent_id do |model, attr, value| root_page = TypeStation::Page.root model.errors.add(attr, 'already have a root page') if value == nil && root_page.present? && model.id != root_page.id end # INSTANT METHODS def redirect? redirect_to.present? end def visible?(user) return true if parent_id == nil # The root page is always visible if user.present? [:draft, :published].include?(status) else status == :published end end end end
Version data entries
23 entries across 23 versions & 1 rubygems