Module: UnlockGateway::Models::Contribution
- Defined in:
- lib/unlock_gateway/models/contribution.rb
Overview
Your module UnlockMyGatewayName::Models::Contribution, that should implement this interface, will be included in Unlock’s Contribution model. All methods will run in the context of an instance of Contribution model.
Instance Method Summary collapse
-
#gateway_identifier ⇒ Object
This method should return the unique identifier of the contribution on the gateway.
-
#state_on_gateway ⇒ Object
This method should return the actual state of a contribution on the gateway, with name according to Contribution’s state machine, as a Symbol.
-
#transition_by_state(state) ⇒ Object
Helper method to find transition name by the desired new state name.
-
#update_state_from_gateway! ⇒ Object
Updates the contribution’s state according to it’s actual state within the gateway, based on each gateway’s implementation of state_on_gateway.
-
#update_state_on_gateway!(state) ⇒ Object
This method should change the state of a contribution on the gateway, according to the new desired state.
Instance Method Details
#gateway_identifier ⇒ Object
This method should return the unique identifier of the contribution on the gateway
8 9 |
# File 'lib/unlock_gateway/models/contribution.rb', line 8 def gateway_identifier end |
#state_on_gateway ⇒ Object
This method should return the actual state of a contribution on the gateway, with name according to Contribution’s state machine, as a Symbol.
12 13 |
# File 'lib/unlock_gateway/models/contribution.rb', line 12 def state_on_gateway end |
#transition_by_state(state) ⇒ Object
Helper method to find transition name by the desired new state name
29 30 31 32 33 34 35 36 37 |
# File 'lib/unlock_gateway/models/contribution.rb', line 29 def transition_by_state(state) state = state.try(:to_sym) case state when :active :activate when :suspended :suspend end end |
#update_state_from_gateway! ⇒ Object
Updates the contribution’s state according to it’s actual state within the gateway, based on each gateway’s implementation of state_on_gateway.
20 21 22 23 24 25 26 |
# File 'lib/unlock_gateway/models/contribution.rb', line 20 def update_state_from_gateway! return unless gateway_state = self.state_on_gateway if self.state_name != gateway_state transition = self.transition_by_state(gateway_state) self.send("#{transition}!") if self.send("can_#{transition}?") end end |
#update_state_on_gateway!(state) ⇒ Object
This method should change the state of a contribution on the gateway, according to the new desired state.
16 17 |
# File 'lib/unlock_gateway/models/contribution.rb', line 16 def update_state_on_gateway!(state) end |