Class: SpreeCmCommissioner::VotingSession
Constant Summary
collapse
- DEFAULT_SUGGESTION_TOP_N =
1
Class Method Summary
collapse
Instance Method Summary
collapse
#embedded_live_stream_url
Class Method Details
.current_or_next_upcoming ⇒ Object
Priority 1: Current session wins over Upcoming session. Priority 2: Follow manual position (Managed by acts_as_list).
63
64
65
66
67
68
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 63
def self.current_or_next_upcoming
current.or(upcoming).order(
Arel.sql('CASE WHEN opens_at <= CURRENT_TIMESTAMP AND closes_at >= CURRENT_TIMESTAMP THEN 0 ELSE 1 END'),
:position
)
end
|
Instance Method Details
#active? ⇒ Boolean
45
46
47
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 45
def active?
enabled? && Time.current.between?(opens_at, closes_at)
end
|
#can_vote? ⇒ Boolean
122
123
124
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 122
def can_vote?
enabled? && Time.zone.now.between?(opens_at, closes_at) && !manual_advance?
end
|
#effective_fraud_config ⇒ Object
114
115
116
117
118
119
120
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 114
def effective_fraud_config
return {} unless show
config = parse_json_config(fraud_config)
show_config = show.effective_fraud_config
config.reverse_merge(show_config || {})
end
|
#effective_suggestion_top_n ⇒ Object
96
97
98
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 96
def effective_suggestion_top_n
suggestion_top_n&.to_i&.positive? ? suggestion_top_n.to_i : DEFAULT_SUGGESTION_TOP_N
end
|
#effective_voting_config(show_config: nil) ⇒ Object
106
107
108
109
110
111
112
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 106
def effective_voting_config(show_config: nil)
return {} unless show
show_config ||= show.effective_voting_config
session_config = parse_json_config(voting_config).compact
show_config.merge(session_config)
end
|
#find_or_create_voting_contestant(show_contestant) ⇒ Object
100
101
102
103
104
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 100
def find_or_create_voting_contestant(show_contestant)
voting_contestants.find_or_create_by!(show_contestant: show_contestant) do |vc|
vc.show_id = show.id
end
end
|
#first_in_episode? ⇒ Boolean
True when this session is the first in its episode. e.g. position=1 → true; position=2 → false
134
135
136
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 134
def first_in_episode?
position == 1
end
|
#max_votes_per_user ⇒ Object
146
147
148
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 146
def max_votes_per_user
effective_voting_config['max_votes_per_user'] || 10
end
|
#missing_show_contestants ⇒ Object
Show contestants expected in this session but not yet assigned. episode.season.show_contestants → all contestants on the season this episode belongs to. show_contestants → already assigned to this voting session. e.g. season has [Alice(active), Bob(active), Carol(eliminated)]; session only has [Alice] → returns [Bob]
142
143
144
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 142
def missing_show_contestants
episode.season.show_contestants.active.where.not(id: show_contestants.select(:id)).ordered
end
|
#next_in_episode ⇒ Object
Returns the next advanceable session within the same episode (by position). Excludes pre_vote sessions. e.g. current session position=1 → returns session at position=2; last session → nil
128
129
130
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 128
def next_in_episode
episode.voting_sessions.where('position > ?', position).where(session_type: %i[vote manual_advance]).order(:position).first
end
|
#past? ⇒ Boolean
53
54
55
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 53
def past?
closed? || (closes_at.present? && Time.current > closes_at)
end
|
#paused? ⇒ Boolean
57
58
59
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 57
def paused?
disabled? && Time.current.between?(opens_at, closes_at)
end
|
#rate_limit_max_votes ⇒ Object
154
155
156
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 154
def rate_limit_max_votes
effective_voting_config['rate_limit_max_votes'] || 5
end
|
#rate_limit_window ⇒ Object
150
151
152
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 150
def rate_limit_window
effective_voting_config['rate_limit_window'] || 60
end
|
#upcoming? ⇒ Boolean
49
50
51
|
# File 'app/models/spree_cm_commissioner/voting_session.rb', line 49
def upcoming?
enabled? && Time.current < opens_at
end
|