auction_fun_core 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +12 -0
  3. data/.env.development.template +7 -0
  4. data/.env.test.template +7 -0
  5. data/.rspec +3 -0
  6. data/.standard.yml +3 -0
  7. data/.tool-versions +5 -0
  8. data/CHANGELOG.md +145 -0
  9. data/CODE_OF_CONDUCT.md +84 -0
  10. data/LICENSE.txt +21 -0
  11. data/Procfile +4 -0
  12. data/README.md +141 -0
  13. data/Rakefile +13 -0
  14. data/auction_fun_core.gemspec +57 -0
  15. data/config/app.rb +5 -0
  16. data/config/application.rb +37 -0
  17. data/config/boot.rb +15 -0
  18. data/db/migrate/20240216200926_enable_postgres_extensions.rb +13 -0
  19. data/db/migrate/20240217115734_create_users.rb +28 -0
  20. data/db/migrate/20240220140151_create_custom_types.rb +11 -0
  21. data/db/migrate/20240220140254_create_staffs.rb +20 -0
  22. data/db/migrate/20240229142933_create_custom_types.rb +13 -0
  23. data/db/migrate/20240229143000_create_auctions.rb +29 -0
  24. data/db/migrate/20240304144422_create_bids.rb +19 -0
  25. data/db/seeds.rb +116 -0
  26. data/i18n/en-US/contracts/contracts.en-US.yml +72 -0
  27. data/i18n/en-US/mail/user_context/registration.en-US.yml +11 -0
  28. data/i18n/pt-BR/contracts/contracts.pt-BR.yml +72 -0
  29. data/i18n/pt-BR/mail/user_context/registration.pt-BR.yml +12 -0
  30. data/lib/auction_fun_core/business/configuration.rb +18 -0
  31. data/lib/auction_fun_core/business/token_generator.rb +17 -0
  32. data/lib/auction_fun_core/commands/auction_context/create_auction.rb +19 -0
  33. data/lib/auction_fun_core/commands/auction_context/delete_auction.rb +15 -0
  34. data/lib/auction_fun_core/commands/auction_context/update_auction.rb +18 -0
  35. data/lib/auction_fun_core/commands/bid_context/create_bid.rb +19 -0
  36. data/lib/auction_fun_core/commands/bid_context/delete_bid.rb +15 -0
  37. data/lib/auction_fun_core/commands/bid_context/update_bid.rb +18 -0
  38. data/lib/auction_fun_core/commands/staff_context/create_staff.rb +19 -0
  39. data/lib/auction_fun_core/commands/user_context/create_user.rb +19 -0
  40. data/lib/auction_fun_core/contracts/application_contract.rb +55 -0
  41. data/lib/auction_fun_core/contracts/auction_context/create_contract.rb +101 -0
  42. data/lib/auction_fun_core/contracts/auction_context/processor/finish_contract.rb +27 -0
  43. data/lib/auction_fun_core/contracts/auction_context/processor/pause_contract.rb +34 -0
  44. data/lib/auction_fun_core/contracts/auction_context/processor/start_contract.rb +46 -0
  45. data/lib/auction_fun_core/contracts/auction_context/processor/unpause_contract.rb +34 -0
  46. data/lib/auction_fun_core/contracts/bid_context/create_bid_closed_contract.rb +79 -0
  47. data/lib/auction_fun_core/contracts/bid_context/create_bid_penny_contract.rb +69 -0
  48. data/lib/auction_fun_core/contracts/bid_context/create_bid_standard_contract.rb +68 -0
  49. data/lib/auction_fun_core/contracts/staff_context/authentication_contract.rb +47 -0
  50. data/lib/auction_fun_core/contracts/staff_context/registration_contract.rb +52 -0
  51. data/lib/auction_fun_core/contracts/user_context/authentication_contract.rb +47 -0
  52. data/lib/auction_fun_core/contracts/user_context/email_confirmation_contract.rb +40 -0
  53. data/lib/auction_fun_core/contracts/user_context/phone_confirmation_contract.rb +40 -0
  54. data/lib/auction_fun_core/contracts/user_context/registration_contract.rb +63 -0
  55. data/lib/auction_fun_core/entities/auction.rb +17 -0
  56. data/lib/auction_fun_core/entities/bid.rb +10 -0
  57. data/lib/auction_fun_core/entities/staff.rb +21 -0
  58. data/lib/auction_fun_core/entities/user.rb +37 -0
  59. data/lib/auction_fun_core/events/app.rb +27 -0
  60. data/lib/auction_fun_core/events/listener.rb +89 -0
  61. data/lib/auction_fun_core/operations/auction_context/create_operation.rb +77 -0
  62. data/lib/auction_fun_core/operations/auction_context/processor/finish_operation.rb +61 -0
  63. data/lib/auction_fun_core/operations/auction_context/processor/pause_operation.rb +57 -0
  64. data/lib/auction_fun_core/operations/auction_context/processor/start_operation.rb +84 -0
  65. data/lib/auction_fun_core/operations/auction_context/processor/unpause_operation.rb +57 -0
  66. data/lib/auction_fun_core/operations/base.rb +11 -0
  67. data/lib/auction_fun_core/operations/bid_context/create_bid_closed_operation.rb +64 -0
  68. data/lib/auction_fun_core/operations/bid_context/create_bid_penny_operation.rb +64 -0
  69. data/lib/auction_fun_core/operations/bid_context/create_bid_standard_operation.rb +74 -0
  70. data/lib/auction_fun_core/operations/staff_context/authentication_operation.rb +52 -0
  71. data/lib/auction_fun_core/operations/staff_context/registration_operation.rb +76 -0
  72. data/lib/auction_fun_core/operations/user_context/authentication_operation.rb +52 -0
  73. data/lib/auction_fun_core/operations/user_context/email_confirmation_operation.rb +67 -0
  74. data/lib/auction_fun_core/operations/user_context/phone_confirmation_operation.rb +67 -0
  75. data/lib/auction_fun_core/operations/user_context/registration_operation.rb +105 -0
  76. data/lib/auction_fun_core/relations/auctions.rb +119 -0
  77. data/lib/auction_fun_core/relations/bids.rb +28 -0
  78. data/lib/auction_fun_core/relations/staffs.rb +27 -0
  79. data/lib/auction_fun_core/relations/users.rb +26 -0
  80. data/lib/auction_fun_core/repos/auction_context/auction_repository.rb +42 -0
  81. data/lib/auction_fun_core/repos/bid_context/bid_repository.rb +27 -0
  82. data/lib/auction_fun_core/repos/staff_context/staff_repository.rb +64 -0
  83. data/lib/auction_fun_core/repos/user_context/user_repository.rb +78 -0
  84. data/lib/auction_fun_core/services/mail/templates/layout.html.erb +72 -0
  85. data/lib/auction_fun_core/services/mail/templates/user_context/registration.html.erb +170 -0
  86. data/lib/auction_fun_core/services/mail/user_context/registration_mailer.rb +25 -0
  87. data/lib/auction_fun_core/version.rb +8 -0
  88. data/lib/auction_fun_core/workers/application_job.rb +22 -0
  89. data/lib/auction_fun_core/workers/operations/auction_context/processor/finish_operation_job.rb +32 -0
  90. data/lib/auction_fun_core/workers/operations/auction_context/processor/start_operation_job.rb +32 -0
  91. data/lib/auction_fun_core/workers/services/mail/user_context/registration_mailer_job.rb +40 -0
  92. data/lib/auction_fun_core.rb +21 -0
  93. data/lib/tasks/database.rake +87 -0
  94. data/system/providers/background_job.rb +15 -0
  95. data/system/providers/core.rb +35 -0
  96. data/system/providers/db.rb +26 -0
  97. data/system/providers/events.rb +13 -0
  98. data/system/providers/logger.rb +11 -0
  99. data/system/providers/mail.rb +25 -0
  100. data/system/providers/persistence.rb +18 -0
  101. data/system/providers/settings.rb +26 -0
  102. metadata +400 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b42434481eccb486a4e38674f4219b1969e8951bd0a06430066a2ca9e9c9931d
4
+ data.tar.gz: a243a07a6b63c1e9a10f17a616290b1eea8c825af4a5e1a47e7f4f3515e192c6
5
+ SHA512:
6
+ metadata.gz: 6a3d12e06b32f527e2744f996b14716e32e6f496a5367452eeeae62425a34c7a90878c2f256e901a9a165b00325838f0bba29526580d02dc65d0240c4444d2f8
7
+ data.tar.gz: 4dcaa1d26811cdab77368cc5eb5567b83a5cf647e9f123ecaed217e41e908e7f1ea6e56a5fcfccc6410f04e9ba91b054fe282c41a7c7b1b5806556006f76e703
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ [*]
7
+ indent_style = space
8
+ indent_size = 2
9
+ end_of_line = lf
10
+ charset = utf-8
11
+ trim_trailing_whitespace = true
12
+ insert_final_newline = true
@@ -0,0 +1,7 @@
1
+ APP_ENV=development
2
+ DATABASE_URL=postgresql://postgres:@127.0.0.1/auction_fun_core_development?pool=10
3
+ REDIS_URL=redis://localhost:6379/0
4
+ DEFAULT_CURRENCY=USD
5
+ DEFAULT_EMAIL_SYSTEM=system@auctionfun.app
6
+ SMTP_ADDRESS=localhost
7
+ SMTP_PORT=1025
@@ -0,0 +1,7 @@
1
+ APP_ENV=test
2
+ DATABASE_URL=postgresql://postgres:@127.0.0.1:5432/auction_fun_core_test?pool=10
3
+ REDIS_URL=redis://localhost:6379/15
4
+ DEFAULT_CURRENCY=USD
5
+ DEFAULT_EMAIL_SYSTEM=system@auctionfun.app
6
+ SMTP_ADDRESS=localhost
7
+ SMTP_PORT=1025
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.0
data/.tool-versions ADDED
@@ -0,0 +1,5 @@
1
+ ruby 3.3.0
2
+ postgres 16.1
3
+ golang 1.21.5
4
+ nodejs 20.10.0
5
+ redis 7.2.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,145 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.8.5] - 2024-04-03
4
+
5
+ ### Added
6
+
7
+ - Seed data for rapid develpment
8
+
9
+ ## [0.8.4] - 2024-03-15
10
+
11
+ - Adjusting dependencies so that they are automatically loaded by the external Gemfile.
12
+
13
+ ## [0.8.3] - 2024-03-12
14
+
15
+ ### Added
16
+
17
+ - Processing actions to pause and unpause an auction.
18
+
19
+ ## [0.8.1] - 2024-03-06
20
+
21
+ ### Added
22
+
23
+ - Added configuration constants module to store fixed values referring to business rules.
24
+
25
+ ## [0.8.0] - 2024-03-06
26
+
27
+ ### Added
28
+
29
+ - Bid entity and your context to handle bid creation business rules.
30
+ - Internal Processor module in bids to handle specific types.
31
+
32
+ ### Fixed
33
+
34
+ - auction migration name fix.
35
+
36
+ ## [0.7.0] - 2024-02-29
37
+
38
+ ### Added
39
+
40
+ - Auction entity and your context to handle auction creation business rules.
41
+ - Internal Processor module in auctions to handle specific actions.
42
+ - User-defined Data Types (custom types) for postgres.
43
+
44
+ ### Fixed
45
+
46
+ - `en-US` i18n contract messages.
47
+
48
+ ## [0.6.1] - 2024-02-28
49
+
50
+ ### Added
51
+
52
+ - Add configuration to handle monetary values.
53
+ - Add required environment variable `DEFAULT_CURRENCY` to set the default currency.
54
+ - Tests for entities.
55
+
56
+ ## [0.6.0] - 2024-02-24
57
+
58
+ ### Added
59
+
60
+ - Redis as database for background processing.
61
+ - Add sidekiq as background processing.
62
+ - Add required environment variable `REDIS_URL` for redis server connection.
63
+ - Add background job as provider application.
64
+ - Add exponential backoff for handle possible scenario failures in background.
65
+
66
+ ### Changes
67
+
68
+ - UserContext::Registration operation to generate email confirmation and send email with token.
69
+ - Syntax standardization for erb files.
70
+ - Refactoring some tests removing unecessary code.
71
+
72
+ ## [0.5.0] - 2024-02-23
73
+
74
+ ### Added
75
+
76
+ - Layer for external services.
77
+ - Creation of first external service: email.
78
+ - Configure email as application provider.
79
+ - Mandatory environment variables for communication with email service.
80
+ - Configuring development environment to run email service on local machine.
81
+ - Using `idlemailer` dependency to build emails and triggers.
82
+
83
+ ## Changes
84
+
85
+ - I18n locale directory from `config/locales` to root path of project.
86
+ - Scope i18n messages by locale.
87
+
88
+ ## [0.4.1] - 2024-02-20
89
+
90
+ ### Added
91
+
92
+ - Authentication for staff members.
93
+ - Only active staff member can authenticate.
94
+
95
+ ## [0.4.0] - 2024-02-20
96
+
97
+ ### Added
98
+
99
+ - Staff entity and your context to handle staff business rules
100
+ - Context for new staff registration
101
+ - Add postgresql enum for staff kind
102
+
103
+ ### Fixed
104
+
105
+ - Fix rake task for create migrations
106
+
107
+ ## [0.3.1] - 2024-02-17
108
+
109
+ ### Added
110
+
111
+ - Authentication for people (users).
112
+ - Only active users can authenticate.
113
+
114
+ ### Changed
115
+
116
+ - [Standardization] Refactoring return monads in operation classes.
117
+
118
+ ## [0.2.0] - 2024-02-17
119
+
120
+ ### Added
121
+
122
+ - User entity and your context to handle people business rules.
123
+ - Context for new user registration.
124
+ - Bcrypt to handle password issues.
125
+ - Phonelib to handle phone issues.
126
+ - Logger provider with level configuration.
127
+ - Configure i18n.
128
+ - `pt-BR` translation.
129
+ - `en-US` translation.
130
+ - Add `pub/sub` pattern and API with dry-events.
131
+ - Add `ActiveSupport` to the main application to facilitate general development.
132
+ - Configure database cleaner for suite of tests.
133
+
134
+ ### Fixed
135
+
136
+ - Adjusting lint with standardrb throughout the code.
137
+ - Lifecyle for core provider.
138
+
139
+ ### Changed
140
+
141
+ - Adjusting directory patterns for test coverage.
142
+
143
+ ## [0.1.0] - 2024-02-06
144
+
145
+ - 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 innervisiondev@gmail.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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Ricardo Pacheco
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/Procfile ADDED
@@ -0,0 +1,4 @@
1
+ database: postgres
2
+ redis: redis-server
3
+ mailserver: maildev --hide-extensions STARTTLS
4
+ background: bundle exec sidekiq -r ./config/app.rb
data/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # AuctionFunCore
2
+
3
+ This lib contains all the business logic necessary to run the auctions. A principle and standard must be strictly followed: The [SRP principle](https://en.wikipedia.org/wiki/Single_responsibility_principle)The principle of single responsibility and some standard [clean architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) concepts.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'auction_fun_core'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ user@host:~$ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```sh
22
+ user@host:~$ gem install auction_fun_core
23
+ ```
24
+
25
+ ## Getting Started
26
+
27
+ Initially, download the project remotely and copy the templates from the project's environment variables:
28
+
29
+ ```sh
30
+ user@host:~$ git clone git@github.com:ricardopacheco/auction-fun-core.git core
31
+ user@host:~$ cd core
32
+ user@host:~$ cp .env.development.template .env.development
33
+ user@host:~$ cp .env.test.template .env.test
34
+ ```
35
+
36
+ > As the idea of this project is to be a lib, it was decided to use a specific environment variable called `APP_ENV`, so as not to conflict with others if the lib is used by a framework.
37
+
38
+ ## Development
39
+
40
+ Configure the `.env.development` file with the values according to your machine or network.
41
+
42
+ Run the commands below to create the database and its structure, remembering to replace
43
+ the `userdb` by the user of your postgresql service. By default, if `APP_ENV` is not provided
44
+ is considered the value `development` by default.
45
+
46
+ ### OS dependencies
47
+
48
+ - [ASDF](https://asdf-vm.com/#/core-manage-asdf)
49
+
50
+ #### Ruby
51
+
52
+ #### Database (PostgreSQL)
53
+
54
+ ```sh
55
+ user@host:~$ sudo apt install build-essential libssl-dev libreadline-dev zlib1g-dev libcurl4-openssl-dev uuid-dev
56
+ user@host:~$ asdf plugin add postgres
57
+ user@host:~$ asdf install postgres 16.1
58
+ user@host:~$ rm -rf $HOME/.asdf/installs/postgres/16.1/data
59
+ user@host:~$ initdb -D $HOME/.asdf/installs/postgres/16.1/data -U postgres
60
+ ```
61
+
62
+ ```sh
63
+ user@host:~$ sudo apt install autoconf patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev
64
+ user@host:~$ asdf plugin add ruby
65
+ user@host:~$ asdf install ruby 3.3.0
66
+ user@host:~$ gem install pg -v 1.5.5 --verbose -- --with-pg-config=$HOME/.asdf/installs/postgres/16.1/bin/pg_config # Fix pg_config
67
+ user@host:~$ bin/setup
68
+ ```
69
+
70
+ #### Overmind (Procfile manager)
71
+
72
+ ```sh
73
+ user@host:~$ asdf install golang latest
74
+ user@host:~$ go install github.com/DarthSim/overmind/v2
75
+ user@host:~$ asdf reshim
76
+ ```
77
+
78
+ #### Create database for development environment
79
+
80
+ > **[postgres]** in rake commands is a name of user for postgres. Change if needed
81
+
82
+ In current tab:
83
+
84
+ ```sh
85
+ user@host:~$ overmind s -l database
86
+ ```
87
+
88
+ Open a new tab and create development database:
89
+
90
+ ```sh
91
+ user@host:~$ bundle exec rake 'auction_fun_core:db:create_database[postgres]'
92
+ user@host:~$ bundle exec rake 'auction_fun_core:db:migrate'
93
+ ```
94
+
95
+ Now come back to overmind tab, kill the current database process using **Ctrl+c**. After that:
96
+
97
+ ```sh
98
+ user@host:~$ overmind start
99
+ ```
100
+
101
+ This will start all required services needed to run core application.
102
+
103
+ In new tab, you could run seed data for development with
104
+
105
+ ```sh
106
+ user@host:~$ bundle exec rake 'auction_fun_core:db:seed'
107
+ ```
108
+
109
+ ## Interactive prompt
110
+
111
+ To experiment with that code, run `bin/console` for an interactive prompt.
112
+
113
+ ## Test
114
+
115
+ Configure the `.env.test` file with the values according to your machine or network.
116
+
117
+ Run the test suite with the coverage report using the command:
118
+
119
+ ```sh
120
+ user@host:~$ APP_ENV=test bundle exec rake auction_fun_core:db:create_database[userdb]
121
+ user@host:~$ APP_ENV=test bundle exec rake auction_fun_core:db:migrate
122
+ user@host:~$ CI=true APP_ENV=test bundle exec rspec .
123
+ ```
124
+
125
+ ## Documentation
126
+
127
+ This project uses `yadr` as a documentation tool. To generate documentation and view it, run
128
+
129
+ ```sh
130
+ user@host:~$ bundle exec yard server --reload
131
+ ```
132
+
133
+ Documentation will be available at `http://localhost:8808`
134
+
135
+ ## External resources
136
+
137
+ - [Email templates](https://codedmails.com/)
138
+
139
+ ## License
140
+
141
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'config/application'
4
+ require "bundler/gem_tasks"
5
+ require "rspec/core/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ require "standard/rake"
10
+
11
+ Dir.glob("#{File.expand_path(__dir__)}/lib/tasks/**/*.rake").each { |f| load f }
12
+
13
+ task default: %i[spec standard]
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/auction_fun_core/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "auction_fun_core"
7
+ spec.version = AuctionFunCore::VERSION
8
+ spec.authors = ["Ricardo Pacheco"]
9
+ spec.email = ["innervisiondev@gmail.com"]
10
+
11
+ spec.summary = "It's a lib that contains all auctionfun's business rules!"
12
+ spec.description = "Practical application of clean architecture in a real business idea using ruby."
13
+ spec.homepage = "https://rubygems.org/gems/auction_fun_core"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.3.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/ricardopacheco/auction-fun-core"
21
+ spec.metadata["changelog_uri"] = "https://github.com/ricardopacheco/auction-fun-core/CHANGELOG"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ spec.add_dependency "activesupport", "7.1.3.2"
37
+ spec.add_dependency "bcrypt", "3.1.20"
38
+ spec.add_dependency "dotenv", "3.1.0"
39
+ spec.add_dependency "dry-events", "1.0.1"
40
+ spec.add_dependency "dry-matcher", "1.0.0"
41
+ spec.add_dependency "dry-monads", "1.6.0"
42
+ spec.add_dependency "dry-system", "1.0.1"
43
+ spec.add_dependency "dry-validation", "1.10.0"
44
+ spec.add_dependency "idlemailer", "2.2.0"
45
+ spec.add_dependency "money", "6.19.0"
46
+ spec.add_dependency "pg", "1.5.6"
47
+ spec.add_dependency "phonelib", "0.8.8"
48
+ spec.add_dependency "rake", "13.2.0"
49
+ spec.add_dependency "rom", "5.3.0"
50
+ spec.add_dependency "rom-sql", "3.6.2"
51
+ spec.add_dependency "sidekiq", "7.2.2"
52
+ spec.add_dependency "yard", "0.9.36"
53
+ spec.add_dependency "zeitwerk", "2.6.13"
54
+
55
+ # For more information and examples about making a new gem, check out our
56
+ # guide at: https://bundler.io/guides/creating_gem.html
57
+ end
data/config/app.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "application"
4
+
5
+ AuctionFunCore::Application.finalize!
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "boot"
4
+
5
+ require "bcrypt"
6
+ require "zeitwerk"
7
+ require "i18n"
8
+ require "dry/system"
9
+ require "dry/system/loader/autoloading"
10
+ require "dry/auto_inject"
11
+ require "dry/types"
12
+ require "money"
13
+
14
+ module AuctionFunCore
15
+ # Main class (Add doc)
16
+ class Application < Dry::System::Container
17
+ Money.default_currency = ENV.fetch("DEFAULT_CURRENCY")
18
+ I18n.load_path += Dir[File.expand_path("i18n/**/*.{rb,yml}")]
19
+ I18n.available_locales = %w[en-US pt-BR]
20
+ I18n.default_locale = "pt-BR"
21
+ use :env, inferrer: -> { ENV.fetch("APP_ENV", "development").to_sym }
22
+ use :zeitwerk, run_setup: true, eager_load: true
23
+
24
+ configure do |config|
25
+ config.root = File.expand_path("..", __dir__)
26
+
27
+ config.component_dirs.add "lib" do |dir|
28
+ dir.auto_register = true
29
+ dir.loader = Dry::System::Loader::Autoloading
30
+ dir.add_to_load_path = true
31
+ dir.namespaces.add "auction_fun_core", key: nil
32
+ end
33
+ end
34
+ end
35
+
36
+ Import = Dry::AutoInject(Application)
37
+ end
data/config/boot.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV["APP_ENV"] ||= "development"
4
+
5
+ require "bundler"
6
+ Bundler.setup(:default, ENV.fetch("APP_ENV", nil))
7
+
8
+ unless defined?(Dotenv)
9
+ require "dotenv"
10
+ Dotenv.load(".env.#{ENV.fetch("APP_ENV", nil)}")
11
+ Dotenv.require_keys(
12
+ "DATABASE_URL", "DEFAULT_CURRENCY", "DEFAULT_EMAIL_SYSTEM", "REDIS_URL",
13
+ "SMTP_ADDRESS", "SMTP_PORT"
14
+ )
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ ROM::SQL.migration do
4
+ up do
5
+ run 'CREATE EXTENSION "unaccent"'
6
+ run 'CREATE EXTENSION "hstore"'
7
+ end
8
+
9
+ down do
10
+ run 'DROP EXTENSION IF EXISTS "unaccent"'
11
+ run 'DROP EXTENSION IF EXISTS "hstore"'
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ ROM::SQL.migration do
4
+ change do
5
+ create_table(:users) do
6
+ primary_key :id
7
+ column :name, String, null: false
8
+ column :email, String, null: false
9
+ column :phone, String, null: false
10
+ column :password_digest, String, null: false
11
+ column :active, TrueClass, null: false, default: true
12
+ column :balance_cents, Integer, null: false, default: 0
13
+ column :balance_currency, String, null: false, default: "USD"
14
+ column :email_confirmation_token, String, size: 20
15
+ column :phone_confirmation_token, String, size: 6
16
+ column :email_confirmation_at, DateTime
17
+ column :phone_confirmation_at, DateTime
18
+ column :confirmed_at, DateTime
19
+ column :created_at, DateTime, null: false
20
+ column :updated_at, DateTime, null: false
21
+
22
+ index :email, unique: true
23
+ index :phone, unique: true
24
+ index :email_confirmation_token, unique: true
25
+ index :phone_confirmation_token, unique: true
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ ROM::SQL.migration do
4
+ up do
5
+ run "CREATE TYPE staff_kinds AS ENUM('root', 'common')"
6
+ end
7
+
8
+ down do
9
+ run 'DROP TYPE IF EXISTS "staff_kinds"'
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ ROM::SQL.migration do
4
+ change do
5
+ create_table(:staffs) do
6
+ primary_key :id
7
+ column :name, String, null: false
8
+ column :email, String, null: false
9
+ column :phone, String, null: false
10
+ column :active, TrueClass, null: false, default: true
11
+ column :password_digest, String, null: false
12
+ column :kind, :staff_kinds, null: false
13
+ column :created_at, DateTime, null: false
14
+ column :updated_at, DateTime, null: false
15
+
16
+ index :email, unique: true
17
+ index :phone, unique: true
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ ROM::SQL.migration do
4
+ up do
5
+ run "CREATE TYPE auction_kinds AS ENUM('standard', 'penny', 'closed')"
6
+ run "CREATE TYPE auction_statuses AS ENUM('scheduled', 'running', 'paused', 'canceled', 'finished')"
7
+ end
8
+
9
+ down do
10
+ run 'DROP TYPE IF EXISTS "auction_kinds"'
11
+ run 'DROP TYPE IF EXISTS "auction_statuses"'
12
+ end
13
+ end