sting 0.3.0 → 0.4.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 +4 -4
- data/README.md +19 -9
- data/lib/sting/sting_operations.rb +5 -6
- data/lib/sting/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b2589314624afd57349ddea39fb0c4fd46af5670eed2e3452e0eae9cfcbe0e4
|
4
|
+
data.tar.gz: 6b8c31692c719ecd1b9eb69e82492555253254bc4bde54acd3d4ef16dd4bd23f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d50d35ab902ce86c71336e0d64c7c84730df18edd882160957b9731828a9eb4536af27b8f32e6b7402ea44ae2006dd01d4abbfee787e917f6c749ed8106a53c
|
7
|
+
data.tar.gz: d893bc658548ae2e88a023bb413703ded8fc3fa1bf733ac232d6baa9451456973270c2fe5b6e8151cbe904027ac4921686366fcf10b15d8c02f765efef84e17f
|
data/README.md
CHANGED
@@ -19,23 +19,16 @@ $ gem install sting
|
|
19
19
|
```
|
20
20
|
|
21
21
|
|
22
|
-
Why was this made?
|
23
|
-
--------------------------------------------------
|
24
|
-
|
25
|
-
Sting was made to replace the Rails Config gem, which has an unreasonable
|
26
|
-
amount of dependencies (i.e. the dry-validation gem, its children and
|
27
|
-
grandchildren...).
|
28
|
-
|
29
|
-
|
30
22
|
Features
|
31
23
|
--------------------------------------------------
|
32
24
|
|
33
|
-
- [Aggressively minimalistic][1]
|
25
|
+
- [Aggressively minimalistic][1].
|
34
26
|
- Settings are accessible through a globally available class.
|
35
27
|
- Can be used either as a singleton class or as an instance.
|
36
28
|
- Load and merge one or more YAML files or hashes.
|
37
29
|
- Settings objects are standard ruby hashes, arrays and basic types.
|
38
30
|
- Ability to update settings at runtime.
|
31
|
+
- [Ability to extend](#extending-yaml-files) (import) other YAML files.
|
39
32
|
- ERB code in the YAML files will be evaluated.
|
40
33
|
|
41
34
|
|
@@ -121,6 +114,22 @@ config << 'local_settings'
|
|
121
114
|
```
|
122
115
|
|
123
116
|
|
117
|
+
### Extending YAML files
|
118
|
+
|
119
|
+
Sting uses [ExtendedYAML], which means you can use the `extends` key to load
|
120
|
+
one ormore YAML files into your loaded configuration files:
|
121
|
+
|
122
|
+
```yaml
|
123
|
+
# Extend a single file (extension is optional)
|
124
|
+
extends: some-other-file.yml
|
125
|
+
|
126
|
+
# Extend multiple files
|
127
|
+
extends:
|
128
|
+
- some-file
|
129
|
+
- another-file
|
130
|
+
```
|
131
|
+
|
132
|
+
|
124
133
|
Using with Rails
|
125
134
|
--------------------------------------------------
|
126
135
|
|
@@ -151,3 +160,4 @@ Create four config files:
|
|
151
160
|
|
152
161
|
|
153
162
|
[1]: https://github.com/DannyBen/sting/blob/master/lib/sting/sting_operations.rb
|
163
|
+
[2]: https://github.com/DannyBen/extended_yaml
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'erb'
|
1
|
+
require 'extended_yaml'
|
3
2
|
|
4
3
|
class Sting
|
5
4
|
module StingOperations
|
@@ -12,15 +11,14 @@ class Sting
|
|
12
11
|
content = source.collect{ |k,v| [k.to_s, v] }.to_h
|
13
12
|
else
|
14
13
|
source = "#{source}.yml" unless source =~ /\.ya?ml$/
|
15
|
-
content =
|
16
|
-
content = YAML.load(ERB.new(content).result)
|
14
|
+
content = ExtendedYAML.load source
|
17
15
|
end
|
18
16
|
settings.merge! content if content
|
19
17
|
end
|
20
18
|
alias_method :push, :<<
|
21
19
|
|
22
20
|
def [](*keys)
|
23
|
-
settings.dig
|
21
|
+
settings.dig(*keys.map(&:to_s))
|
24
22
|
end
|
25
23
|
|
26
24
|
def method_missing(name, *args, &blk)
|
@@ -29,7 +27,7 @@ class Sting
|
|
29
27
|
|
30
28
|
suffix = nil
|
31
29
|
|
32
|
-
if name.end_with?
|
30
|
+
if name.end_with?('=', '!', '?')
|
33
31
|
suffix = name[-1]
|
34
32
|
name = name[0..-2]
|
35
33
|
end
|
@@ -58,6 +56,7 @@ class Sting
|
|
58
56
|
def settings
|
59
57
|
@settings ||= {}
|
60
58
|
end
|
59
|
+
alias to_h settings
|
61
60
|
|
62
61
|
def reset!
|
63
62
|
@settings = nil
|
data/lib/sting/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2020-01-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: extended_yaml
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
13
27
|
description: Minimal, lightweight, multi-YAML settings
|
14
28
|
email: db@dannyben.com
|
15
29
|
executables: []
|
@@ -39,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
requirements: []
|
42
|
-
rubygems_version: 3.0.
|
56
|
+
rubygems_version: 3.0.3
|
43
57
|
signing_key:
|
44
58
|
specification_version: 4
|
45
59
|
summary: Minimal, lightweight, multi-YAML settings
|