ascm 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
+ SHA1:
3
+ metadata.gz: f90ccc59f87a3dd79a04b44e02ac8f423a16f748
4
+ data.tar.gz: 05651fe74d2eaec13dd954cec936b20393bb047f
5
+ SHA512:
6
+ metadata.gz: 48a8f3a6290ac1702a070ca6249e4bc2e39e4d22a74e9f9ca500637237d1fb4bcbb497f1bc2aec7ea09dc69651e8c18774354649c48dd6a954d93c15942bb618
7
+ data.tar.gz: 46f72ab630bf46e7b603a2512a71b530370eb132bd694db8baaf7e0972fae098e9948113b901ffd1e47e1a77047ee91133fa3890f92aca2c85cd070258b54d24
data/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+
8
+ [{*.rb,*.yml,*.rake,Gemfile,Rakefile}]
9
+ indent_style = space
10
+ indent_size = 2
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,316 @@
1
+ AllCops:
2
+ DisabledByDefault: true
3
+
4
+ Bundler/DuplicatedGem:
5
+ Enabled: true
6
+
7
+ Bundler/OrderedGems:
8
+ Enabled: true
9
+
10
+ Layout/BlockAlignment:
11
+ Enabled: true
12
+
13
+ Lint/CircularArgumentReference:
14
+ Enabled: true
15
+
16
+ Layout/ConditionPosition:
17
+ Enabled: true
18
+
19
+ Lint/Debugger:
20
+ Enabled: true
21
+
22
+ Layout/DefEndAlignment:
23
+ Enabled: true
24
+
25
+ Lint/DeprecatedClassMethods:
26
+ Enabled: true
27
+
28
+ Lint/DuplicateMethods:
29
+ Enabled: true
30
+
31
+ Lint/DuplicatedKey:
32
+ Enabled: true
33
+
34
+ Lint/EachWithObjectArgument:
35
+ Enabled: true
36
+
37
+ Lint/ElseLayout:
38
+ Enabled: true
39
+
40
+ Lint/EmptyEnsure:
41
+ Enabled: true
42
+
43
+ Lint/EndInMethod:
44
+ Enabled: true
45
+
46
+ Lint/EmptyInterpolation:
47
+ Enabled: true
48
+
49
+ Layout/EndAlignment:
50
+ Enabled: false
51
+
52
+ Lint/EnsureReturn:
53
+ Enabled: true
54
+
55
+ Lint/FloatOutOfRange:
56
+ Enabled: true
57
+
58
+ Lint/FormatParameterMismatch:
59
+ Enabled: true
60
+
61
+ Style/HashSyntax:
62
+ Enabled: true
63
+ EnforcedStyle: ruby19
64
+
65
+ Lint/LiteralAsCondition:
66
+ Enabled: true
67
+
68
+ Lint/LiteralInInterpolation:
69
+ Enabled: true
70
+
71
+ Lint/Loop:
72
+ Enabled: true
73
+
74
+ Lint/NextWithoutAccumulator:
75
+ Enabled: true
76
+
77
+ Lint/RandOne:
78
+ Enabled: true
79
+
80
+ Lint/RequireParentheses:
81
+ Enabled: true
82
+
83
+ Lint/RescueException:
84
+ Enabled: true
85
+
86
+ Lint/StringConversionInInterpolation:
87
+ Enabled: true
88
+
89
+ Lint/UnderscorePrefixedVariableName:
90
+ Enabled: true
91
+
92
+ Lint/UnneededCopDisableDirective:
93
+ Enabled: true
94
+
95
+ Lint/UnneededSplatExpansion:
96
+ Enabled: true
97
+
98
+ Lint/UnreachableCode:
99
+ Enabled: true
100
+
101
+ Lint/UselessComparison:
102
+ Enabled: true
103
+
104
+ Lint/UselessSetterCall:
105
+ Enabled: true
106
+
107
+ Lint/Void:
108
+ Enabled: true
109
+
110
+ Metrics/AbcSize:
111
+ Enabled: false
112
+
113
+ Metrics/BlockLength:
114
+ Enabled: false
115
+
116
+ Metrics/BlockNesting:
117
+ Enabled: false
118
+
119
+ Metrics/ClassLength:
120
+ Enabled: false
121
+
122
+ Metrics/CyclomaticComplexity:
123
+ Enabled: false
124
+
125
+ Metrics/LineLength:
126
+ Enabled: false
127
+
128
+ Metrics/MethodLength:
129
+ Enabled: false
130
+
131
+ Metrics/ModuleLength:
132
+ Enabled: false
133
+
134
+ Metrics/ParameterLists:
135
+ Enabled: false
136
+
137
+ Metrics/PerceivedComplexity:
138
+ Enabled: false
139
+
140
+ Performance/CaseWhenSplat:
141
+ Enabled: false
142
+
143
+ Performance/Count:
144
+ Enabled: true
145
+
146
+ Performance/Detect:
147
+ Enabled: true
148
+
149
+ Performance/DoubleStartEndWith:
150
+ Enabled: true
151
+
152
+ Performance/EndWith:
153
+ Enabled: true
154
+
155
+ Performance/FlatMap:
156
+ Enabled: true
157
+
158
+ Performance/LstripRstrip:
159
+ Enabled: true
160
+
161
+ Performance/RangeInclude:
162
+ Enabled: false
163
+
164
+ Performance/RedundantMatch:
165
+ Enabled: false
166
+
167
+ Performance/RedundantMerge:
168
+ Enabled: true
169
+ MaxKeyValuePairs: 1
170
+
171
+ Performance/RedundantSortBy:
172
+ Enabled: true
173
+
174
+ Performance/ReverseEach:
175
+ Enabled: true
176
+
177
+ Performance/Sample:
178
+ Enabled: true
179
+
180
+ Performance/Size:
181
+ Enabled: true
182
+
183
+ Performance/StartWith:
184
+ Enabled: true
185
+
186
+ Security/Eval:
187
+ Enabled: true
188
+
189
+ Style/ArrayJoin:
190
+ Enabled: true
191
+
192
+ Naming/AsciiIdentifiers:
193
+ Enabled: true
194
+
195
+ Style/BeginBlock:
196
+ Enabled: true
197
+
198
+ Style/BlockComments:
199
+ Enabled: true
200
+
201
+ Layout/BlockEndNewline:
202
+ Enabled: true
203
+
204
+ Style/CaseEquality:
205
+ Enabled: true
206
+
207
+ Style/CharacterLiteral:
208
+ Enabled: true
209
+
210
+ Naming/ClassAndModuleCamelCase:
211
+ Enabled: true
212
+
213
+ Style/ClassMethods:
214
+ Enabled: true
215
+
216
+ Style/Copyright:
217
+ Enabled: false
218
+
219
+ Style/DefWithParentheses:
220
+ Enabled: true
221
+
222
+ Style/EndBlock:
223
+ Enabled: true
224
+
225
+ Layout/EndOfLine:
226
+ Enabled: true
227
+
228
+ Naming/FileName:
229
+ Enabled: true
230
+
231
+ Style/FlipFlop:
232
+ Enabled: true
233
+
234
+ Style/For:
235
+ Enabled: true
236
+
237
+ Style/FrozenStringLiteralComment:
238
+ Enabled: true
239
+
240
+ Layout/InitialIndentation:
241
+ Enabled: true
242
+
243
+ Style/LambdaCall:
244
+ Enabled: true
245
+
246
+ Style/MethodCallWithoutArgsParentheses:
247
+ Enabled: true
248
+
249
+ Style/MethodDefParentheses:
250
+ Enabled: true
251
+
252
+ Naming/MethodName:
253
+ Enabled: true
254
+
255
+ Style/MultilineIfThen:
256
+ Enabled: true
257
+
258
+ Style/NilComparison:
259
+ Enabled: true
260
+
261
+ Style/Not:
262
+ Enabled: true
263
+
264
+ Style/OneLineConditional:
265
+ Enabled: true
266
+
267
+ Layout/SpaceAfterMethodName:
268
+ Enabled: true
269
+
270
+ Layout/SpaceAfterColon:
271
+ Enabled: true
272
+
273
+ Layout/SpaceAfterComma:
274
+ Enabled: true
275
+
276
+ Layout/SpaceAfterNot:
277
+ Enabled: true
278
+
279
+ Layout/SpaceAfterSemicolon:
280
+ Enabled: true
281
+
282
+ Layout/SpaceAroundBlockParameters:
283
+ Enabled: true
284
+
285
+ Layout/SpaceAroundEqualsInParameterDefault:
286
+ Enabled: true
287
+
288
+ Layout/SpaceInsideArrayPercentLiteral:
289
+ Enabled: true
290
+
291
+ Layout/SpaceInsideArrayLiteralBrackets:
292
+ Enabled: true
293
+
294
+ Layout/SpaceInsideReferenceBrackets:
295
+ Enabled: true
296
+
297
+ Layout/SpaceInsideParens:
298
+ Enabled: true
299
+
300
+ Layout/SpaceInsideRangeLiteral:
301
+ Enabled: true
302
+
303
+ Style/StabbyLambdaParentheses:
304
+ Enabled: true
305
+
306
+ Style/StringLiterals:
307
+ Enabled: true
308
+
309
+ Layout/Tab:
310
+ Enabled: true
311
+
312
+ Layout/TrailingBlankLines:
313
+ Enabled: true
314
+
315
+ Layout/TrailingWhitespace:
316
+ Enabled: true
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hey@vito.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ascm.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ascm (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ climate_control (0.2.0)
11
+ codecov (0.1.10)
12
+ json
13
+ simplecov
14
+ url
15
+ diff-lcs (1.3)
16
+ docile (1.3.1)
17
+ json (2.1.0)
18
+ parallel (1.12.1)
19
+ parser (2.5.1.0)
20
+ ast (~> 2.4.0)
21
+ powerpack (0.1.2)
22
+ rainbow (3.0.0)
23
+ rake (10.5.0)
24
+ rspec (3.7.0)
25
+ rspec-core (~> 3.7.0)
26
+ rspec-expectations (~> 3.7.0)
27
+ rspec-mocks (~> 3.7.0)
28
+ rspec-core (3.7.1)
29
+ rspec-support (~> 3.7.0)
30
+ rspec-expectations (3.7.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.7.0)
33
+ rspec-mocks (3.7.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.7.0)
36
+ rspec-support (3.7.1)
37
+ rubocop (0.55.0)
38
+ parallel (~> 1.10)
39
+ parser (>= 2.5)
40
+ powerpack (~> 0.1)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (~> 1.0, >= 1.0.1)
44
+ ruby-progressbar (1.9.0)
45
+ simplecov (0.16.1)
46
+ docile (~> 1.1)
47
+ json (>= 1.8, < 3)
48
+ simplecov-html (~> 0.10.0)
49
+ simplecov-html (0.10.2)
50
+ unicode-display_width (1.4.0)
51
+ url (0.3.2)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ ascm!
58
+ bundler (~> 1.16)
59
+ climate_control (~> 0.2)
60
+ codecov
61
+ rake (~> 10.0)
62
+ rspec (~> 3.0)
63
+ rubocop (~> 0.55.0)
64
+ simplecov (~> 0.16.1)
65
+
66
+ BUNDLED WITH
67
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Victor Gama
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,97 @@
1
+ # ASCM
2
+
3
+ ASCM stands to **A** **S**mall **C**onfiguration **M**anager. It simply reads
4
+ configuration keys available in your Environment (`ENV`) and defines class
5
+ methods in a given class.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ascm'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ascm
22
+
23
+ ## Usage
24
+
25
+ To use ASCM, define a class and inherit `ASCM::Reader`:
26
+
27
+ ```ruby
28
+ class Config < ASCM::Reader
29
+ def_setting :database_url
30
+ def_setting :redis_url
31
+ def_setting :max_connections, default: 20, map: -> i { i.to_i }
32
+ def_setting :is_debug, default: false, map: -> v { ['yes', 'true', '1'].include? v }
33
+ end
34
+ ```
35
+
36
+ `def_setting` instructs the `Reader` to look for a environment key with the
37
+ provided name. For instance, our `def_setting :is_debug` will look for a
38
+ `IS_DEBUG` key in the current application environment, and will define a few
39
+ class methods in our `Config` class:
40
+
41
+ 1. `is_debug`: Returns the found `IS_DEBUG` value, or `nil`, if none is
42
+ found (and no `default` is provided), passing any found value through the
43
+ provided `map` lambda
44
+ 2. `has_is_debug?` returns `true` as long as `is_debug` is not `nil`,
45
+ returning `false` otherwise.
46
+
47
+ > **Protip**: ASCM defines an extra `is_debug?` (note the question mark) when a
48
+ > variable begins has `is_` as prefix.
49
+
50
+ `def_setting` also support a few modifiers:
51
+ - `map` expects a lambda (or `Proc`), passing the found value as the first (and
52
+ only) parameter of the provided lambda. In case the lambda throws an Error,
53
+ ASCM automatically falls back to the `default` provided value.
54
+ - `default` defines a default value in case the provided key cannot be found.
55
+ Defaults to `nil`. **Notice**: `map` lambdas are not called when a `default`
56
+ value is used.
57
+
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/victorgama/ascm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+
69
+ ## Code of Conduct
70
+
71
+ Everyone interacting in the ASCM project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/victorgama/ascm/blob/master/CODE_OF_CONDUCT.md).
72
+
73
+ ## License
74
+
75
+ ```
76
+ The MIT License (MIT)
77
+
78
+ Copyright (c) 2018 Victor Gama
79
+
80
+ Permission is hereby granted, free of charge, to any person obtaining a copy
81
+ of this software and associated documentation files (the "Software"), to deal
82
+ in the Software without restriction, including without limitation the rights
83
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
84
+ copies of the Software, and to permit persons to whom the Software is
85
+ furnished to do so, subject to the following conditions:
86
+
87
+ The above copyright notice and this permission notice shall be included in
88
+ all copies or substantial portions of the Software.
89
+
90
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
91
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
92
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
93
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
94
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
95
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
96
+ THE SOFTWARE.
97
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/ascm.gemspec ADDED
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ascm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ascm'
8
+ spec.version = ASCM::VERSION
9
+ spec.authors = ['Victor Gama']
10
+ spec.email = ['hey@vito.io']
11
+
12
+ spec.summary = 'ASCM is A Simple Configuration Manager, reading things from ENV to values in a class'
13
+ spec.description = <<-description
14
+ ASCM reads ENV varaibles into a class, providing methods to ensure a setting
15
+ is available, and mapping variables using Lambdas. The result is a clean,
16
+ comprehensive configuration file that may be documented as desired, allowing
17
+ other developers to quickly inspect and understand existing parameters and
18
+ quickly adding new ones.
19
+ description
20
+ spec.homepage = 'https://github.com/victorgama/ascm'
21
+ spec.license = 'MIT'
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.16'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'climate_control', '~> 0.2'
34
+ spec.add_development_dependency 'simplecov', '~> 0.16.1'
35
+ spec.add_development_dependency 'rubocop', '~> 0.55.0'
36
+ spec.add_development_dependency 'codecov'
37
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ascm'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/ascm.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+ require 'ascm/version'
5
+ require 'ascm/reader'
6
+
7
+ module ASCM
8
+ class << self
9
+ attr_writer :logger
10
+
11
+ def logger
12
+ @logger ||= Logger.new($stdout).tap do |log|
13
+ log.progname = self.name
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ASCM
4
+ # Reader represents the base class that configuration classes should inherit
5
+ # in order to read settings from ENV
6
+ class Reader
7
+ @@prefix = nil
8
+
9
+ # Public: Declares a new setting to be loaded from the local environment. It
10
+ # automatically appends the provided prefix (through #uses_prefix!) to the
11
+ # provided string and capitalizes it.
12
+ #
13
+ # name - Name of the setting to be loaded
14
+ # opts - Hash of extra options.
15
+ # default: used to automatically set a value when it cannot be found
16
+ # on the current environment. Defaults to `nil`.
17
+ # map: Lambda to be called in order to map a value obtained from the
18
+ # environment. Won't be called when using a value supplied by
19
+ # the `default` key, and will fallback to the `default` value
20
+ # in case the Lambda throws an error.
21
+ #
22
+ # Returns nothing, but defines two new methods on the inheriting class.
23
+ # Methods are based on the provided name. Defines a class method with the
24
+ # provided name and another method named `has_#name?`, that returns true
25
+ # whenever the value of #name is not nil.
26
+ # After loading settings, those cannot be changed dynamically during runtime.
27
+ def self.def_setting(name, opts = {})
28
+ string_name = name.to_s.freeze
29
+ env_name = "#{@@prefix.nil? ? '' : "#{@@prefix}_"}#{string_name}".upcase
30
+ default = opts.fetch(:default, nil)
31
+ value = ENV.fetch(env_name, default)
32
+
33
+ if opts.key? :map
34
+ begin
35
+ value = opts[:map][value]
36
+ rescue StandardError => ex
37
+ ASCM.logger.error("BaseConfig failed to map key #{name}:")
38
+ ASCM.logger.error(ex)
39
+ ASCM.logger.error("Falling back to default value '#{default}'")
40
+ value = default
41
+ end
42
+ end
43
+
44
+ define_singleton_method name do
45
+ value
46
+ end
47
+
48
+ define_singleton_method "has_#{name}?" do
49
+ !value.nil?
50
+ end
51
+
52
+ if string_name.start_with?('is_')
53
+ define_singleton_method "#{name}?" do
54
+ value
55
+ end
56
+ end
57
+ end
58
+
59
+ # Public: Marks the current configuration as to having a prefix before the
60
+ # declared names on #def_setting
61
+ # Reffer to #def_setting for further details.
62
+ #
63
+ # prefix - Prefix used by the configuration keys
64
+ #
65
+ # Returns nothing
66
+ def self.uses_prefix!(prefix)
67
+ @@prefix = prefix
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module ASCM
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ascm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor Gama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: climate_control
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.16.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.16.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.55.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.55.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: codecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: |2
112
+ ASCM reads ENV varaibles into a class, providing methods to ensure a setting
113
+ is available, and mapping variables using Lambdas. The result is a clean,
114
+ comprehensive configuration file that may be documented as desired, allowing
115
+ other developers to quickly inspect and understand existing parameters and
116
+ quickly adding new ones.
117
+ email:
118
+ - hey@vito.io
119
+ executables: []
120
+ extensions: []
121
+ extra_rdoc_files: []
122
+ files:
123
+ - ".editorconfig"
124
+ - ".gitignore"
125
+ - ".rspec"
126
+ - ".rubocop.yml"
127
+ - ".travis.yml"
128
+ - CODE_OF_CONDUCT.md
129
+ - Gemfile
130
+ - Gemfile.lock
131
+ - LICENSE.txt
132
+ - README.md
133
+ - Rakefile
134
+ - ascm.gemspec
135
+ - bin/console
136
+ - bin/setup
137
+ - lib/ascm.rb
138
+ - lib/ascm/reader.rb
139
+ - lib/ascm/version.rb
140
+ homepage: https://github.com/victorgama/ascm
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.6.14
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: ASCM is A Simple Configuration Manager, reading things from ENV to values
164
+ in a class
165
+ test_files: []