Class: SpreeCmCommissioner::Show

Inherits:
Spree::Taxon
  • Object
show all
Includes:
StoreMetadata
Defined in:
app/models/spree_cm_commissioner/show.rb

Constant Summary collapse

SHOW_TYPES =
%w[show tournament boxing].freeze
CREDIT_SCOPES =

voting_credit_scope determines how purchased vote credits are grouped (scoped). Changing this after credits have been allocated will cause inconsistencies:

- existing credits are scoped to the old type (e.g. ShowEpisode),
  but new purchases will create credits under the new type (e.g. Show),
  leading to split balances that cannot be merged.

UI rule: once voting_credit_scope is set and any VotingCredit exists for this show, the field must be read-only — do not allow changes. Note: VoteCredit of user should base on CREDIT_SCOPES

- if scope is Show, User's credits should be only 1 per show, and can be used for any episode under the show.
- if scope is ShowEpisode, User's credits should be N per show (N is the number of episodes), and can be only used for specific episode.
- if scope is VotingSession, User's credits should be N per show (N is the number of voting sessions), and can be only used for specific voting session. # rubocop:disable Layout/LineLength
{
  'Show' => { free_vote_limit_type: 'per_show' }.freeze,
  'ShowEpisode' => { free_vote_limit_type: 'per_episode' }.freeze,
  'VotingSession' => { free_vote_limit_type: 'per_voting_session' }.freeze
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#claimedObject

Define standard voting configuration keys



30
31
32
# File 'app/models/spree_cm_commissioner/show.rb', line 30

def claimed
  @claimed
end

#effective_free_vote_limitObject

Define standard voting configuration keys



30
31
32
# File 'app/models/spree_cm_commissioner/show.rb', line 30

def effective_free_vote_limit
  @effective_free_vote_limit
end

#effective_free_vote_limit_typeObject

Define standard voting configuration keys



30
31
32
# File 'app/models/spree_cm_commissioner/show.rb', line 30

def effective_free_vote_limit_type
  @effective_free_vote_limit_type
end

Class Method Details

.polymorphic_nameObject



59
60
61
# File 'app/models/spree_cm_commissioner/show.rb', line 59

def self.polymorphic_name
  name
end

Instance Method Details

#build_next_season(attributes = {}) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/models/spree_cm_commissioner/show.rb', line 124

def build_next_season(attributes = {})
  last_season = seasons.order(created_at: :desc).first

  default_number = (last_season&.season_number || 0) + 1
  default_year = last_season&.season_year || Time.current.year

  seasons.new(
    {
      season_number: default_number,
      season_year: default_year
    }.merge(attributes)
  )
end

#contestantsObject



106
107
108
# File 'app/models/spree_cm_commissioner/show.rb', line 106

def contestants
  show_contestants
end

#credit_votable_typeObject



65
66
67
68
69
70
# File 'app/models/spree_cm_commissioner/show.rb', line 65

def credit_votable_type
  voting_credit_scope = self[:voting_credit_scope] || 'ShowEpisode'

  type = CREDIT_SCOPES.key?(voting_credit_scope) ? voting_credit_scope : 'ShowEpisode'
  "SpreeCmCommissioner::#{type}"
end

#display_nameObject



98
99
100
101
102
103
104
# File 'app/models/spree_cm_commissioner/show.rb', line 98

def display_name
  if season? && parent.present?
    "#{parent.name} #{name}"
  else
    name
  end
end

#effective_fraud_configObject



117
118
119
120
121
122
# File 'app/models/spree_cm_commissioner/show.rb', line 117

def effective_fraud_config
  config = parse_json_config(fraud_config)
  return config if show?

  config.reverse_merge(parent&.effective_fraud_config || {})
end

#effective_voting_configObject



110
111
112
113
114
115
# File 'app/models/spree_cm_commissioner/show.rb', line 110

def effective_voting_config
  config = parse_json_config(voting_config)
  return config if show?

  config.reverse_merge(parent&.effective_voting_config || {})
end

#free_vote_idempotency_key(user_id:, votable_id: nil, limit_type: nil) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'app/models/spree_cm_commissioner/show.rb', line 72

def free_vote_idempotency_key(user_id:, votable_id: nil, limit_type: nil)
  effective_limit_type = limit_type || free_vote_limit_type
  case effective_limit_type
  when 'per_episode'        then "free_claim::episode::#{votable_id}::user::#{user_id}"
  when 'per_voting_session' then "free_claim::voting_session::#{votable_id}::user::#{user_id}"
  when 'per_show'           then "free_claim::show::#{id}::user::#{user_id}"
  else raise ArgumentError, "Invalid free_vote_limit_type: #{effective_limit_type}"
  end
end

#season?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/spree_cm_commissioner/show.rb', line 94

def season?
  depth == 2
end

#show?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/models/spree_cm_commissioner/show.rb', line 90

def show?
  depth == 1
end