Sha256: 0fa7974042701c2235ac37fe9ed55b609eeecd4f592de9d0a3c58f87b3500204

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

module Helena
  class VersionPublisher
    def self.publish(version)
      copied_version = build_copied_version_from(version)

      version.question_groups.each do |original_question_group|
        question_group = copied_version.question_groups.build original_question_group.clone.attributes
        original_question_group.questions.each do |original_question|
          question = question_group.questions.build original_question.clone.attributes
          question.labels = original_question.labels
          question.sub_questions = original_question.sub_questions
        end
      end
      copied_version
    end

    def self.adjust_copied_attributes(version, copied_version)
      copied_version.version = newest_version_of(version.survey) + 1
      copied_version.survey_detail = version.survey_detail.attributes if version.survey_detail
      copied_version.created_at = Time.now
      copied_version.updated_at = Time.now
      copied_version.active = false
      copied_version
    end

    def self.newest_version_of(survey)
      survey.newest_version.version
    end

    def self.build_copied_version_from(version)
      copied_version = version.clone
      adjust_copied_attributes(version, copied_version)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
helena-2.1.0 lib/helena/version_publisher.rb
helena-2.0.2 lib/helena/version_publisher.rb
helena-2.0.1 lib/helena/version_publisher.rb
helena-2.0.0 lib/helena/version_publisher.rb
helena-1.3.1 lib/helena/version_publisher.rb
helena-1.3.0 lib/helena/version_publisher.rb