nero 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +128 -57
- data/lib/nero/version.rb +3 -1
- data/lib/nero.rb +12 -4
- data/rakelib/gem.rake +25 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aefcd9c69dd9c20501632b97f8738fa7bbe95115f694c086c89b20da5b55359a
|
4
|
+
data.tar.gz: 63c7d94edc645ad1bf4912f7f7ef4256aec15b6ee063ffc568ab322c2a8299c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9911e7bf5881fe44a2524adc67e875ff1b44318306cd00661a52d698fe12e87ac0d4bfaf91e41ad0122d531ffa7f1426ce86a1d81e72e36baac9088f093d185e
|
7
|
+
data.tar.gz: c25d5bf01e86ace03358cd1a829e784cc4479910601cb69ba9eebe5c8e71c176ebb17f53e319a6e710d575c14f6dc862af156e46d86cfd58b6591d1e6b0f6116
|
data/README.md
CHANGED
@@ -1,51 +1,148 @@
|
|
1
|
-
# Nero
|
1
|
+
# 🔥 Nero
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/nero)
|
4
4
|
|
5
|
-
|
6
|
-
development:
|
7
|
-
# required value from ENV
|
8
|
-
github_token: !env GH_TOKEN
|
5
|
+
Nero is a RubyGem that offers predefined tags and allows you to effortlessly create custom ones for YAML configuration files.
|
9
6
|
|
10
|
-
|
11
|
-
sentry_dsn: !env? SENTRY_DSN
|
7
|
+
E.g. instead of having the following settings file in your Ruby/Rails project:
|
12
8
|
|
13
|
-
|
14
|
-
|
9
|
+
```yaml
|
10
|
+
development:
|
11
|
+
# env-var with a fallback
|
12
|
+
secret: <%= ENV.fetch("SECRET", "dummy") %>
|
13
|
+
# NOTE *any* value provided is taken as `true`
|
14
|
+
debug?: <%= !!ENV["DEBUG"] %>
|
15
|
+
production:
|
16
|
+
# NOTE we can't fail-fast on ENV-var absence (i.e. use `ENV.fetch`),
|
17
|
+
# as it would require the env-var for development as well
|
18
|
+
secret: <%= ENV["SECRET"] %>
|
19
|
+
max_threads: <%= ENV.fetch("MAX_THREADS", 5).to_i %>
|
20
|
+
```
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
...turn it into this:
|
23
|
+
```yaml
|
24
|
+
development:
|
25
|
+
# env-var with a fallback
|
26
|
+
secret: !env [SECRET, "dummy"]
|
27
|
+
# Though the default is false, explicitly providing "false"/"off"/"n"/"no" is also possible.
|
28
|
+
debug?: !env/bool? DEBUG
|
29
|
+
production:
|
30
|
+
# fail-fast on absence of SECRET
|
31
|
+
secret: !env SECRET
|
32
|
+
# always an integer
|
33
|
+
max_threads: !env/integer [MAX_THREADS, 5]
|
34
|
+
```
|
20
35
|
|
21
|
-
|
36
|
+
## Installation
|
22
37
|
|
23
|
-
|
24
|
-
log: !str/inquirer
|
25
|
-
- !env LOG_LEVEL
|
38
|
+
Install the gem and add to the application's Gemfile by executing:
|
26
39
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
- /payment/setup
|
40
|
+
```bash
|
41
|
+
bundle add nero
|
42
|
+
```
|
31
43
|
|
32
|
-
|
33
|
-
- https://%s%s
|
34
|
-
- !env HOST
|
35
|
-
- /login
|
44
|
+
## Usage
|
36
45
|
|
37
|
-
|
46
|
+
> [!WARNING]
|
47
|
+
> It's early days - the API and included tags will certainly change. Check the CHANGELOG when upgrading.
|
38
48
|
|
49
|
+
Given the following config:
|
50
|
+
```yaml
|
51
|
+
# config/settings.yml
|
52
|
+
development:
|
53
|
+
# env-var with a fallback
|
54
|
+
secret: !env [SECRET, "dummy"]
|
55
|
+
# Though the default is false, explicitly providing "false"/"off"/"n"/"no" is also possible.
|
56
|
+
debug?: !env/bool? DEBUG
|
39
57
|
production:
|
40
|
-
#
|
41
|
-
# :development as
|
58
|
+
# fail-fast on absence of SECRET
|
42
59
|
secret: !env SECRET
|
60
|
+
# always an integer
|
61
|
+
max_threads: !env/integer [MAX_THREADS, 5]
|
43
62
|
```
|
44
63
|
|
45
|
-
|
64
|
+
Loading this config:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# Loading development
|
68
|
+
Nero.load_config(Pathname.pwd / "config/settings.yml", root: :development)
|
69
|
+
# ...and no ENV-vars were provided
|
70
|
+
#=> {secret: "dummy", debug?: false}
|
71
|
+
|
72
|
+
# ...with ENV {"debug" => "true"}
|
73
|
+
#=> {secret: "dummy", debug?: true}
|
74
|
+
|
75
|
+
# Loading production
|
76
|
+
Nero.load_config(Pathname.pwd / "config/settings.yml", root: :production)
|
77
|
+
# ...and no ENV-vars were provided
|
78
|
+
# raises error: key not found: "SECRET" (KeyError)
|
79
|
+
|
80
|
+
# ...with ENV {"SECRET" => "s3cr3t", "MAX_THREADS" => "3"}
|
81
|
+
#=> {secret: "s3cr3t", max_threads: 3}
|
82
|
+
```
|
83
|
+
|
84
|
+
The following tags are provided:
|
85
|
+
- `!env KEY`, `!env? KEY`
|
86
|
+
Resp. to fetch or get a value from `ENV`:
|
87
|
+
```yaml
|
88
|
+
---
|
89
|
+
# required
|
90
|
+
secret: !env SECRET
|
91
|
+
# optional, with fallback:
|
92
|
+
secret: !env [SECRET, "dummy-fallback"]
|
93
|
+
# ...or nil
|
94
|
+
secret: !env? SECRET
|
95
|
+
```
|
96
|
+
- to coerce env-values:
|
97
|
+
- `env/integer`, `env/integer?`:
|
98
|
+
```yaml
|
99
|
+
port: !env/integer [PORT, 3000]
|
100
|
+
threads: !env/integer? THREADS # nil when not provided
|
101
|
+
```
|
102
|
+
- `env/bool`, `env/bool?`:
|
103
|
+
```yaml
|
104
|
+
# required (valid values 'y(es)'/'n(o)', 'true'/'false', 'on'/'off')
|
105
|
+
over18: !env/bool OVER18
|
106
|
+
# optional, with fallback:
|
107
|
+
secure: !env/bool [SECURE, true]
|
108
|
+
# ...or false:
|
109
|
+
debug?: !env/bool? DEBUG
|
110
|
+
```
|
111
|
+
- `!path`
|
112
|
+
Create a [Pathname](https://rubyapi.org/3.4/o/pathname):
|
113
|
+
```yaml
|
114
|
+
config: !path config
|
115
|
+
# combining tags:
|
116
|
+
asset_folder: !path
|
117
|
+
- !env PROJECT_ROOT
|
118
|
+
- /public/assets
|
119
|
+
```
|
120
|
+
- `!uri`
|
121
|
+
Create a [URI](https://rubyapi.org/3.4/o/uri):
|
122
|
+
```yaml
|
123
|
+
smtp_url: !uri
|
124
|
+
- smtps://
|
125
|
+
- !env SMTP_CREDS
|
126
|
+
- @smtp.gmail.com
|
127
|
+
```
|
128
|
+
- `!str/format`
|
129
|
+
Using Ruby's [format specifications](https://docs.ruby-lang.org/en/master/format_specifications_rdoc.html):
|
130
|
+
```yaml
|
131
|
+
smtp_url: !str/format
|
132
|
+
- smtps://%s:%s@smtp.gmail.com
|
133
|
+
- !env SMTP_USER
|
134
|
+
- !env SMTP_PASS
|
135
|
+
# using references
|
136
|
+
smtp_url: !str/format
|
137
|
+
fmt: smtps://%<user>s:%<pass>s@smtp.gmail.com
|
138
|
+
user: !env SMTP_USER
|
139
|
+
pass: !env SMTP_PASS
|
140
|
+
```
|
141
|
+
|
142
|
+
TBD Add one yourself:
|
46
143
|
```ruby
|
47
144
|
Nero.configure do
|
48
|
-
|
145
|
+
add_tag("foo") do |coder|
|
49
146
|
# coder.type is one of :scalar, :seq or :map
|
50
147
|
# e.g. respective YAML:
|
51
148
|
# ---
|
@@ -63,32 +160,6 @@ Nero.configure do
|
|
63
160
|
end
|
64
161
|
```
|
65
162
|
|
66
|
-
|
67
|
-
|
68
|
-
TODO: Delete this and the text below, and describe your gem
|
69
|
-
|
70
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nero`. To experiment with that code, run `bin/console` for an interactive prompt.
|
71
|
-
|
72
|
-
## Installation
|
73
|
-
|
74
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
75
|
-
|
76
|
-
Install the gem and add to the application's Gemfile by executing:
|
77
|
-
|
78
|
-
```bash
|
79
|
-
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
80
|
-
```
|
81
|
-
|
82
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
83
|
-
|
84
|
-
```bash
|
85
|
-
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
86
|
-
```
|
87
|
-
|
88
|
-
## Usage
|
89
|
-
|
90
|
-
TODO: Write usage instructions here
|
91
|
-
|
92
163
|
## Development
|
93
164
|
|
94
165
|
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.
|
data/lib/nero/version.rb
CHANGED
data/lib/nero.rb
CHANGED
@@ -8,6 +8,7 @@ require "uri" # why needed?
|
|
8
8
|
|
9
9
|
# TODO fail on unknown tag
|
10
10
|
# TODO show missing env's at once
|
11
|
+
# TODO raise when missing arg(s) for tag
|
11
12
|
module Nero
|
12
13
|
class Error < StandardError; end
|
13
14
|
|
@@ -57,8 +58,15 @@ module Nero
|
|
57
58
|
(@resolvers ||= {})["!#{name}"] = block
|
58
59
|
end
|
59
60
|
|
61
|
+
def self.env_fetch(k, fallback = nil, all_optional: "dummy")
|
62
|
+
fallback ||= all_optional if ENV["NERO_ENV_ALL_OPTIONAL"]
|
63
|
+
|
64
|
+
fallback.nil? ? ENV.fetch(k) : ENV.fetch(k, fallback)
|
65
|
+
end
|
66
|
+
private_class_method :env_fetch
|
67
|
+
|
60
68
|
add_resolver("env/integer") do |coder|
|
61
|
-
Integer(
|
69
|
+
Integer(env_fetch(*(coder.scalar || coder.seq), all_optional: "999"))
|
62
70
|
end
|
63
71
|
|
64
72
|
add_resolver("env/integer?") do |coder|
|
@@ -79,7 +87,7 @@ module Nero
|
|
79
87
|
end
|
80
88
|
end
|
81
89
|
|
82
|
-
coerce[
|
90
|
+
coerce[env_fetch(*(coder.scalar || coder.seq), all_optional: "false")]
|
83
91
|
end
|
84
92
|
|
85
93
|
add_resolver("env/bool?") do |coder|
|
@@ -100,7 +108,7 @@ module Nero
|
|
100
108
|
end
|
101
109
|
|
102
110
|
add_resolver("env") do |coder|
|
103
|
-
|
111
|
+
env_fetch(*(coder.scalar || coder.seq))
|
104
112
|
end
|
105
113
|
|
106
114
|
add_resolver("env?") do |coder|
|
@@ -135,7 +143,7 @@ module Nero
|
|
135
143
|
if file.exist?
|
136
144
|
unresolved = Util.deep_symbolize_keys(YAML.load_file(file,
|
137
145
|
permitted_classes: [Symbol, TagResolver], aliases: true)).then do
|
138
|
-
root ? _1[root] : _1
|
146
|
+
root ? _1[root.to_sym] : _1
|
139
147
|
end
|
140
148
|
|
141
149
|
deep_resolve(unresolved, resolvers: @resolvers)
|
data/rakelib/gem.rake
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
namespace :gem do
|
2
|
+
task "write_version", [:version] do |_task, args|
|
3
|
+
if args[:version]
|
4
|
+
version = args[:version].split("=").last
|
5
|
+
version_file = File.expand_path("../../lib/nero/version.rb", __FILE__)
|
6
|
+
|
7
|
+
system(<<~CMD, exception: true)
|
8
|
+
ruby -pi -e 'gsub(/VERSION = ".*"/, %{VERSION = "#{version}"})' #{version_file}
|
9
|
+
CMD
|
10
|
+
Bundler.ui.confirm "Version #{version} written to #{version_file}."
|
11
|
+
else
|
12
|
+
Bundler.ui.warn "No version provided, keeping version.rb as is."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Build [version]"
|
17
|
+
task "build", [:version] => %w[write_version] do
|
18
|
+
Rake::Task["build"].invoke
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Build and push [version] to rubygems"
|
22
|
+
task "release", [:version] => %w[build] do
|
23
|
+
Rake::Task["release:rubygem_push"].invoke
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gert Goet
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-01-
|
10
|
+
date: 2025-01-29 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: zeitwerk
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/nero.rb
|
47
47
|
- lib/nero/util.rb
|
48
48
|
- lib/nero/version.rb
|
49
|
+
- rakelib/gem.rake
|
49
50
|
- sig/nero.rbs
|
50
51
|
homepage: https://github.com/eval/nero
|
51
52
|
licenses:
|
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
69
|
- !ruby/object:Gem::Version
|
69
70
|
version: '0'
|
70
71
|
requirements: []
|
71
|
-
rubygems_version: 3.6.
|
72
|
+
rubygems_version: 3.6.2
|
72
73
|
specification_version: 4
|
73
74
|
summary: Convenience YAML-tags
|
74
75
|
test_files: []
|