Sha256: a708823ec8c00e73e02c81fef4dbe41afe39cd5b0e07a214cfe1f9ff32437718

Contents?: true

Size: 666 Bytes

Versions: 48

Compression:

Stored size: 666 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Surveys
    # The data store for a SurveyQuestion in the Decidim::Surveys component.
    class SurveyQuestion < Surveys::ApplicationRecord
      TYPES = %w(short_answer long_answer single_option multiple_option).freeze

      belongs_to :survey, class_name: "Survey", foreign_key: "decidim_survey_id"

      validates :question_type, inclusion: { in: TYPES }

      # Rectify can't handle a hash when using the from_model method so
      # the answer options must be converted to struct.
      def answer_options
        self[:answer_options].map { |option| OpenStruct.new(option) }
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
decidim-surveys-0.6.6 app/models/decidim/surveys/survey_question.rb
decidim-0.6.6 decidim-surveys/app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.6.5 app/models/decidim/surveys/survey_question.rb
decidim-0.6.5 decidim-surveys/app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.6.4 app/models/decidim/surveys/survey_question.rb
decidim-0.6.4 decidim-surveys/app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.6.3 app/models/decidim/surveys/survey_question.rb
decidim-0.6.3 decidim-surveys/app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.6.2 app/models/decidim/surveys/survey_question.rb
decidim-0.6.2 decidim-surveys/app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.6.1 app/models/decidim/surveys/survey_question.rb
decidim-0.6.1 decidim-surveys/app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.6.0 app/models/decidim/surveys/survey_question.rb
decidim-0.6.0 decidim-surveys/app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.5.1 app/models/decidim/surveys/survey_question.rb
decidim-0.5.1 decidim-surveys/app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.5.0 app/models/decidim/surveys/survey_question.rb
decidim-0.5.0 decidim-surveys/app/models/decidim/surveys/survey_question.rb
decidim-surveys-0.4.4 app/models/decidim/surveys/survey_question.rb
decidim-0.4.4 decidim-surveys/app/models/decidim/surveys/survey_question.rb