Sha256: d94ed8c949bb273ac66de3da73131304f5dee53351cbb0ac83b30ae4c1e1b799
Contents?: true
Size: 1.56 KB
Versions: 4
Compression:
Stored size: 1.56 KB
Contents
module Helena class Question include Helena::Concerns::ApplicationModel include Mongoid::Orderable TYPES = [ Helena::Questions::ShortText, Helena::Questions::LongText, Helena::Questions::StaticText, Helena::Questions::RadioGroup, Helena::Questions::CheckboxGroup, Helena::Questions::RadioMatrix, Helena::Questions::BipolarRadioMatrix ] belongs_to :question_group, inverse_of: :questions embeds_many :labels, class_name: 'Helena::Label', cascade_callbacks: true embeds_many :sub_questions, class_name: 'Helena::SubQuestion', cascade_callbacks: true accepts_nested_attributes_for :labels, allow_destroy: true, reject_if: :reject_labels accepts_nested_attributes_for :sub_questions, allow_destroy: true, reject_if: :reject_sub_questions field :code, type: String field :question_text, type: String orderable scope: :question_group validates :code, presence: true validate :uniqueness_of_code def includes_labels? false end def includes_subquestions? false end private def uniqueness_of_code question_code_occurences = question_group.version.question_code_occurences errors.add :code, :taken if question_code_occurences[code] > 1 end def reject_labels(attributed) attributed['text'].blank? && attributed['value'].blank? end def reject_sub_questions(attributed) attributed['code'].blank? && attributed['default_value'].blank? && attributed['question_text'].blank? end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
helena-1.0.1 | app/models/helena/question.rb |
helena-1.0.0.rc4 | app/models/helena/question.rb |
helena-1.0.0.rc3 | app/models/helena/question.rb |
helena-1.0.0.rc2 | app/models/helena/question.rb |