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

Version Path
type_station-0.7.0 app/models/type_station/page.rb
type_station-0.6.0 app/models/type_station/page.rb
type_station-0.5.4 app/models/type_station/page.rb
type_station-0.5.3 app/models/type_station/page.rb
type_station-0.5.2 app/models/type_station/page.rb
type_station-0.5.1 app/models/type_station/page.rb
type_station-0.4.7 app/models/type_station/page.rb
type_station-0.4.6 app/models/type_station/page.rb
type_station-0.4.5 app/models/type_station/page.rb
type_station-0.4.4 app/models/type_station/page.rb
type_station-0.4.3 app/models/type_station/page.rb
type_station-0.4.2 app/models/type_station/page.rb
type_station-0.4.1 app/models/type_station/page.rb
type_station-0.4.0 app/models/type_station/page.rb
type_station-0.3.4 app/models/type_station/page.rb
type_station-0.3.3 app/models/type_station/page.rb
type_station-0.3.2 app/models/type_station/page.rb
type_station-0.3.1 app/models/type_station/page.rb
type_station-0.3.0 app/models/type_station/page.rb
type_station-0.2.3 app/models/type_station/page.rb