Class: SpreeCmCommissioner::VoteProcessor
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::VoteProcessor
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/vote_processor.rb
Instance Attribute Summary collapse
-
#contestant ⇒ Object
readonly
Returns the value of attribute contestant.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#voting_session ⇒ Object
readonly
Returns the value of attribute voting_session.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(voting_session:, contestant:, user:, params: {}, request: nil) ⇒ VoteProcessor
constructor
A new instance of VoteProcessor.
Constructor Details
#initialize(voting_session:, contestant:, user:, params: {}, request: nil) ⇒ VoteProcessor
Returns a new instance of VoteProcessor.
22 23 24 25 26 27 28 |
# File 'app/services/spree_cm_commissioner/vote_processor.rb', line 22 def initialize(voting_session:, contestant:, user:, params: {}, request: nil) @voting_session = voting_session @contestant = contestant @user = user @params = params @request = request end |
Instance Attribute Details
#contestant ⇒ Object (readonly)
Returns the value of attribute contestant.
20 21 22 |
# File 'app/services/spree_cm_commissioner/vote_processor.rb', line 20 def contestant @contestant end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
20 21 22 |
# File 'app/services/spree_cm_commissioner/vote_processor.rb', line 20 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
20 21 22 |
# File 'app/services/spree_cm_commissioner/vote_processor.rb', line 20 def request @request end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
20 21 22 |
# File 'app/services/spree_cm_commissioner/vote_processor.rb', line 20 def user @user end |
#voting_session ⇒ Object (readonly)
Returns the value of attribute voting_session.
20 21 22 |
# File 'app/services/spree_cm_commissioner/vote_processor.rb', line 20 def voting_session @voting_session end |
Instance Method Details
#call ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/services/spree_cm_commissioner/vote_processor.rb', line 30 def call validate! vote = nil ActiveRecord::Base.transaction do check_fraud! credit = allocate_credit vote = persist_vote!(credit) end increment_redis_counter(vote) success(vote) rescue RuntimeError, ActiveRecord::RecordInvalid, ArgumentError => e failure(nil, e.) rescue StandardError => e CmAppLogger.error( label: 'VoteProcessor unexpected error', data: { voting_session_id: voting_session.id, contestant_id: contestant.id, user_id: user&.id, error_class: e.class.name, error_message: e., backtrace: e.backtrace&.first(5)&.join("\n") } ) failure(nil, 'Vote could not be processed') end |