Sha256: 16e6f5b1d58f2633527223f787b8ffb5dfc66339a183435804c433b2209342a4

Contents?: true

Size: 710 Bytes

Versions: 2

Compression:

Stored size: 710 Bytes

Contents

module Vapid
  module Models
    # Record model
    class Record < ActiveRecord::Base
      serialize :content, JSON
      belongs_to :group, touch: true
      validates :group, presence: true

      def display_name
        content["name"] || content["title"]
      end

      def slug
        return unless display_name
        display_name.downcase.gsub(/[^a-z0-9]+/, "-").chomp("-")
      end

      def url
        return unless group.repeating?

        parts = [group.name, id, slug].reject(&:nil?)
        "/#{parts.join('/')}".downcase
      end

      def content_summary
        group.text_fields.any? ? content.values_at(*group.text_fields).join(", ") : content.to_json
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vapid-0.1.1 lib/vapid/models/record.rb
vapid-0.1.0 lib/vapid/models/record.rb