Sha256: a86376f035be826a5f54d659e55b9e21617af4f6624f99343401c622a6650c9b

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

require 'subj_models/concerns/comprising_external_id'

module SubjModels

  module FaqModule

    include SubjModels::TypesSupport::FaqTypes
    include SubjModels::ValuesChecker

    def self.included(including_class)

      including_class.class_eval do

        include SubjModels::ComprisingExternalId

        enum faq_type: FAQ_TYPES

        after_save :notify_user

        validates :question, presence: true, allow_blank: false,
          uniqueness: { message: 'Простите, такой вопрос уже был задан' }
        validates :faq_type, inclusion: { in: faq_types.keys },
              on: :update

        scope :with_answer, -> { where.not(answer: nil) }
        scope :without_answer, -> { where(answer: nil) }
        scope :on_site, -> { where(show_on_site: true) }
        scope :type_is, -> (condition) { where(faq_type: condition) }

      end

    end

    def to_s
      question
    end

    def faq_type=(value)
      super(check_string_for_int(value))
    end

    private

    def notify_user
      FaqMailer.notify_user(self).deliver if send_to_user
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
subj_models-0.5.7 lib/subj_models/faq.rb
subj_models-0.5.6 lib/subj_models/faq.rb
subj_models-0.5.5 lib/subj_models/faq.rb
subj_models-0.5.4 lib/subj_models/faq.rb
subj_models-0.5.3 lib/subj_models/faq.rb