Class: Survey

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Surveyor::Models::SurveyMethods
Defined in:
lib/surveyor/unparser.rb,
app/models/survey.rb,
lib/generators/surveyor/templates/db/migrate/update_blank_versions_on_surveys.rb,
lib/generators/surveyor/templates/db/migrate/update_blank_api_ids_on_question_group.rb

Overview

Surveyor models with extra parsing methods

Instance Method Summary collapse

Methods included from Surveyor::Models::SurveyMethods

#activate!, #active?, #active_as_of?, #as_json, #deactivate!, #default_access_code, #default_args, #filtered_for_json, #generate_access_code, #increment_version, #initialize, #translation

Instance Method Details

#unparse(dsl) ⇒ Object

block



21
22
23
24
25
26
27
28
# File 'lib/surveyor/unparser.rb', line 21

def unparse(dsl)
  with_defaults = Survey.new(:title => title)
  attrs = self.attributes.delete_if{|k,v| with_defaults[k] == v or %w(created_at updated_at inactive_at id title access_code api_id).include? k}.symbolize_keys!
  dsl << "survey \"#{title}\""
  dsl << (attrs.blank? ? " do\n" : ", #{attrs.inspect.gsub(/\{|\}/, "")} do\n")
  sections.each{|section| section.unparse(dsl)}
  dsl << "end\n"
end