Last active
April 3, 2024 12:21
-
-
Save Melrt/f88102501119c8f246d245b0853f13ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/subscriptions/application_controller.rb | |
class Subscriptions::ApplicationController < ApplicationController | |
def steps_provider | |
# current_step est défini dans chaque controller | |
@steps_provider ||= StepsProvider.new(@subscription, current_step) | |
end | |
helper_method(:steps_provider) | |
def subscription_steps | |
steps_provider.steps | |
end | |
helper_method(:subscription_steps) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/steps/base_step.rb | |
class BaseStep | |
include Rails.application.routes.url_helpers | |
attr_reader :name | |
def initialize(subscription, name) | |
@subscription = subscription | |
@name = name | |
end | |
def link | |
# Route de l'étape | |
"#" | |
end | |
def visible? | |
true | |
end | |
def completed? | |
# Définir la logique pour vérifier si l'étape est complétée, ou mieux, mettre la policy associée à l'étape | |
false | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/providers/steps_provider.rb | |
class StepsProvider | |
def initialize(subscription, current_step_name) | |
@subscription = subscription | |
@current_step_name = current_step_name | |
end | |
def steps | |
@__steps ||= steps_list.select(&:visible?) | |
end | |
private | |
def steps_list | |
[ | |
UserDetailsStep.new(@subscription, :user_details_step), | |
# Ajoutez d'autres étapes ici en suivant le modèle ci-dessus | |
] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/steps/user_information_step.rb | |
class UserDetailsStep < BaseStep | |
def step_link | |
edit_subscriptions_user_details_path(@subscription) | |
end | |
def completed? | |
@subscription.user.extend(UsersDetailsValidation).valid? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment