app_configurable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2bbcefb59395aa424d071c1f2122d7f051e87571ff75d62eb56c80c4c3fc6ec4
4
+ data.tar.gz: b095757dfcf1351ed5fabe65106dcf8a8a039a7a62744f8b811620dd0ef537f6
5
+ SHA512:
6
+ metadata.gz: ce77b5158704203937bc2460bf5020d4b34200598c3f85e4e5e832935f5ee29d4c784ed12ded51d159770e820ad64a74dcb9d4c5e004fa2cbc1064282901b805
7
+ data.tar.gz: d9335f684c5da7ea160030d0da4d28642f73dd779059508a60a9e9b89240353a79fdaf62313936337506979c2f89b377464d08283e9f94978ab79092545ddd49
data/.byebug_history ADDED
@@ -0,0 +1,6 @@
1
+ exit
2
+ ::Rails
3
+ Rails
4
+ config
5
+ exit
6
+ self
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,97 @@
1
+ Layout/BlockAlignment:
2
+ EnforcedStyleAlignWith: start_of_block
3
+
4
+ Layout/FirstHashElementIndentation:
5
+ EnforcedStyle: consistent
6
+
7
+ Layout/IndentationConsistency:
8
+ Enabled: true
9
+ EnforcedStyle: normal
10
+
11
+ Layout/LineLength:
12
+ Max: 140
13
+
14
+ Layout/MultilineHashKeyLineBreaks:
15
+ Enabled: true
16
+
17
+ Layout/FirstHashElementLineBreak:
18
+ Enabled: true
19
+
20
+ Layout/MultilineAssignmentLayout:
21
+ Enabled: true
22
+ EnforcedStyle: new_line
23
+
24
+ Lint/Debugger: # don't leave binding.pry
25
+ Enabled: true
26
+ Exclude: []
27
+
28
+ Lint/AmbiguousBlockAssociation:
29
+ Enabled: true
30
+ Exclude:
31
+ - 'spec/**/*'
32
+
33
+ Lint/EmptyBlock:
34
+ Enabled: true
35
+ Exclude:
36
+ - 'spec/factories/**/*'
37
+
38
+ Lint/MissingSuper:
39
+ Enabled: true
40
+ Exclude:
41
+ - 'app/graphql/sources/**/*'
42
+
43
+ Metrics/ClassLength:
44
+ Enabled: false
45
+
46
+ Metrics/MethodLength:
47
+ Max: 20
48
+ Exclude:
49
+ - lib/**/*.rake
50
+ - spec/support/fixtures_setup.rb
51
+
52
+ Metrics/AbcSize:
53
+ CountRepeatedAttributes: false
54
+ Exclude:
55
+ - lib/**/*.rake
56
+ - spec/support/fixtures_setup.rb
57
+ - app/models/ability.rb
58
+
59
+ Metrics/CyclomaticComplexity:
60
+ Exclude:
61
+ - lib/**/*.rake
62
+
63
+ Metrics/BlockLength:
64
+ Exclude:
65
+ - app/admin/**/*.rb
66
+ - app/views/admin/**/*.arb
67
+ - lib/**/*.rake
68
+ - config/initializers/*.rb
69
+ - config/routes.rb
70
+
71
+ Naming/PredicateName:
72
+ Enabled: false
73
+
74
+ Naming/VariableNumber:
75
+ Enabled: false
76
+
77
+ Naming/BlockForwarding:
78
+ EnforcedStyle: explicit
79
+
80
+ Style/Documentation:
81
+ Enabled: false
82
+
83
+ Style/ClassAndModuleChildren:
84
+ Enabled: false
85
+
86
+ Style/FormatString:
87
+ EnforcedStyle: percent
88
+
89
+ Style/FormatStringToken:
90
+ EnforcedStyle: template
91
+
92
+ Style/ArgumentsForwarding:
93
+ UseAnonymousForwarding: false
94
+
95
+ Style/GlobalVars:
96
+ AllowedVariables:
97
+ - $redis
@@ -0,0 +1,60 @@
1
+ Rails:
2
+ Enabled: true
3
+
4
+ Rails/SkipsModelValidations:
5
+ Enabled: false
6
+
7
+ Rails/ReversibleMigration:
8
+ Enabled: false
9
+
10
+ Rails/CreateTableWithTimestamps:
11
+ Enabled: false
12
+
13
+ Rails/RakeEnvironment:
14
+ Enabled: false
15
+
16
+ Rails/HasManyOrHasOneDependent:
17
+ Enabled: false
18
+
19
+ Rails/HasAndBelongsToMany:
20
+ Enabled: false
21
+
22
+ Rails/NotNullColumn:
23
+ Enabled: false
24
+
25
+ Rails/Exit:
26
+ Enabled: false
27
+
28
+ Rails/ApplicationController:
29
+ Enabled: false
30
+
31
+ Rails/Output: # Don't leave puts-debugging
32
+ Enabled: true
33
+ Exclude: []
34
+
35
+ Rails/OutputSafety:
36
+ Enabled: true
37
+ Exclude:
38
+ - app/admin/**/*
39
+ - app/helpers/admin/**/*
40
+ - app/views/admin/**/*
41
+ - app/inputs/**/*
42
+
43
+ Rails/FindEach: # each could severely affect the performance, use find_each
44
+ Enabled: true
45
+ Exclude: []
46
+
47
+ Rails/UniqBeforePluck: # uniq.pluck and not pluck.uniq
48
+ Enabled: true
49
+ Exclude: []
50
+
51
+ Rails/UnknownEnv:
52
+ Environments:
53
+ - production
54
+ - staging
55
+ - development
56
+ - test
57
+
58
+ Rails/I18nLocaleTexts:
59
+ Exclude:
60
+ - app/admin/**/*
@@ -0,0 +1,42 @@
1
+ RSpec/BeforeAfterAll: # we use before/after blocks to setup es tests
2
+ Enabled: false
3
+
4
+ RSpec/DescribeClass:
5
+ Enabled: true
6
+ Exclude:
7
+ - spec/lib/tasks/**/*
8
+
9
+ RSpec/MessageSpies:
10
+ Enabled: false
11
+
12
+ RSpec/MultipleMemoizedHelpers:
13
+ Max: 15
14
+
15
+ RSpec/MultipleExpectations:
16
+ Max: 15
17
+
18
+ RSpec/ExampleLength:
19
+ Max: 35
20
+
21
+ RSpec/NestedGroups:
22
+ Max: 6
23
+
24
+ RSpec/StubbedMock:
25
+ Enabled: false
26
+
27
+ RSpec/VerifiedDoubles:
28
+ Enabled: false
29
+
30
+ RSpec/NamedSubject:
31
+ Enabled: false
32
+
33
+ RSpec/LetSetup:
34
+ Enabled: false
35
+
36
+ RSpec/Focus: # run ALL tests on CI
37
+ Enabled: true
38
+ Exclude: []
39
+
40
+ RSpec/ImplicitSubject:
41
+ Exclude:
42
+ - spec/graphql/resolvers/**/*_spec.rb
data/.rubocop.yml ADDED
@@ -0,0 +1,38 @@
1
+ require:
2
+ - rubocop-performance # https://docs.rubocop.org/rubocop-performance/cops_performance.html
3
+ - rubocop-rails # https://docs.rubocop.org/rubocop-rails/cops_rails.html
4
+ - rubocop-rspec # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html
5
+ - rubocop-rspec_rails # https://docs.rubocop.org/rubocop-rspec/cops_rspec_rails.html
6
+
7
+ inherit_mode:
8
+ merge:
9
+ - Exclude
10
+
11
+ inherit_from:
12
+ - .rubocop/rails.yml
13
+ - .rubocop/rspec.yml
14
+ - .rubocop/custom.yml
15
+
16
+ AllCops:
17
+ NewCops: enable
18
+ TargetRubyVersion: 3.1.0
19
+
20
+ Style/StringLiterals:
21
+ Enabled: true
22
+ EnforcedStyle: single_quotes
23
+
24
+ Style/StringLiteralsInInterpolation:
25
+ Enabled: true
26
+ EnforcedStyle: double_quotes
27
+
28
+ Layout/LineLength:
29
+ Max: 120
30
+
31
+ Style/ClassAndModuleChildren:
32
+ Enabled: false
33
+
34
+ Gemspec/DevelopmentDependencies:
35
+ EnforcedStyle: gemspec
36
+
37
+ Metrics/ParameterLists:
38
+ CountKeywordArgs: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-11-14
4
+
5
+ - 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 dmytro.pasichnyk@omr.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 app_configurable.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,251 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ app_configurable (0.1.0)
5
+ dotenv
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (7.2.2)
11
+ actionpack (= 7.2.2)
12
+ activesupport (= 7.2.2)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ zeitwerk (~> 2.6)
16
+ actionmailbox (7.2.2)
17
+ actionpack (= 7.2.2)
18
+ activejob (= 7.2.2)
19
+ activerecord (= 7.2.2)
20
+ activestorage (= 7.2.2)
21
+ activesupport (= 7.2.2)
22
+ mail (>= 2.8.0)
23
+ actionmailer (7.2.2)
24
+ actionpack (= 7.2.2)
25
+ actionview (= 7.2.2)
26
+ activejob (= 7.2.2)
27
+ activesupport (= 7.2.2)
28
+ mail (>= 2.8.0)
29
+ rails-dom-testing (~> 2.2)
30
+ actionpack (7.2.2)
31
+ actionview (= 7.2.2)
32
+ activesupport (= 7.2.2)
33
+ nokogiri (>= 1.8.5)
34
+ racc
35
+ rack (>= 2.2.4, < 3.2)
36
+ rack-session (>= 1.0.1)
37
+ rack-test (>= 0.6.3)
38
+ rails-dom-testing (~> 2.2)
39
+ rails-html-sanitizer (~> 1.6)
40
+ useragent (~> 0.16)
41
+ actiontext (7.2.2)
42
+ actionpack (= 7.2.2)
43
+ activerecord (= 7.2.2)
44
+ activestorage (= 7.2.2)
45
+ activesupport (= 7.2.2)
46
+ globalid (>= 0.6.0)
47
+ nokogiri (>= 1.8.5)
48
+ actionview (7.2.2)
49
+ activesupport (= 7.2.2)
50
+ builder (~> 3.1)
51
+ erubi (~> 1.11)
52
+ rails-dom-testing (~> 2.2)
53
+ rails-html-sanitizer (~> 1.6)
54
+ activejob (7.2.2)
55
+ activesupport (= 7.2.2)
56
+ globalid (>= 0.3.6)
57
+ activemodel (7.2.2)
58
+ activesupport (= 7.2.2)
59
+ activerecord (7.2.2)
60
+ activemodel (= 7.2.2)
61
+ activesupport (= 7.2.2)
62
+ timeout (>= 0.4.0)
63
+ activestorage (7.2.2)
64
+ actionpack (= 7.2.2)
65
+ activejob (= 7.2.2)
66
+ activerecord (= 7.2.2)
67
+ activesupport (= 7.2.2)
68
+ marcel (~> 1.0)
69
+ activesupport (7.2.2)
70
+ base64
71
+ benchmark (>= 0.3)
72
+ bigdecimal
73
+ concurrent-ruby (~> 1.0, >= 1.3.1)
74
+ connection_pool (>= 2.2.5)
75
+ drb
76
+ i18n (>= 1.6, < 2)
77
+ logger (>= 1.4.2)
78
+ minitest (>= 5.1)
79
+ securerandom (>= 0.3)
80
+ tzinfo (~> 2.0, >= 2.0.5)
81
+ ast (2.4.2)
82
+ base64 (0.2.0)
83
+ benchmark (0.4.0)
84
+ bigdecimal (3.1.8)
85
+ builder (3.3.0)
86
+ byebug (11.1.3)
87
+ concurrent-ruby (1.3.4)
88
+ connection_pool (2.4.1)
89
+ crass (1.0.6)
90
+ date (3.4.0)
91
+ diff-lcs (1.5.1)
92
+ dotenv (3.1.4)
93
+ drb (2.2.1)
94
+ erubi (1.13.0)
95
+ globalid (1.2.1)
96
+ activesupport (>= 6.1)
97
+ i18n (1.14.6)
98
+ concurrent-ruby (~> 1.0)
99
+ io-console (0.7.2)
100
+ irb (1.14.1)
101
+ rdoc (>= 4.0.0)
102
+ reline (>= 0.4.2)
103
+ json (2.7.6)
104
+ language_server-protocol (3.17.0.3)
105
+ logger (1.6.1)
106
+ loofah (2.23.1)
107
+ crass (~> 1.0.2)
108
+ nokogiri (>= 1.12.0)
109
+ mail (2.8.1)
110
+ mini_mime (>= 0.1.1)
111
+ net-imap
112
+ net-pop
113
+ net-smtp
114
+ marcel (1.0.4)
115
+ mini_mime (1.1.5)
116
+ minitest (5.25.1)
117
+ net-imap (0.5.1)
118
+ date
119
+ net-protocol
120
+ net-pop (0.1.2)
121
+ net-protocol
122
+ net-protocol (0.2.2)
123
+ timeout
124
+ net-smtp (0.5.0)
125
+ net-protocol
126
+ nio4r (2.7.4)
127
+ nokogiri (1.16.7-arm64-darwin)
128
+ racc (~> 1.4)
129
+ nokogiri (1.16.7-x86_64-linux)
130
+ racc (~> 1.4)
131
+ parallel (1.24.0)
132
+ parser (3.3.6.0)
133
+ ast (~> 2.4.1)
134
+ racc
135
+ psych (5.2.0)
136
+ stringio
137
+ racc (1.8.1)
138
+ rack (3.1.8)
139
+ rack-session (2.0.0)
140
+ rack (>= 3.0.0)
141
+ rack-test (2.1.0)
142
+ rack (>= 1.3)
143
+ rackup (2.2.1)
144
+ rack (>= 3)
145
+ rails (7.2.2)
146
+ actioncable (= 7.2.2)
147
+ actionmailbox (= 7.2.2)
148
+ actionmailer (= 7.2.2)
149
+ actionpack (= 7.2.2)
150
+ actiontext (= 7.2.2)
151
+ actionview (= 7.2.2)
152
+ activejob (= 7.2.2)
153
+ activemodel (= 7.2.2)
154
+ activerecord (= 7.2.2)
155
+ activestorage (= 7.2.2)
156
+ activesupport (= 7.2.2)
157
+ bundler (>= 1.15.0)
158
+ railties (= 7.2.2)
159
+ rails-dom-testing (2.2.0)
160
+ activesupport (>= 5.0.0)
161
+ minitest
162
+ nokogiri (>= 1.6)
163
+ rails-html-sanitizer (1.6.0)
164
+ loofah (~> 2.21)
165
+ nokogiri (~> 1.14)
166
+ railties (7.2.2)
167
+ actionpack (= 7.2.2)
168
+ activesupport (= 7.2.2)
169
+ irb (~> 1.13)
170
+ rackup (>= 1.0.0)
171
+ rake (>= 12.2)
172
+ thor (~> 1.0, >= 1.2.2)
173
+ zeitwerk (~> 2.6)
174
+ rainbow (3.1.1)
175
+ rake (13.2.1)
176
+ rdoc (6.7.0)
177
+ psych (>= 4.0.0)
178
+ regexp_parser (2.9.2)
179
+ reline (0.5.11)
180
+ io-console (~> 0.5)
181
+ rspec (3.13.0)
182
+ rspec-core (~> 3.13.0)
183
+ rspec-expectations (~> 3.13.0)
184
+ rspec-mocks (~> 3.13.0)
185
+ rspec-core (3.13.2)
186
+ rspec-support (~> 3.13.0)
187
+ rspec-expectations (3.13.3)
188
+ diff-lcs (>= 1.2.0, < 2.0)
189
+ rspec-support (~> 3.13.0)
190
+ rspec-mocks (3.13.2)
191
+ diff-lcs (>= 1.2.0, < 2.0)
192
+ rspec-support (~> 3.13.0)
193
+ rspec-support (3.13.1)
194
+ rubocop (1.68.0)
195
+ json (~> 2.3)
196
+ language_server-protocol (>= 3.17.0)
197
+ parallel (~> 1.10)
198
+ parser (>= 3.3.0.2)
199
+ rainbow (>= 2.2.2, < 4.0)
200
+ regexp_parser (>= 2.4, < 3.0)
201
+ rubocop-ast (>= 1.32.2, < 2.0)
202
+ ruby-progressbar (~> 1.7)
203
+ unicode-display_width (>= 2.4.0, < 3.0)
204
+ rubocop-ast (1.36.1)
205
+ parser (>= 3.3.1.0)
206
+ rubocop-performance (1.23.0)
207
+ rubocop (>= 1.48.1, < 2.0)
208
+ rubocop-ast (>= 1.31.1, < 2.0)
209
+ rubocop-rails (2.27.0)
210
+ activesupport (>= 4.2.0)
211
+ rack (>= 1.1)
212
+ rubocop (>= 1.52.0, < 2.0)
213
+ rubocop-ast (>= 1.31.1, < 2.0)
214
+ rubocop-rspec (3.2.0)
215
+ rubocop (~> 1.61)
216
+ rubocop-rspec_rails (2.30.0)
217
+ rubocop (~> 1.61)
218
+ rubocop-rspec (~> 3, >= 3.0.1)
219
+ ruby-progressbar (1.13.0)
220
+ securerandom (0.3.2)
221
+ stringio (3.1.2)
222
+ thor (1.3.2)
223
+ timeout (0.4.2)
224
+ tzinfo (2.0.6)
225
+ concurrent-ruby (~> 1.0)
226
+ unicode-display_width (2.6.0)
227
+ useragent (0.16.10)
228
+ websocket-driver (0.7.6)
229
+ websocket-extensions (>= 0.1.0)
230
+ websocket-extensions (0.1.5)
231
+ zeitwerk (2.6.18)
232
+
233
+ PLATFORMS
234
+ arm64-darwin-23
235
+ arm64-darwin-24
236
+ x86_64-linux
237
+
238
+ DEPENDENCIES
239
+ app_configurable!
240
+ byebug
241
+ rails (> 7.1)
242
+ rake (~> 13.0)
243
+ rspec (~> 3.0)
244
+ rubocop (~> 1.21)
245
+ rubocop-performance (~> 1.23.0)
246
+ rubocop-rails (~> 2.27.0)
247
+ rubocop-rspec (~> 3.2.0)
248
+ rubocop-rspec_rails (~> 2.30.0)
249
+
250
+ BUNDLED WITH
251
+ 2.4.12
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Dmytro Pasichnyk
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,62 @@
1
+ # AppConfigurable
2
+
3
+ Single source of truth for app configuration.
4
+
5
+ ## Adding a new config
6
+
7
+ There are 2 types of configs:
8
+ - Namespaced - used to store configs which could be grouped by attributes such as external service name e.g Hubspot.
9
+ - Root-level configs - generic configs for the app such as `rails_serve_static_files`.
10
+
11
+ Example of namespaced config:
12
+
13
+ ```ruby
14
+ class AppConfig::Hubspot
15
+ include AppConfigurable
16
+
17
+ entry :access_token, default: 'secret'
18
+ entry :base_url, default: 'https://app-eu1.hubspot.com/contacts/26265873', production: 'https://app-eu1.hubspot.com/contacts/25696692'
19
+ entry :client_secret, default: 'secret'
20
+ end
21
+ ```
22
+
23
+ Then config entries could be accessed through: `AppConfig::Hubspot.base_url`.
24
+
25
+ ## Attributes
26
+ Attributes are declared using `entry` directive.
27
+ Example: `entry :rails_serve_static_files`.
28
+
29
+ ### Options
30
+ `production/staging/development/test` - sets attributes per environment.
31
+
32
+ `default`:
33
+ - sets default attribute, used in `production/staging/development` environments as a fallback.
34
+ - accepts `string`/`number`/`boolean` as well as `Proc`/`Lambda` as a parameter.
35
+ - in `test` environment always falls back to a dummy value `some_super_dummy_#{namespaced_attribute_name}`
36
+
37
+ #### Priority and lifecycle:
38
+ `production/staging/development`:
39
+ 1) Tries to find a value in joint hash of `ENV` and `Rails.application.credentials`.
40
+ 2) Gets value from specific environment attribute passed to `entry`.
41
+ 3) Get's value from `default`.
42
+ 4) Raises `AppConfig::Error::RequiredVarMissing` if no attribute found.
43
+
44
+ `testing`:
45
+ 1) Tries to find a value in joint hash of `ENV` and `Rails.application.credentials`.
46
+ 2) Gets value from `test` environment attribute.
47
+ 3) Returns `some_super_dummy_#{namespaced_attribute_name}`, ignores specified `default` attribute.
48
+
49
+ ### Setting the environment
50
+ You could set environment per namespace like so:
51
+
52
+ Given namespace `AppConfig::MyNiceConfigClass` and `.env.staging`
53
+
54
+ ```bash
55
+ APPCONFIG_MYNICEMODULE_ENV=staging rspec
56
+ ```
57
+
58
+ *`.env.#{RAILS_ENV}` will be read per specific `AppConfig::SomeNiceClass` class.*
59
+
60
+ ### TODO:
61
+ - Read `Rails.application.credentials`
62
+ - Make dynamic switch possible, simillar to what we have with `ENV`.
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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AppConfigurable
4
+ class Error < StandardError
5
+ class InvalidValue < Error; end
6
+ class RequiredVarMissing < Error; end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AppConfigurable
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,258 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'app_configurable/version'
4
+
5
+ require 'active_support/core_ext/module/delegation'
6
+ require 'active_support/core_ext/hash/indifferent_access'
7
+ require 'active_support/core_ext/hash/keys'
8
+ require 'active_support/core_ext/string/inflections'
9
+ require 'active_support/string_inquirer'
10
+
11
+ require 'dotenv'
12
+
13
+ module AppConfigurable
14
+ @@available_config_attributes = [] # rubocop:disable Style/ClassVars
15
+
16
+ def self.included(owner)
17
+ owner.extend ClassMethods
18
+ owner.include InstanceMethods
19
+ end
20
+
21
+ def self.available_config_attributes
22
+ @@available_config_attributes
23
+ end
24
+
25
+ # Report missing required `ENV` variables.
26
+ # @return [Array]
27
+ def self.missing_required_vars
28
+ out = []
29
+
30
+ available_config_attributes.each do |method|
31
+ method.call
32
+ rescue Error::RequiredVarMissing
33
+ out << "#{method.receiver.name}.#{method.name}"
34
+ end
35
+ out
36
+ end
37
+
38
+ module ClassMethods
39
+ #--------------------------------------- Service
40
+ # return [Array]
41
+ def config_attributes
42
+ @config_attributes
43
+ end
44
+
45
+ # @param value [String]
46
+ # return [Boolean]
47
+ def env_value_boolean?(value)
48
+ env_value_truthy?(value) || env_value_falsey?(value)
49
+ end
50
+
51
+ # `true` if value is falsey.
52
+ #
53
+ # # These are falsey.
54
+ # DEBUG=0
55
+ # DEBUG=-1
56
+ # DEBUG=false
57
+ # DEBUG=f
58
+ # DEBUG=no
59
+ # DEBUG=disabled
60
+ #
61
+ # @param value [String]
62
+ # @return [Boolean]
63
+ def env_value_falsey?(value)
64
+ %w[0 -1 false f n no disabled].include? value.to_s.downcase
65
+ end
66
+
67
+ # `true` if value is truthy.
68
+ #
69
+ # # These are truthy.
70
+ # DEBUG=1
71
+ # DEBUG=true
72
+ # DEBUG=y
73
+ # DEBUG=yes
74
+ # DEBUG=enabled
75
+ #
76
+ # @param value [String]
77
+ # @return [Boolean]
78
+ def env_value_truthy?(value)
79
+ %w[1 true y yes enabled].include? value.to_s.downcase
80
+ end
81
+
82
+ # @param name [Symbol/String]
83
+ # @param default [Proc/String]
84
+ # @param development [String]
85
+ # @param production [String]
86
+ # @param staging [String]
87
+ # @param test [String]
88
+ # @return [void] Defines a class/instance getters for `name`.
89
+ def entry(name, default: nil, development: nil, production: nil, staging: nil, test: nil) # rubocop:disable Metrics/AbcSize
90
+ defined?(@config_attributes) ? @config_attributes << name : @config_attributes = [name]
91
+
92
+ define_method(name) do
93
+ preset_value = { development:, production:, staging:, test: }[rails_env.to_sym]
94
+
95
+ if instance_variable_defined?(:"@#{name}")
96
+ instance_variable_get(:"@#{name}")
97
+ else
98
+ instance_variable_set(:"@#{name}", per_env_value_fallback_for(name, default:, preset: preset_value))
99
+ end
100
+ end
101
+
102
+ define_singleton_method(name.to_s, -> { instance.public_send(name) })
103
+ AppConfigurable.available_config_attributes << method(name)
104
+ end
105
+
106
+ # @return [AppConfigurable]
107
+ def instance
108
+ @instance ||= new
109
+ end
110
+
111
+ delegate :rails_env, to: :instance
112
+ end
113
+
114
+ module InstanceMethods
115
+ require_relative 'app_configurable/error'
116
+
117
+ def initialize(attrs = {})
118
+ attrs.each { |k, v| public_send(:"#{k}=", v) }
119
+ end
120
+
121
+ # A *copy* of the credentials for value-reading purposes.
122
+ # @return [Hash]
123
+ def credentials
124
+ @credentials ||= ::Rails.application&.credentials.to_h
125
+ end
126
+
127
+ # A *copy* of the environment for value-reading purposes.
128
+ # @return [Hash]
129
+ def env
130
+ @env ||= ::Rails.env == rails_env ? ENV.to_h : ::Dotenv.parse(".env.#{rails_env}")
131
+ end
132
+
133
+ # @!attribute rails_env
134
+ # @return [ActiveSupport::StringInquirer] Default is `Rails.env`.
135
+ def rails_env
136
+ @rails_env ||= submodule_env || ::Rails.env
137
+ end
138
+
139
+ def rails_env=(value)
140
+ @rails_env =
141
+ begin
142
+ wrapper_klass = ActiveSupport::StringInquirer
143
+ value.is_a?(wrapper_klass) ? value : wrapper_klass.new(value)
144
+ end
145
+ recalculate_env
146
+ recalculate_values
147
+ end
148
+
149
+ # @return [ActiveSupport::StringInquirer/nil]
150
+ def submodule_env
151
+ @submodule_env ||=
152
+ begin
153
+ class_name = self.class.name
154
+ if class_name
155
+ selector = "#{class_name.parameterize(separator: "_")}_ENV"
156
+ env_string = ENV.fetch(selector.upcase, nil)
157
+ ActiveSupport::StringInquirer.new(env_string) if env_string
158
+ end
159
+ end
160
+ end
161
+
162
+ #--------------------------------------- `ENV` management
163
+ private
164
+
165
+ # @see #env_truthy?
166
+ # @param [String]
167
+ # @return [Boolean]
168
+ def env_boolean?(key)
169
+ env_falsey?(key) || env_truthy?(key)
170
+ end
171
+
172
+ # @see #env_truthy?
173
+ def env_falsey?(key)
174
+ self.class.env_value_falsey?(secrets[key.to_s])
175
+ end
176
+
177
+ # @param key [String/Symbol]
178
+ # @return [String/Boolean] The value of the environment variable, converts `bolean`'ish values into boolean.
179
+ def env_value(key)
180
+ v = secrets.dig(*key)
181
+ v = env_truthy?(key) if env_boolean?(key)
182
+ v
183
+ end
184
+
185
+ # `true` if environment variable `key` is truthy.
186
+ #
187
+ # env_truthy? "WITH_HTTP" # => `true` or `false`
188
+ # env_truthy? :WITH_HTTP # same as above
189
+ #
190
+ # @param key [String]
191
+ # @return [Boolean]
192
+ def env_truthy?(key)
193
+ self.class.env_value_truthy?(secrets[key.to_s])
194
+ end
195
+
196
+ # @param name [Symbol/String]
197
+ # @param default [Proc/String]
198
+ # @param preset [String]
199
+ # @raise [Error::RequiredVarMissing]
200
+ # @return [String]
201
+ def per_env_value_fallback_for(name, default: nil, preset: nil)
202
+ namespace = self.class.name&.[](/(?<=::).*$/)&.underscore.to_s
203
+ key = namespace.empty? ? name : "#{namespace}_#{name}"
204
+ default_value = per_env_default_value_fallback(default)
205
+ dummy_value = "some_super_dummy_#{key}"
206
+
207
+ result = env_value(key)
208
+ result = preset if result.nil?
209
+ result = default_value.call(dummy_value) if result.nil?
210
+ if result.nil?
211
+ raise Error::RequiredVarMissing,
212
+ "Required ENV variable or credential missing: #{self.class.name}.#{name}"
213
+ end
214
+
215
+ result
216
+ end
217
+
218
+ # @param default [Proc/String]
219
+ # @return [Proc]
220
+ def per_env_default_value_fallback(default)
221
+ if rails_env.test?
222
+ ->(dummy) { dummy }
223
+ else
224
+ default.is_a?(Proc) ? default : ->(_) { default }
225
+ end
226
+ end
227
+
228
+ # Recalculates the `env` hash.
229
+ # @return [void]
230
+ def recalculate_env
231
+ remove_instance_variable(:@env) if instance_variable_defined?(:@env)
232
+ send(:env)
233
+ end
234
+
235
+ # TODO: Implement this. Currently it's not re-reading secrets after enviromnemt change.
236
+ # Recalculates the `credentials` hash.
237
+ # @return [void]
238
+ def recalculate_credentials
239
+ remove_instance_variable(:@credentials) if instance_variable_defined?(:@credentials)
240
+ send(:credentials)
241
+ end
242
+
243
+ # Recalculates the values of all the attributes.
244
+ # @return [void]
245
+ def recalculate_values
246
+ self.class.config_attributes.each do |a|
247
+ remove_instance_variable(:"@#{a}") if instance_variable_defined?(:"@#{a}")
248
+ send(a)
249
+ end
250
+ end
251
+
252
+ # Joint hash of `ENV` and `Rails.application.credentials`
253
+ # @return [HashWithIndifferentAccess]
254
+ def secrets
255
+ { **env }.deep_transform_keys!(&:downcase).with_indifferent_access
256
+ end
257
+ end
258
+ end
@@ -0,0 +1,4 @@
1
+ module AppConfigurable
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: app_configurable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmytro Pasichnyk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '7.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '7.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.21'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.21'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.23.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.23.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.27.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.27.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 3.2.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 3.2.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec_rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.30.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.30.0
153
+ description: AppConfigurable allows you to configure your application with a simple
154
+ DSL including environment-specific configuration, define fallbacks etc.
155
+ email:
156
+ - dmytro.pasichnyk@omr.com
157
+ executables: []
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".byebug_history"
162
+ - ".rspec"
163
+ - ".rubocop.yml"
164
+ - ".rubocop/custom.yml"
165
+ - ".rubocop/rails.yml"
166
+ - ".rubocop/rspec.yml"
167
+ - CHANGELOG.md
168
+ - CODE_OF_CONDUCT.md
169
+ - Gemfile
170
+ - Gemfile.lock
171
+ - LICENSE.txt
172
+ - README.md
173
+ - Rakefile
174
+ - lib/app_configurable.rb
175
+ - lib/app_configurable/error.rb
176
+ - lib/app_configurable/version.rb
177
+ - sig/app_configurable.rbs
178
+ homepage: https://github.com/ramp106/app_configurable.git
179
+ licenses:
180
+ - MIT
181
+ metadata:
182
+ homepage_uri: https://github.com/ramp106/app_configurable.git
183
+ source_code_uri: https://github.com/ramp106/app_configurable.git
184
+ changelog_uri: https://github.com/ramp106/app_configurable/blob/main/CHANGELOG.md
185
+ rubygems_mfa_required: 'true'
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: 3.1.0
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ requirements: []
201
+ rubygems_version: 3.3.27
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: AppConfigurable allows you to configure your application with a simple DSL
205
+ including environment-specific configuration, define fallbacks etc.
206
+ test_files: []