sting 0.1.0 → 0.1.1
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 +88 -8
- data/lib/sting.rb +8 -4
- data/lib/sting/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b4cb2c0a668bf879e98ac401f7419678288949857b8ed055daf23a41cc6b7e7
|
4
|
+
data.tar.gz: e3c52cd17082f8cd7ce774aaa404ec1bc87091f09d3d5b5223d8e8fb70377b4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00dd281cbc65ec4365686ae4137c011397a18f1e12bef0bea99ae46d63a119d9f30063f3601de1ddc294cfe921808df515ad1d58454eba14e027413dc56dd044
|
7
|
+
data.tar.gz: ae1d6134e99010e99d9a06a836b28db0429c23236fcbb1ca614cfa1a06582825af0e728bfba7d28c265a9408b79984392e81f9ddaa12e89bb97f43c1d33cbbf9
|
data/README.md
CHANGED
@@ -15,9 +15,38 @@ Sting is a minimal, lightweight, multi-YAML settings library.
|
|
15
15
|
Installation
|
16
16
|
--------------------------------------------------
|
17
17
|
|
18
|
-
|
18
|
+
```shell
|
19
|
+
$ gem install sting
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
Why was this made?
|
24
|
+
--------------------------------------------------
|
25
|
+
|
26
|
+
Sting was made to replace the Rails Config gem, which has an unreasonable
|
27
|
+
amount of dependencies (i.e. the dry-validation gem, its children and
|
28
|
+
grandchildren...).
|
29
|
+
|
30
|
+
|
31
|
+
Features
|
32
|
+
--------------------------------------------------
|
33
|
+
|
34
|
+
- [Aggressively minimalistic][1], no dependencies, no monkey-patching, no magic.
|
35
|
+
- Settings are accessible through a globally available class.
|
36
|
+
- Load and merge one or more YAML files or hashes.
|
37
|
+
- Settings objects are standard ruby hashes, arrays and basic types.
|
38
|
+
- Ability to update settings at runtime.
|
39
|
+
- ERB code in the YAML files will be evaluated.
|
19
40
|
|
20
41
|
|
42
|
+
Nonfeatures
|
43
|
+
--------------------------------------------------
|
44
|
+
|
45
|
+
- No dot notation access to nested values - Use `Settings.server['host']`
|
46
|
+
instead of `Settings.server.host` - to avoid having to monkey-patch hashes.
|
47
|
+
- No special generators for Rails.
|
48
|
+
[Usage with rails is still trivial](#using-with-rails).
|
49
|
+
|
21
50
|
|
22
51
|
Usage
|
23
52
|
--------------------------------------------------
|
@@ -25,21 +54,72 @@ Usage
|
|
25
54
|
```ruby
|
26
55
|
require 'sting'
|
27
56
|
|
28
|
-
# If you want to use a different name than Sting
|
57
|
+
# If you want to use a different name than Sting (optional)
|
29
58
|
Settings = Sting
|
30
59
|
|
31
|
-
# Load some YAML files
|
60
|
+
# Load some YAML files. If the provided filename does end with '.yml' or
|
61
|
+
# '.yaml', we will add '.yml' to it.
|
32
62
|
Settings << 'one'
|
33
|
-
Settings << 'two'
|
63
|
+
Settings << 'two.yml'
|
64
|
+
|
65
|
+
# Merge with another options hash
|
66
|
+
Settings << { port: 3000, host: 'localhost' }
|
34
67
|
|
35
68
|
# Access values
|
36
|
-
p Settings.
|
37
|
-
p Settings['
|
38
|
-
p Settings[:
|
69
|
+
p Settings.host
|
70
|
+
p Settings['host']
|
71
|
+
p Settings[:host]
|
72
|
+
|
73
|
+
# Access nested values
|
74
|
+
p Settings.server['host']
|
39
75
|
|
40
76
|
# Access all values
|
41
|
-
p Settings.
|
77
|
+
p Settings.settings
|
42
78
|
|
43
79
|
# Check if a key is defined
|
44
80
|
p Settings.has_key? :hello
|
81
|
+
|
82
|
+
# Access value, but raise an exception if it does not exist
|
83
|
+
p Settings.host!
|
84
|
+
|
85
|
+
# Access boolean values, or check if a key exists
|
86
|
+
p Settings.host?
|
87
|
+
|
88
|
+
# Update a value (in memory only, not in file)
|
89
|
+
Settings.port = 3000
|
90
|
+
|
91
|
+
# Reset (erase) all values
|
92
|
+
Settings.reset!
|
45
93
|
```
|
94
|
+
|
95
|
+
|
96
|
+
Using with Rails
|
97
|
+
--------------------------------------------------
|
98
|
+
|
99
|
+
You can use this however you wish in Rails. This is the recommended
|
100
|
+
implementation:
|
101
|
+
|
102
|
+
Add sting to your Gemfile:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
gem 'sting'
|
106
|
+
```
|
107
|
+
|
108
|
+
Create an initializer:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
# config/initializers/settings.rb
|
112
|
+
Settings = Sting
|
113
|
+
Settings << "#{Rails.root}/config/settings"
|
114
|
+
Settings << "#{Rails.root}/config/settings/#{Rails.env}"
|
115
|
+
```
|
116
|
+
|
117
|
+
Create four config files:
|
118
|
+
|
119
|
+
- config/**settings**.yml
|
120
|
+
- config/settings/**development**.yml
|
121
|
+
- config/settings/**production**.yml
|
122
|
+
- config/settings/**test**.yml
|
123
|
+
|
124
|
+
|
125
|
+
[1]: https://github.com/DannyBen/sting/blob/master/lib/sting.rb
|
data/lib/sting.rb
CHANGED
@@ -3,10 +3,14 @@ require 'erb'
|
|
3
3
|
|
4
4
|
class Sting
|
5
5
|
class << self
|
6
|
-
def <<(
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def <<(source)
|
7
|
+
if source.is_a? Hash
|
8
|
+
content = source.collect{ |k,v| [k.to_s, v] }.to_h
|
9
|
+
else
|
10
|
+
source = "#{source}.yml" unless source =~ /\.ya?ml$/
|
11
|
+
content = File.read source
|
12
|
+
content = YAML.load(ERB.new(content).result)
|
13
|
+
end
|
10
14
|
settings.merge! content if content
|
11
15
|
end
|
12
16
|
|
data/lib/sting/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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: 2018-
|
11
|
+
date: 2018-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|