Sha256: 17a5ea8b3b74a58165b89c0c345d740b8e7d1c835a4f8328c679e51483486b7d

Contents?: true

Size: 1.02 KB

Versions: 42

Compression:

Stored size: 1.02 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

    private

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

  end

end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
subj_sub_models-0.0.3.29 lib/subj_models/faq.rb
subj_sub_models-0.0.3.28 lib/subj_models/faq.rb
subj_sub_models-0.0.3.27 lib/subj_models/faq.rb
subj_sub_models-0.0.3.26 lib/subj_models/faq.rb
subj_sub_models-0.0.3.25 lib/subj_models/faq.rb
subj_sub_models-0.0.3.24 lib/subj_models/faq.rb
subj_sub_models-0.0.3.23 lib/subj_models/faq.rb
subj_sub_models-0.0.3.22 lib/subj_models/faq.rb
subj_sub_models-0.0.3.21 lib/subj_models/faq.rb
subj_sub_models-0.0.3.20 lib/subj_models/faq.rb
subj_sub_models-0.0.3.19 lib/subj_models/faq.rb
subj_sub_models-0.0.3.18 lib/subj_models/faq.rb
subj_sub_models-0.0.3.17 lib/subj_models/faq.rb
subj_sub_models-0.0.3.16 lib/subj_models/faq.rb
subj_sub_models-0.0.3.15 lib/subj_models/faq.rb
subj_sub_models-0.0.3.14 lib/subj_models/faq.rb
subj_sub_models-0.0.3.13 lib/subj_models/faq.rb
subj_sub_models-0.0.3.12 lib/subj_models/faq.rb
subj_sub_models-0.0.3.11 lib/subj_models/faq.rb
subj_sub_models-0.0.3.10 lib/subj_models/faq.rb