Class: StripeModelCallbacks::Subscription::StateCheckerService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/stripe_model_callbacks/subscription/state_checker_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allowed:, state:) ⇒ StateCheckerService

Returns a new instance of StateCheckerService.



4
5
6
7
# File 'app/services/stripe_model_callbacks/subscription/state_checker_service.rb', line 4

def initialize(allowed:, state:)
  @allowed = allowed
  @state = state.to_s
end

Instance Attribute Details

#allowedObject (readonly)

Returns the value of attribute allowed.



2
3
4
# File 'app/services/stripe_model_callbacks/subscription/state_checker_service.rb', line 2

def allowed
  @allowed
end

#stateObject (readonly)

Returns the value of attribute state.



2
3
4
# File 'app/services/stripe_model_callbacks/subscription/state_checker_service.rb', line 2

def state
  @state
end

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/stripe_model_callbacks/subscription/state_checker_service.rb', line 9

def execute
  if state.is_a?(Array)
    state.each do |state_i|
      response = Subscription::StateCheckerService.execute!(allowed: allowed, state: state_i)
      return response unless response.success?
    end
  elsif !allowed.include?(state)
    return fail! ["Not allowed: #{state}"]
  end

  succeed!
end