effective_polls 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11143f2261f0f8612c941822e3bf9e1704a0947add8a5a6b3630d069e79f9c4e
4
- data.tar.gz: e3e30bab0949f25f2a7e4abd91ed104bca8b81bee06ddb65ce143fae6cfcbbe4
3
+ metadata.gz: 2cfe4cf4f1234c7c3f852e1911915151a1108e064f6928b76dba908eab08143a
4
+ data.tar.gz: 8582312348fd9d1af9155d86e0e51e821da5a53978941b74adc0d2c13dcf420e
5
5
  SHA512:
6
- metadata.gz: 241e27e10d7d9679b110ef7e2074b783dce578082606518c5d07afad8b857e77c7106ba6d7b0d4bb1f46427f8defd184f75a25540cdca8886f5c30a758a02b61
7
- data.tar.gz: 20785a03ed7d6c4b80dddce9d6c703676e03735fdd99bfbb78e60cd5587efbf2d9bebe24d23f21bbc6dfc2f1ddca389dc1ff0c117fb4c33ab61caf1185123615
6
+ metadata.gz: 3b2f41b42b75041a7c78e8b89bdf38c7e5c967727529da14072dc448987e0341788f3918d1017e5deedf34698e21cf86e6f41292c25909f32fe2b696ce79da3c
7
+ data.tar.gz: 73068fcca32e8c96ba4a5c4960f6edddd4f1853f4c2205fb4212aafa9dc69c90781dd3dd16a11517a07302f59178a9454407a6bde09db291f5e9ae6c22fe1033
@@ -1,3 +1,3 @@
1
1
  module EffectivePolls
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_polls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-29 00:00:00.000000000 Z
11
+ date: 2026-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -243,12 +243,8 @@ files:
243
243
  - app/mailers/effective/polls_mailer.rb
244
244
  - app/models/concerns/effective_polls_user.rb
245
245
  - app/models/effective/ballot.rb
246
- - app/models/effective/ballot_response.rb
247
- - app/models/effective/ballot_response_option.rb
248
246
  - app/models/effective/poll.rb
249
247
  - app/models/effective/poll_notification.rb
250
- - app/models/effective/poll_question.rb
251
- - app/models/effective/poll_question_option.rb
252
248
  - app/views/admin/poll_notifications/_form.html.haml
253
249
  - app/views/admin/poll_notifications/_form_poll_before_poll_ends.html.haml
254
250
  - app/views/admin/poll_notifications/_form_poll_reminder.html.haml
@@ -1,94 +0,0 @@
1
- # TO BE DELETED
2
-
3
- module Effective
4
- class BallotResponse < ActiveRecord::Base
5
- belongs_to :ballot
6
-
7
- belongs_to :poll
8
- belongs_to :poll_question
9
-
10
- has_many :ballot_response_options, dependent: :delete_all
11
- has_many :poll_question_options, through: :ballot_response_options
12
-
13
- has_one_attached :upload_file
14
-
15
- effective_resource do
16
- # The response
17
- date :date
18
- email :string
19
- number :integer
20
- long_answer :text
21
- short_answer :text
22
-
23
- timestamps
24
- end
25
-
26
- scope :completed, -> { where(ballot: Effective::Ballot.completed) }
27
- scope :deep, -> { includes(:ballot, :poll, :poll_question, :poll_question_options) }
28
-
29
- validates :poll, presence: true
30
- validates :ballot, presence: true
31
- validates :poll_question, presence: true
32
-
33
- # Sanity check. These shouldn't happen.
34
- validate(if: -> { poll.present? && ballot.present? }) do
35
- self.errors.add(:ballot, 'must match poll') unless ballot.poll_id == poll.id
36
- end
37
-
38
- validate(if: -> { poll.present? && poll_question.present? }) do
39
- self.errors.add(:poll_question, 'must match poll') unless poll_question.poll_id == poll.id
40
- end
41
-
42
- validates :date, presence: true, if: -> { poll_question&.required? && poll_question.date? }
43
- validates :email, presence: true, email: true, if: -> { poll_question&.required? && poll_question.email? }
44
- validates :number, presence: true, if: -> { poll_question&.required? && poll_question.number? }
45
- validates :long_answer, presence: true, if: -> { poll_question&.required? && poll_question.long_answer? }
46
- validates :short_answer, presence: true, if: -> { poll_question&.required? && poll_question.short_answer? }
47
- validates :upload_file, presence: true, if: -> { poll_question&.required? && poll_question.upload_file? }
48
- validates :poll_question_option_ids, presence: true, if: -> { poll_question&.required? && poll_question.poll_question_option? }
49
-
50
- validates :poll_question_option_ids, if: -> { poll_question&.choose_one? },
51
- length: { maximum: 1, message: 'please choose 1 option only' }
52
-
53
- validates :poll_question_option_ids, if: -> { poll_question&.select_up_to_1? },
54
- length: { maximum: 1, message: 'please select 1 option or fewer' }
55
-
56
- validates :poll_question_option_ids, if: -> { poll_question&.select_up_to_2? },
57
- length: { maximum: 2, message: 'please select 2 options or fewer' }
58
-
59
- validates :poll_question_option_ids, if: -> { poll_question&.select_up_to_3? },
60
- length: { maximum: 3, message: 'please select 3 options or fewer' }
61
-
62
- validates :poll_question_option_ids, if: -> { poll_question&.select_up_to_4? },
63
- length: { maximum: 4, message: 'please select 4 options or fewer' }
64
-
65
- validates :poll_question_option_ids, if: -> { poll_question&.select_up_to_5? },
66
- length: { maximum: 5, message: 'please select 5 options or fewer' }
67
-
68
- def to_s
69
- model_name.human
70
- end
71
-
72
- def response
73
- return nil unless poll_question.present?
74
-
75
- return date if poll_question.date?
76
- return email if poll_question.email?
77
- return number if poll_question.number?
78
- return long_answer if poll_question.long_answer?
79
- return short_answer if poll_question.short_answer?
80
- return upload_file if poll_question.upload_file?
81
-
82
- return poll_question_options.first if poll_question.choose_one?
83
- return poll_question_options.first if poll_question.select_up_to_1?
84
- return poll_question_options if poll_question.poll_question_option?
85
-
86
- raise('unknown response for unexpected poll question category')
87
- end
88
-
89
- def category_partial
90
- poll_question&.category_partial
91
- end
92
-
93
- end
94
- end
@@ -1,8 +0,0 @@
1
- # TO BE DELETED
2
-
3
- module Effective
4
- class BallotResponseOption < ActiveRecord::Base
5
- belongs_to :ballot_response
6
- belongs_to :poll_question_option
7
- end
8
- end
@@ -1,124 +0,0 @@
1
- # TO BE DELETED
2
-
3
- module Effective
4
- class PollQuestion < ActiveRecord::Base
5
- belongs_to :poll
6
-
7
- belongs_to :poll_question, optional: true # Present when I'm a follow up question
8
- belongs_to :poll_question_option, optional: true # Might be present when I'm a follow up question
9
-
10
- has_many :poll_question_options, -> { order(:position) }, inverse_of: :poll_question, dependent: :delete_all
11
- accepts_nested_attributes_for :poll_question_options, reject_if: :all_blank, allow_destroy: true
12
-
13
- has_many :follow_up_poll_questions, -> { order(:position) }, class_name: 'Effective::PollQuestion', foreign_key: :poll_question_id, dependent: :destroy
14
-
15
- has_rich_text :body
16
- log_changes(to: :poll) if respond_to?(:log_changes)
17
-
18
- CATEGORIES = [
19
- 'Choose one', # Radios
20
- 'Select all that apply', # Checks
21
- 'Select up to 1',
22
- 'Select up to 2',
23
- 'Select up to 3',
24
- 'Select up to 4',
25
- 'Select up to 5',
26
- 'Date', # Date Field
27
- 'Email', # Email Field
28
- 'Number', # Numeric Field
29
- 'Long Answer', # Text Area
30
- 'Short Answer', # Text Field
31
- 'Upload File' # File field
32
- ]
33
-
34
- WITH_OPTIONS_CATEGORIES = [
35
- 'Choose one', # Radios
36
- 'Select all that apply', # Checks
37
- 'Select up to 1',
38
- 'Select up to 2',
39
- 'Select up to 3',
40
- 'Select up to 4',
41
- 'Select up to 5'
42
- ]
43
-
44
- UNSUPPORTED_FOLLOW_UP_QUESTION_CATEGORIES = ['Upload File']
45
-
46
- effective_resource do
47
- title :string
48
- category :string
49
- required :boolean
50
-
51
- position :integer
52
-
53
- follow_up :boolean
54
- follow_up_value :string
55
-
56
- timestamps
57
- end
58
-
59
- before_validation(if: -> { poll_question.present? }) do
60
- assign_attributes(poll: poll_question.poll)
61
- end
62
-
63
- # Set position
64
- before_validation do
65
- source = poll_question_option.try(:follow_up_poll_questions) || poll.try(:poll_questions) || []
66
- self.position = (source.map { |obj| obj.position }.compact.max || -1) + 1
67
- end
68
-
69
- scope :deep, -> { with_rich_text_body_and_embeds.includes(:poll_question_options) }
70
- scope :sorted, -> { order(:position) }
71
-
72
- scope :top_level, -> { where(follow_up: false) }
73
- scope :follow_up, -> { where(follow_up: true) }
74
-
75
- validates :title, presence: true
76
- validates :category, presence: true, inclusion: { in: CATEGORIES }
77
- validates :position, presence: true
78
- validates :poll_question_options, presence: true, if: -> { poll_question_option? }
79
-
80
- validates :poll_question, presence: true, if: -> { follow_up? }
81
- validates :poll_question_option, presence: true, if: -> { follow_up? && poll_question.try(:poll_question_option?) }
82
- validates :follow_up_value, presence: true, if: -> { follow_up? && !poll_question.try(:poll_question_option?) }
83
-
84
- # Create choose_one? and select_all_that_apply? methods for each category
85
- CATEGORIES.each do |category|
86
- define_method(category.parameterize.underscore + '?') { self.category == category }
87
- end
88
-
89
- def to_s
90
- title.presence || model_name.human
91
- end
92
-
93
- def show_if_attribute
94
- return :poll_question_option_ids if poll_question_option?
95
-
96
- case category
97
- when 'Date' then :date
98
- when 'Email' then :email
99
- when 'Number' then :number
100
- when 'Long Answer' then :long_answer
101
- when 'Short Answer' then :short_answer
102
- when 'Upload File' then :upload_file
103
- else :unknown
104
- end
105
- end
106
-
107
- def show_if_value
108
- poll_question.try(:poll_question_option?) ? poll_question_option_id : follow_up_value
109
- end
110
-
111
- def show_if_value_to_s
112
- (poll_question.try(:poll_question_option?) ? poll_question_option : follow_up_value).to_s
113
- end
114
-
115
- def poll_question_option?
116
- WITH_OPTIONS_CATEGORIES.include?(category)
117
- end
118
-
119
- def category_partial
120
- category.to_s.parameterize.underscore
121
- end
122
-
123
- end
124
- end
@@ -1,28 +0,0 @@
1
- # TO BE DELETED
2
-
3
- module Effective
4
- class PollQuestionOption < ActiveRecord::Base
5
- belongs_to :poll_question
6
-
7
- effective_resource do
8
- title :text
9
- position :integer
10
-
11
- timestamps
12
- end
13
-
14
- before_validation(if: -> { poll_question.present? }) do
15
- self.position ||= (poll_question.poll_question_options.map { |obj| obj.position }.compact.max || -1) + 1
16
- end
17
-
18
- scope :sorted, -> { order(:position) }
19
-
20
- validates :title, presence: true
21
- validates :position, presence: true
22
-
23
- def to_s
24
- title.presence || model_name.human
25
- end
26
-
27
- end
28
- end