surveyor 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,6 +27,10 @@ Try out the "kitchen sink" survey:
27
27
 
28
28
  rake surveyor FILE=surveys/kitchen_sink_survey.rb
29
29
 
30
+ The rake surveyor task overwrites previous surveys by default, but can append instead:
31
+
32
+ rake surveyor FILE=surveys/kitchen_sink_survey.rb APPEND=true
33
+
30
34
  # Configuration
31
35
 
32
36
  The surveyor generator creates config/initializers/surveyor.rb. There, you can specify:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.9.5
@@ -6,6 +6,7 @@ class DependencyCondition < ActiveRecord::Base
6
6
  belongs_to :answer
7
7
  belongs_to :dependency
8
8
  belongs_to :dependent_question, :foreign_key => :question_id, :class_name => :question
9
+ belongs_to :question
9
10
 
10
11
  # Validations
11
12
  validates_numericality_of :dependency_id, :question_id, :answer_id
@@ -6,5 +6,5 @@ Surveyor installed. Next, run the migrations:
6
6
  Try out the "kitchen sink" survey:
7
7
 
8
8
  rake surveyor FILE=surveys/kitchen_sink_survey.rb
9
-
9
+
10
10
  Or see README.md for configuration and customization details
@@ -0,0 +1,6 @@
1
+ class Fixtures
2
+ def delete_existing_fixtures
3
+ # @connection.delete "DELETE FROM #{@connection.quote_table_name(table_name)}", 'Fixture Delete'
4
+ puts "Appending, skipping delete..."
5
+ end
6
+ end
@@ -17,8 +17,8 @@ namespace :surveyor do
17
17
  desc "load survey fixtures"
18
18
  task :load_fixtures => :environment do
19
19
  require 'active_record/fixtures'
20
-
21
- ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
20
+ require 'fixtures_extensions' unless ENV["APPEND"].blank?
21
+ ActiveRecord::Base.establish_connection(Rails.env)
22
22
 
23
23
  fixture_dir = File.join(RAILS_ROOT, "surveys", "fixtures")
24
24
  fixtures = Dir.glob("#{fixture_dir}/*.yml")
@@ -46,13 +46,20 @@ module SurveyParser
46
46
 
47
47
  # Filter out attributes that shouldn't be in fixtures, including children, parser, placeholders
48
48
  def yml_attrs
49
- instance_variables.sort - self.class.children.map{|model| "@#{model.to_s}"} - %w(@parser @dependency @validation @question_reference @answer_reference)
49
+ instance_variables.sort - self.class.children.map{|model| "@#{model.to_s}"} - %w(@id @parser @dependency @validation @question_reference @answer_reference)
50
50
  end
51
51
  def to_yml
52
- out = [ %(#{@data_export_identifier}_#{@id}:) ]
53
- yml_attrs.each{|a| out << " #{a[1..-1]}: #{instance_variable_get(a).is_a?(String) ? "\"#{instance_variable_get(a)}\"" : instance_variable_get(a) }"}
52
+ out = [ %(#{self.parser.salt}_#{self.class.name.demodulize.underscore}_#{@id}:) ]
53
+ yml_attrs.each{|a| out << associate_and_format(a)}
54
54
  (out << nil ).join("\r\n")
55
55
  end
56
+ def associate_and_format(a)
57
+ if a =~ /_id$/ # a foreign key, e.g. survey_id
58
+ " #{a[1..-4]}: " + (instance_variable_get(a).nil? ? "" : "#{self.parser.salt}_#{a[1..-4]}_#{instance_variable_get(a)}")
59
+ else # quote strings
60
+ " #{a[1..-1]}: #{instance_variable_get(a).is_a?(String) ? "\"#{instance_variable_get(a)}\"" : instance_variable_get(a) }"
61
+ end
62
+ end
56
63
  def to_file
57
64
  File.open(self.parser.send("#{self.class.name.demodulize.underscore.pluralize}_yml"), File::CREAT|File::APPEND|File::WRONLY) {|f| f << to_yml}
58
65
  self.class.children.each{|model| self.send(model).compact.map(&:to_file)}
@@ -7,7 +7,7 @@ module SurveyParser
7
7
  (%w(base) + @@models).each{|m| require File.dirname(__FILE__) + "/#{m}"}
8
8
 
9
9
  # Attributes
10
- attr_accessor :surveys, :grid_answers
10
+ attr_accessor :salt, :surveys, :grid_answers
11
11
  @@models.each{|m| attr_accessor "#{m.pluralize}_yml".to_sym } # for fixtures
12
12
  (@@models - %w(dependency_condition validation_condition)).each {|m| attr_accessor "current_#{m}".to_sym} # for current_model caches
13
13
 
@@ -32,12 +32,13 @@ module SurveyParser
32
32
 
33
33
  # Instance methods
34
34
  def initialize
35
+ self.salt = Time.now.strftime("%Y%m%d%H%M%S")
35
36
  self.surveys = []
36
37
  self.grid_answers = []
37
38
  initialize_counters(@@models)
38
39
  initialize_fixtures(@@models.map(&:pluralize), File.join(RAILS_ROOT, "surveys", "fixtures"))
39
40
  end
40
-
41
+
41
42
  # @last_survey_id, @last_survey_section_id, etc.
42
43
  def initialize_counters(names)
43
44
  names.each{|name| instance_variable_set("@last_#{name}_id", 0)}
data/surveyor.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{surveyor}
8
- s.version = "0.9.4"
8
+ s.version = "0.9.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Chamberlain", "Mark Yoon"]
12
- s.date = %q{2009-11-10}
12
+ s.date = %q{2009-11-12}
13
13
  s.email = %q{yoon@northwestern.edu}
14
14
  s.extra_rdoc_files = [
15
15
  "README.md"
@@ -128,6 +128,7 @@ Gem::Specification.new do |s|
128
128
  "generators/test_surveyor/test_surveyor_generator.rb",
129
129
  "init.rb",
130
130
  "install.rb",
131
+ "lib/fixtures_extensions.rb",
131
132
  "lib/surveyor.rb",
132
133
  "lib/surveyor/acts_as_response.rb",
133
134
  "lib/surveyor/config.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surveyor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Chamberlain
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-11-10 00:00:00 -06:00
13
+ date: 2009-11-12 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -145,6 +145,7 @@ files:
145
145
  - generators/test_surveyor/test_surveyor_generator.rb
146
146
  - init.rb
147
147
  - install.rb
148
+ - lib/fixtures_extensions.rb
148
149
  - lib/surveyor.rb
149
150
  - lib/surveyor/acts_as_response.rb
150
151
  - lib/surveyor/config.rb