Commit 15d66b11dba4957dc083bd975ce34b1a65e2b63d
1 parent
bf91175c
Exists in
master
Fixing question type inheritance
Showing
5 changed files
with
34 additions
and
26 deletions
Show diff stats
lib/surveyable.rb
lib/surveyable/acts_as_response.rb
1 | 1 | module Surveyable |
2 | 2 | module ActsAsResponse |
3 | - extend ActiveSupport::Concern | |
4 | - included do | |
5 | - has_many :answers, as: :response | |
6 | - def survey | |
7 | - self.send(survey_relationship) | |
8 | - end | |
3 | + def self.included(base) | |
4 | + base.send :extend, ClassMethods | |
9 | 5 | end |
6 | + | |
10 | 7 | module ClassMethods |
11 | - def acts_as_response(survey_relationship, options = {}) | |
12 | - cattr_accessor :survey | |
13 | - self.survey_relationship = survey_relationship.to_s | |
8 | + def acts_as_response(options = {}) | |
9 | + has_many :answers, as: :response, class_name: 'Surveyable::Answer' | |
10 | + | |
11 | + send :include, InstanceMethods | |
12 | + end | |
13 | + end | |
14 | + module InstanceMethods | |
15 | + def survey | |
16 | + nil | |
14 | 17 | end |
15 | 18 | end |
16 | 19 | end |
17 | 20 | end |
18 | -ActiveRecord::Base.send :include, Surveyable::ActsAsResponse | |
19 | 21 | \ No newline at end of file | ... | ... |
lib/surveyable/acts_as_survey.rb
... | ... | @@ -6,8 +6,12 @@ module Surveyable |
6 | 6 | module ClassMethods |
7 | 7 | def acts_as_survey(response_relationship, options = {}) |
8 | 8 | has_many :questions, as: :survey, class_name: 'Surveyable::Question' |
9 | - #cattr_accessor :responses | |
10 | - #self.responses = responses | |
9 | + send :include, InstanceMethods | |
10 | + end | |
11 | + end | |
12 | + module InstanceMethods | |
13 | + def responses | |
14 | + [] | |
11 | 15 | end |
12 | 16 | end |
13 | 17 | end | ... | ... |
lib/surveyable/question.rb
... | ... | @@ -14,32 +14,32 @@ module Surveyable |
14 | 14 | 'text' |
15 | 15 | end |
16 | 16 | end |
17 | - class InfoField < Question | |
17 | + class InfoField < Surveyable::Question | |
18 | 18 | def field_type |
19 | 19 | 'noAnswer' |
20 | 20 | end |
21 | 21 | end |
22 | 22 | |
23 | 23 | |
24 | - class HiddenField < Question | |
24 | + class HiddenField < Surveyable::Question | |
25 | 25 | def field_type |
26 | 26 | 'hidden' |
27 | 27 | end |
28 | 28 | end |
29 | 29 | |
30 | - class BooleanField < Question | |
30 | + class BooleanField < Surveyable::Question | |
31 | 31 | def field_type |
32 | 32 | 'boolean' |
33 | 33 | end |
34 | 34 | end |
35 | 35 | |
36 | - class DateField < Question | |
36 | + class DateField < Surveyable::Question | |
37 | 37 | def field_type |
38 | 38 | 'date' |
39 | 39 | end |
40 | 40 | end |
41 | 41 | |
42 | - class SingleSelectField < Question | |
42 | + class SingleSelectField < Surveyable::Question | |
43 | 43 | def field_type |
44 | 44 | 'select' |
45 | 45 | end |
... | ... | @@ -49,49 +49,49 @@ module Surveyable |
49 | 49 | |
50 | 50 | end |
51 | 51 | |
52 | - class MultiSelectField < Question | |
52 | + class MultiSelectField < Surveyable::Question | |
53 | 53 | def field_type |
54 | 54 | 'select' |
55 | 55 | end |
56 | 56 | end |
57 | 57 | |
58 | - class TextField < Question | |
58 | + class TextField < Surveyable::Question | |
59 | 59 | def field_type |
60 | 60 | 'textarea' |
61 | 61 | end |
62 | 62 | end |
63 | 63 | |
64 | - class StringField < Question | |
64 | + class StringField < Surveyable::Question | |
65 | 65 | def field_type |
66 | 66 | 'text' |
67 | 67 | end |
68 | 68 | end |
69 | 69 | |
70 | - class IntegerField < Question | |
70 | + class IntegerField < Surveyable::Question | |
71 | 71 | def field_type |
72 | 72 | 'number' |
73 | 73 | end |
74 | 74 | end |
75 | 75 | |
76 | - class MoneyAmountField < Question | |
76 | + class MoneyAmountField < Surveyable::Question | |
77 | 77 | def field_type |
78 | 78 | 'text' |
79 | 79 | end |
80 | 80 | end |
81 | 81 | |
82 | - class SingleDocumentField < Question | |
82 | + class SingleDocumentField < Surveyable::Question | |
83 | 83 | def field_type |
84 | 84 | 'file' |
85 | 85 | end |
86 | 86 | end |
87 | 87 | |
88 | - class MultiDocumentField < Question | |
88 | + class MultiDocumentField < Surveyable::Question | |
89 | 89 | def field_type |
90 | 90 | 'file' |
91 | 91 | end |
92 | 92 | end |
93 | 93 | |
94 | - class TelephoneField < Question | |
94 | + class TelephoneField < Surveyable::Question | |
95 | 95 | def field_type |
96 | 96 | 'tel' |
97 | 97 | end | ... | ... |
lib/surveyable/version.rb