onboardable 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2f8dab433ffdae729d520f952885f1023821f8174bfcf761d7e8b81ed4970e2f
4
+ data.tar.gz: a2abc67ae9936358c9742bd5e3c39a98f4a97e134d12ca7ece4773a235296763
5
+ SHA512:
6
+ metadata.gz: 8f1ec81d701796ba14700f104ba424d73d27dc6dca04b172dad575d3b9b4fb925997caf6491f95400aedb7d7b8d0d8e00ed5b4c24206c88ff72808e22462f625
7
+ data.tar.gz: 7518e5c2d5713bc2ce3db3c5f50d136c92c328b9eeccc045e9c59c60dbfab4b0d240cbc107e1ddbc0779ca6e36aa64108e7b0eaff17afb975d2f5877fbc03dcd
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --order rand
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+ - rubocop-rake
5
+
6
+ AllCops:
7
+ NewCops: enable
8
+ TargetRubyVersion: 3.0.0
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Gemspec/DevelopmentDependencies:
14
+ EnforcedStyle: gemspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # CHANGELOG
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.1.0] - 2024-03-2
6
+
7
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at skrynnyk.artem@coaxsoft.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in onboardable.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ onboardable (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.1)
11
+ docile (1.4.0)
12
+ json (2.7.2)
13
+ language_server-protocol (3.17.0.3)
14
+ parallel (1.24.0)
15
+ parser (3.3.1.0)
16
+ ast (~> 2.4.1)
17
+ racc
18
+ racc (1.7.3)
19
+ rainbow (3.1.1)
20
+ rake (13.2.1)
21
+ regexp_parser (2.9.0)
22
+ rexml (3.2.6)
23
+ rspec (3.13.0)
24
+ rspec-core (~> 3.13.0)
25
+ rspec-expectations (~> 3.13.0)
26
+ rspec-mocks (~> 3.13.0)
27
+ rspec-core (3.13.0)
28
+ rspec-support (~> 3.13.0)
29
+ rspec-expectations (3.13.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.13.0)
32
+ rspec-mocks (3.13.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-support (3.13.1)
36
+ rubocop (1.63.4)
37
+ json (~> 2.3)
38
+ language_server-protocol (>= 3.17.0)
39
+ parallel (~> 1.10)
40
+ parser (>= 3.3.0.2)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ regexp_parser (>= 1.8, < 3.0)
43
+ rexml (>= 3.2.5, < 4.0)
44
+ rubocop-ast (>= 1.31.1, < 2.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 2.4.0, < 3.0)
47
+ rubocop-ast (1.31.3)
48
+ parser (>= 3.3.1.0)
49
+ rubocop-capybara (2.20.0)
50
+ rubocop (~> 1.41)
51
+ rubocop-factory_bot (2.25.1)
52
+ rubocop (~> 1.41)
53
+ rubocop-performance (1.21.0)
54
+ rubocop (>= 1.48.1, < 2.0)
55
+ rubocop-ast (>= 1.31.1, < 2.0)
56
+ rubocop-rake (0.6.0)
57
+ rubocop (~> 1.0)
58
+ rubocop-rspec (2.29.2)
59
+ rubocop (~> 1.40)
60
+ rubocop-capybara (~> 2.17)
61
+ rubocop-factory_bot (~> 2.22)
62
+ rubocop-rspec_rails (~> 2.28)
63
+ rubocop-rspec_rails (2.28.3)
64
+ rubocop (~> 1.40)
65
+ ruby-progressbar (1.13.0)
66
+ simplecov (0.22.0)
67
+ docile (~> 1.1)
68
+ simplecov-html (~> 0.11)
69
+ simplecov_json_formatter (~> 0.1)
70
+ simplecov-html (0.12.3)
71
+ simplecov_json_formatter (0.1.4)
72
+ unicode-display_width (2.5.0)
73
+
74
+ PLATFORMS
75
+ x86_64-darwin-23
76
+ x86_64-linux
77
+
78
+ DEPENDENCIES
79
+ onboardable!
80
+ rake (~> 13.2, >= 13.2.1)
81
+ rspec (~> 3.13)
82
+ rubocop (~> 1.63, >= 1.63.4)
83
+ rubocop-performance (~> 1.21)
84
+ rubocop-rake (~> 0.6.0)
85
+ rubocop-rspec (~> 2.29, >= 2.29.2)
86
+ simplecov (~> 0.22.0)
87
+
88
+ BUNDLED WITH
89
+ 2.5.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Artem Skrynnyk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # 🚀 Onboardable
2
+
3
+ ![Build](https://img.shields.io/github/actions/workflow/status/dmrAnderson/onboardable/ci.yml)
4
+ ![Code Coverage](https://img.shields.io/coverallsCoverage/github/dmrAnderson/onboardable)
5
+
6
+ The Onboardable gem is a Ruby module designed to simplify and streamline the
7
+ process of managing and navigating through a series of steps or stages within
8
+ an application, typically used for user onboarding workflows. By including
9
+ the Onboardable module in a class, developers can easily define a sequence
10
+ of onboarding steps, handle transitions between these steps, and maintain
11
+ the state of the current step in the sequence.
12
+
13
+ ## 🔌 Installation
14
+
15
+ Install the gem and add to the application's Gemfile by executing:
16
+
17
+ ```shell
18
+ bundle add onboardable
19
+ ```
20
+
21
+ If bundler is not being used to manage dependencies, install the gem by executing:
22
+
23
+ ```shell
24
+ gem install onboardable
25
+ ```
26
+
27
+ ## ⚙️ Usage
28
+
29
+ First, ensure that the Onboardable gem is installed and properly set up in your
30
+ project as per the installation guide provided earlier.
31
+
32
+ ### Basic Configuration
33
+
34
+ 1. **Include Onboardable in Your Class**
35
+
36
+ Decide which Ruby class should have the onboarding process.
37
+ For example, if you want to add an onboarding process to a `User`
38
+ class, you would modify the class as follows:
39
+
40
+ ```ruby
41
+ class User
42
+ include Onboardable
43
+ end
44
+ ```
45
+
46
+ 1. **Define Onboarding Steps**
47
+
48
+ You can define the steps involved in the onboarding process using
49
+ the `has_onboarding` method provided by the gem. Here's an example of
50
+ how to define a simple onboarding process with custom steps,
51
+ potentially including specific data for each step:
52
+
53
+ ```ruby
54
+ class User
55
+ has_onboarding do
56
+ step 'Create Account', tooltip: 'Minimum 8 characters.'
57
+ step('Verify Email', Class.new { def self.to_hash = { required: true } })
58
+ step 'Complete Profile' # This step does not include specific action data
59
+ step 'Introduction Tour', description: 'Get to know your new workspace!'
60
+ end
61
+ end
62
+ ```
63
+
64
+ ### Using the Onboarding Steps
65
+
66
+ To enhance the guidance for users on how to navigate and manage the
67
+ onboarding flow using the Onboardable gem, here's a concise guide that
68
+ could be included in the documentation. This guide covers initialization,
69
+ navigation, step verification, and completion of the onboarding process.
70
+
71
+ After defining and accessing the onboarding steps as described
72
+ earlier, managed the onboarding process through various controls
73
+ that allow step navigation and state verification:
74
+
75
+ 1. **Initialize Onboarding Process**
76
+
77
+ Instantiate the onboarding process when a user object is created.
78
+ This sets up the initial step based on the defined onboarding flow.
79
+
80
+ ```ruby
81
+ User.new.onboarding
82
+ # Initializes the onboarding process for a new user instance
83
+ ```
84
+
85
+ 1. **Navigating Through Steps**
86
+
87
+ Navigate through the onboarding steps using the navigation methods provided.
88
+ These methods help in moving forward and backward through the onboarding process
89
+ - **Next Step**
90
+
91
+ Access the next step without changing the current step to preview
92
+ what's next or advance to it, updating the current step status.
93
+
94
+ ```ruby
95
+ onboarding.next_step
96
+ # Returns the next step without changing the current step
97
+
98
+ onboarding.next_step!
99
+ # Advances to the next step, updating the current step
100
+ ```
101
+
102
+ - **Previous Step**
103
+
104
+ Similarly, access the previous step to move back without
105
+ making changes or updates to revert to the previous step.
106
+
107
+ ```ruby
108
+ onboarding.prev_step
109
+ # Returns the previous step without changing the current step
110
+
111
+ onboarding.prev_step!
112
+ # Reverts to the previous step, updating the current step
113
+ ```
114
+
115
+ 1. **Check Step Position**
116
+
117
+ Determine whether the current step is the first or the last in the sequence
118
+ to manage UI elements like 'Next' or 'Back' buttons appropriately.
119
+
120
+ ```ruby
121
+ onboarding.first_step?
122
+ # Returns true if the current step is the first
123
+
124
+ onboarding.last_step?
125
+ # Returns true if the current step is the last
126
+ ```
127
+
128
+ 1. **Access Current Step Details**
129
+
130
+ Retrieve details about the current step, which can include the name,
131
+ custom data, and status, to display appropriate information or help
132
+ the user complete tasks associated with the step.
133
+
134
+ ```ruby
135
+ onboarding.current_step
136
+ # Returns the current step in the onboarding process
137
+
138
+ onboarding.current_step.name
139
+ # Returns the name of the current step
140
+
141
+ onboarding.current_step.data
142
+ # Returns the custom data associated with the step or an empty hash if not specified
143
+
144
+ onboarding.current_step.status
145
+ # Provides the current status or progress of the step
146
+ ```
147
+
148
+ 1. **Complete the Onboarding Process**
149
+
150
+ Once the user reaches the last step and completes it, finalize the
151
+ onboarding process, which might involve setting a user attribute to
152
+ indicate completion or triggering other application logic.
153
+
154
+ ```ruby
155
+ if onboarding.last_step?
156
+ # Trigger finalization processes like database updates or notifications
157
+ end
158
+ ```
159
+
160
+ By following these steps, developers can effectively manage and facilitate a
161
+ user-friendly onboarding process using the Onboardable gem.
162
+
163
+ ## 🛠 Development
164
+
165
+ 1. After checking out the repo, run `bin/setup` to install dependencies.
166
+ 1. Then, run `rake spec` to run the tests.
167
+ 1. Also run `bin/console` for an interactive prompt that will allow you to experiment.
168
+ 1. To install this gem onto your local machine, run `bundle exec rake install`.
169
+ 1. To release a new version, update the version number in `version.rb`.
170
+ 1. After, run `bundle exec rake release`, which will create a git tag for the version.
171
+ 1. Push git commits and the created tag.
172
+ 1. Then push the `.gem` file to [rubygems.org](https://rubygems.org).
173
+
174
+ ## 🤝 Contributing
175
+
176
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/dmrAnderson/onboardable>.
177
+ This project is intended to be a safe, welcoming space for collaboration,
178
+ and contributors are expected to adhere to the [code of conduct](https://github.com/dmrAnderson/onboardable/blob/main/CODE_OF_CONDUCT.md).
179
+
180
+ ## 📃 License
181
+
182
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
183
+
184
+ ## 📜 Code of Conduct
185
+
186
+ Everyone interacting in the Onboardable project's codebases, issue trackers,
187
+ chat rooms and mailing lists are expected to follow the [code of conduct](https://github.com/dmrAnderson/onboardable/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Onboardable
4
+ class Error < StandardError; end
5
+
6
+ class EmptyListError < Error
7
+ def initialize
8
+ super('Cannot be performed because the list is empty.')
9
+ end
10
+ end
11
+
12
+ class InvalidStepError < Error
13
+ def initialize(step, expected_steps)
14
+ super("Invalid step: `#{step}`. Must be one of: `#{expected_steps.join('`, `')}`.")
15
+ end
16
+ end
17
+
18
+ class InvalidComparisonResultError < Error
19
+ def initialize(comparison, expected_comparisons)
20
+ super("Invalid comparison result: `#{comparison}`. Must be one of: #{expected_comparisons.join('`, `')}.")
21
+ end
22
+ end
23
+
24
+ class LastStepError < Error
25
+ def initialize(step, expected_steps)
26
+ super("Currently `#{step}` the last step. Available steps are: `#{expected_steps.join('`, `')}`.")
27
+ end
28
+ end
29
+
30
+ class FirstStepError < Error
31
+ def initialize(step, expected_steps)
32
+ super("Currently `#{step}` the first step. Available steps are: `#{expected_steps.join('`, `')}`.")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Onboardable
4
+ class List
5
+ include Utils::Navigation
6
+
7
+ attr_reader :steps, :current_step
8
+
9
+ def initialize(steps, current_step)
10
+ self.steps = steps
11
+ self.current_step = current_step
12
+ end
13
+
14
+ private
15
+
16
+ def steps=(raw_steps)
17
+ Array(Array.try_convert(raw_steps)).then do |converted_steps|
18
+ raise EmptyListError if converted_steps.empty?
19
+
20
+ @steps = converted_steps.freeze
21
+ end
22
+ end
23
+
24
+ def current_step=(raw_current_step)
25
+ current_step_index = step_index!(raw_current_step)
26
+ steps.each_with_index { |step, index| step.update_status!(index <=> current_step_index) }
27
+ @current_step = steps.fetch(current_step_index)
28
+ end
29
+
30
+ def step_index!(raw_step)
31
+ steps.index { |step| step == raw_step } || raise(InvalidStepError.new(raw_step, steps.map(&:to_str)))
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Onboardable
4
+ class ListBuilder
5
+ attr_reader :steps
6
+ attr_accessor :current_step
7
+
8
+ def initialize
9
+ self.steps = {}
10
+ end
11
+
12
+ def add_step(name, data = {})
13
+ Step.new(name, data).tap do |step|
14
+ steps[name] = step
15
+ self.current_step ||= step
16
+ end
17
+ end
18
+ alias step add_step
19
+
20
+ def build!(current_step_name)
21
+ List.new(steps.values, convert_to_step!(current_step_name))
22
+ end
23
+
24
+ private
25
+
26
+ def steps=(raw_steps)
27
+ @steps = Hash(Hash.try_convert(raw_steps))
28
+ end
29
+
30
+ def convert_to_step!(name)
31
+ return current_step unless name
32
+
33
+ steps[name] || raise(InvalidStepError.new(name, steps.keys))
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Onboardable
4
+ class Step
5
+ PENDING_STATUS = :pending
6
+ CURRENT_STATUS = :current
7
+ COMPLETED_STATUS = :completed
8
+ DEFAULT_STATUS = PENDING_STATUS
9
+ STATUSES = [PENDING_STATUS, CURRENT_STATUS, COMPLETED_STATUS].freeze
10
+
11
+ attr_reader :name, :data, :status
12
+
13
+ def initialize(name, data = {})
14
+ self.name = name
15
+ self.data = data
16
+
17
+ self.status = DEFAULT_STATUS
18
+ end
19
+
20
+ STATUSES.each do |status_method|
21
+ define_method :"#{status_method}?" do
22
+ status == status_method
23
+ end
24
+ end
25
+
26
+ def ==(other)
27
+ to_str == other.to_str
28
+ end
29
+
30
+ def to_str
31
+ name
32
+ end
33
+
34
+ def update_status!(comparison_result)
35
+ self.status = case comparison_result
36
+ when -1 then COMPLETED_STATUS
37
+ when 0 then CURRENT_STATUS
38
+ when 1 then PENDING_STATUS
39
+ else
40
+ raise InvalidComparisonResultError.new(comparison_result, [-1, 0, 1])
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def name=(raw_name)
47
+ @name = String.new(String.try_convert(raw_name)).freeze
48
+ end
49
+
50
+ def data=(raw_data)
51
+ @data = Hash(Hash.try_convert(raw_data)).freeze
52
+ end
53
+
54
+ attr_writer :status
55
+ end
56
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Onboardable
4
+ module Utils
5
+ module Navigation
6
+ def next_step
7
+ current_index = step_index!(current_step)
8
+
9
+ steps[current_index.next]
10
+ end
11
+
12
+ def next_step!
13
+ self.current_step = next_step || raise(LastStepError.new(current_step, steps))
14
+ end
15
+
16
+ def prev_step
17
+ current_index = step_index!(current_step)
18
+
19
+ current_index.positive? ? steps[current_index.pred] : nil
20
+ end
21
+
22
+ def prev_step!
23
+ self.current_step = prev_step || raise(FirstStepError.new(current_step, steps))
24
+ end
25
+
26
+ def first_step?
27
+ current_step == steps.fetch(0)
28
+ end
29
+
30
+ def last_step?
31
+ current_step == steps.fetch(-1)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Onboardable
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'onboardable/utils/navigation'
4
+ require_relative 'onboardable/errors'
5
+ require_relative 'onboardable/list'
6
+ require_relative 'onboardable/list_builder'
7
+ require_relative 'onboardable/step'
8
+ require_relative 'onboardable/version'
9
+
10
+ module Onboardable
11
+ def self.included(klass)
12
+ klass.extend ClassMethods
13
+ klass.include InstanceMethods
14
+ end
15
+
16
+ module ClassMethods
17
+ def list_builder
18
+ @list_builder ||= ListBuilder.new
19
+ end
20
+
21
+ def list_builder=(&block)
22
+ list_builder.instance_eval(&block)
23
+ end
24
+ alias has_onboarding list_builder=
25
+ end
26
+
27
+ module InstanceMethods
28
+ def onboarding(current_step_name = nil)
29
+ self.class.list_builder.build!(current_step_name)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module Onboardable
2
+ class List
3
+ attr_reader steps: Array[Step]
4
+ attr_reader current_step: Step
5
+
6
+ def initialize: (Array[Step], Step) -> instance
7
+
8
+ private
9
+
10
+ attr_writer steps: Array[Step]
11
+ attr_writer current_step: Step
12
+
13
+ def step_index!: (Step)-> Integer
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Onboardable
2
+ class ListBuilder
3
+ attr_reader steps: Hash[String, Step]
4
+ attr_accessor current_step: Step
5
+
6
+ def initialize: () -> Hash[String, Step]
7
+
8
+ def add_step: (String, Hash[Symbol, untyped]) -> Step
9
+ alias step add_step
10
+
11
+ def build!: (String?) -> List
12
+
13
+ private
14
+
15
+ attr_writer steps: Hash[String, Step]
16
+
17
+ def convert_to_step!: (String?) -> Step
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module Onboardable
2
+ class Step
3
+ PENDING_STATUS: Symbol
4
+ CURRENT_STATUS: Symbol
5
+ COMPLETED_STATUS: Symbol
6
+ DEFAULT_STATUS: Symbol
7
+ STATUSES: Array[Symbol]
8
+
9
+ attr_reader name: String
10
+ attr_reader data: Hash[Symbol, untyped]
11
+ attr_reader status: Symbol
12
+
13
+ def initialize: (String, Hash[Symbol, untyped]) -> instance
14
+
15
+ def pending?: () -> bool
16
+ def current?: () -> bool
17
+ def completed?: () -> bool
18
+ def ==: (Step) -> bool
19
+ def to_str: () -> String
20
+
21
+ def update_status!: (Integer) -> Symbol
22
+
23
+ private
24
+
25
+ attr_writer name: String
26
+ attr_writer data: Hash[Symbol, untyped]
27
+ attr_writer status: Symbol
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ module Onboardable
2
+ module Utils
3
+ module Navigation
4
+ def next_step: () -> Step?
5
+ def next_step!: () -> Step
6
+ def prev_step: () -> Step?
7
+ def prev_step!: () -> Step
8
+ def first_step?: () -> bool
9
+ def last_step?: () -> bool
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Onboardable
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+
5
+ module ClassMethods
6
+ attr_reader list_builder: ListBuilder
7
+
8
+ def list_builder=: () { () -> ListBuilder } -> Step
9
+ alias has_onboarding list_builder=
10
+ end
11
+
12
+ module InstanceMethods
13
+ def onboarding: (String?) -> List
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onboardable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Artem Skrynnyk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 13.2.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '13.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 13.2.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.13'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.13'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rubocop
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.63'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 1.63.4
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '1.63'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.63.4
67
+ - !ruby/object:Gem::Dependency
68
+ name: rubocop-performance
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.21'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.21'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rubocop-rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: 0.6.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: 0.6.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: rubocop-rspec
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '2.29'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.29.2
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '2.29'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 2.29.2
115
+ - !ruby/object:Gem::Dependency
116
+ name: simplecov
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: 0.22.0
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: 0.22.0
129
+ description: Provides tools for easy setup of custom onboarding to boost engagement.
130
+ email:
131
+ - skrynnyk.artem@coaxsoft.com
132
+ executables: []
133
+ extensions: []
134
+ extra_rdoc_files: []
135
+ files:
136
+ - ".rspec"
137
+ - ".rubocop.yml"
138
+ - CHANGELOG.md
139
+ - CODE_OF_CONDUCT.md
140
+ - Gemfile
141
+ - Gemfile.lock
142
+ - LICENSE.txt
143
+ - README.md
144
+ - Rakefile
145
+ - lib/onboardable.rb
146
+ - lib/onboardable/errors.rb
147
+ - lib/onboardable/list.rb
148
+ - lib/onboardable/list_builder.rb
149
+ - lib/onboardable/step.rb
150
+ - lib/onboardable/utils/navigation.rb
151
+ - lib/onboardable/version.rb
152
+ - sig/onboardable.rbs
153
+ - sig/onboardable/list.rbs
154
+ - sig/onboardable/list_builder.rbs
155
+ - sig/onboardable/step.rbs
156
+ - sig/onboardable/utils/navigation.rbs
157
+ homepage: https://github.com/dmrAnderson/onboardable
158
+ licenses:
159
+ - MIT
160
+ metadata:
161
+ changelog_uri: https://github.com/dmrAnderson/onboardable/blob/main/CHANGELOG.md
162
+ bug_tracker_uri: https://github.com/dmrAnderson/onboardable/issues
163
+ documentation_uri: https://github.com/dmrAnderson/onboardable/blob/main/README.md
164
+ rubygems_mfa_required: 'true'
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: 3.0.0
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubygems_version: 3.5.10
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Streamlines onboarding process integration
184
+ test_files: []