Sha256: 794450fb9740a0b140cc55cc667c0b1891246ed7c1f90298047276ba08482285

Contents?: true

Size: 1017 Bytes

Versions: 1

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

module Archangel
  ##
  # Entry model
  #
  class Entry < ApplicationRecord
    acts_as_paranoid

    serialize :value, JSON

    acts_as_list scope: :collection_id, top_of_list: 0, add_new_at: :top

    validates :collection_id, presence: true
    validates :available_at, allow_blank: true, date: true
    validates :value, presence: true

    belongs_to :collection

    default_scope { order(position: :asc) }

    ##
    # Check if Entry is available. Available in the past, present and future.
    # Future availability date is also considered available.
    #
    # @return [Boolean] if available
    #
    def available?
      available_at.present?
    end

    ##
    # Return string of availability status.
    #
    # @return [String] available status
    #
    def available_status
      if available?
        if available_at > Time.now
          "future-available"
        else
          "available"
        end
      else
        "unavailable"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
archangel-0.0.7 app/models/archangel/entry.rb