Module: RailsOnboarding::Personalizable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/rails_onboarding/personalizable.rb
Overview
Concern for personalization capabilities on User models Adapts onboarding flows based on user type, role, or other attributes
Instance Method Summary collapse
-
#personalization_type ⇒ Symbol, String
Get the user's type for personalization.
-
#personalized_first_step? ⇒ Boolean
Check if this is the first step in the personalized flow.
-
#personalized_last_step? ⇒ Boolean
Check if this is the last step in the personalized flow.
-
#personalized_next_step ⇒ Hash?
Get the next step in the personalized flow.
-
#personalized_previous_step ⇒ Hash?
Get the previous step in the personalized flow.
-
#personalized_progress_percentage ⇒ Integer
Get the progress percentage for the personalized flow.
-
#personalized_recommendations ⇒ Array<Hash>
Get recommended next actions based on user type.
-
#personalized_step_by_name(name) ⇒ Hash?
Get a specific step from the personalized flow.
-
#personalized_step_index(name) ⇒ Integer?
Get the index of a step in the personalized flow.
-
#personalized_steps ⇒ Array<Hash>
Get the personalized onboarding steps for this user.
-
#personalized_total_steps ⇒ Integer
Get the total number of steps in the personalized flow.
-
#show_personalized_feature?(feature_name) ⇒ Boolean
Check if a specific feature should be shown to this user type.
Instance Method Details
#personalization_type ⇒ Symbol, String
Get the user's type for personalization
44 45 46 47 48 49 50 51 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 44 def personalization_type return nil unless RailsOnboarding.configuration.personalization_enabled method_name = RailsOnboarding.configuration.user_type_method return nil unless respond_to?(method_name) send(method_name) end |
#personalized_first_step? ⇒ Boolean
Check if this is the first step in the personalized flow
125 126 127 128 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 125 def personalized_first_step? return false if onboarding_current_step.nil? personalized_step_index(onboarding_current_step)&.zero? || false end |
#personalized_last_step? ⇒ Boolean
Check if this is the last step in the personalized flow
133 134 135 136 137 138 139 140 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 133 def personalized_last_step? return false if onboarding_current_step.nil? current_index = personalized_step_index(onboarding_current_step) return false if current_index.nil? current_index == personalized_total_steps - 1 end |
#personalized_next_step ⇒ Hash?
Get the next step in the personalized flow
98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 98 def personalized_next_step return nil if onboarding_current_step.nil? current_index = personalized_step_index(onboarding_current_step) return nil if current_index.nil? next_index = current_index + 1 return nil if next_index >= personalized_total_steps personalized_steps[next_index] end |
#personalized_previous_step ⇒ Hash?
Get the previous step in the personalized flow
113 114 115 116 117 118 119 120 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 113 def personalized_previous_step return nil if onboarding_current_step.nil? current_index = personalized_step_index(onboarding_current_step) return nil if current_index.nil? || current_index.zero? personalized_steps[current_index - 1] end |
#personalized_progress_percentage ⇒ Integer
Get the progress percentage for the personalized flow
145 146 147 148 149 150 151 152 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 145 def personalized_progress_percentage return 0 if onboarding_current_step.nil? current_index = personalized_step_index(onboarding_current_step) return 0 if current_index.nil? ((current_index + 1).to_f / personalized_total_steps * 100).round end |
#personalized_recommendations ⇒ Array<Hash>
Get recommended next actions based on user type
179 180 181 182 183 184 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 179 def personalized_recommendations return [] unless RailsOnboarding.configuration.personalization_enabled return [] unless respond_to?(:personalization_recommendations) send(:personalization_recommendations) end |
#personalized_step_by_name(name) ⇒ Hash?
Get a specific step from the personalized flow
81 82 83 84 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 81 def personalized_step_by_name(name) return nil if name.nil? personalized_steps.find { |s| s[:name].to_s == name.to_s } end |
#personalized_step_index(name) ⇒ Integer?
Get the index of a step in the personalized flow
90 91 92 93 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 90 def personalized_step_index(name) return nil if name.nil? personalized_steps.find_index { |s| s[:name].to_s == name.to_s } end |
#personalized_steps ⇒ Array<Hash>
Get the personalized onboarding steps for this user
60 61 62 63 64 65 66 67 68 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 60 def personalized_steps return RailsOnboarding.configuration.steps unless RailsOnboarding.configuration.personalization_enabled user_type = personalization_type return RailsOnboarding.configuration.steps unless user_type flow = RailsOnboarding.configuration.personalized_flow(user_type) flow || RailsOnboarding.configuration.steps end |
#personalized_total_steps ⇒ Integer
Get the total number of steps in the personalized flow
73 74 75 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 73 def personalized_total_steps personalized_steps.size end |
#show_personalized_feature?(feature_name) ⇒ Boolean
Check if a specific feature should be shown to this user type
162 163 164 165 166 167 168 169 170 |
# File 'app/models/concerns/rails_onboarding/personalizable.rb', line 162 def show_personalized_feature?(feature_name) return true unless RailsOnboarding.configuration.personalization_enabled user_type = personalization_type return true unless user_type # Check if feature is in the personalized steps personalized_steps.any? { |step| step[:name].to_s == feature_name.to_s } end |