sting 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -2
- data/lib/sting/sting_operations.rb +70 -0
- data/lib/sting/version.rb +1 -1
- data/lib/sting.rb +4 -58
- metadata +4 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 271132274baa28e3ded663cbd4abda0b371b948cdc71b2a6b1cd6a9e0dd444aa
|
4
|
+
data.tar.gz: 424dc73b1871a68e87f0206b354a40995f9fef20a9b35892d0ec71102f293c0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa0836070e5db815867796c726b4e3eea387d9f3fd859ecb17abe770d224994142c478295f4340eeecb5f42e89a39f3dbd18374ca4b76f50d361675930704093
|
7
|
+
data.tar.gz: ba50fce961c36bee99fbbc05b8ab06dcbda5112d26d04a14f0320df572fdba9791f062d9cc7bd6cb25ad72f9de40f2dd8f231d5266efd3a4cce0636c308f033e
|
data/README.md
CHANGED
@@ -33,6 +33,7 @@ Features
|
|
33
33
|
|
34
34
|
- [Aggressively minimalistic][1], no dependencies, no monkey-patching, no magic.
|
35
35
|
- Settings are accessible through a globally available class.
|
36
|
+
- Can be used either as a singleton class or as an instance.
|
36
37
|
- Load and merge one or more YAML files or hashes.
|
37
38
|
- Settings objects are standard ruby hashes, arrays and basic types.
|
38
39
|
- Ability to update settings at runtime.
|
@@ -43,7 +44,7 @@ Nonfeatures
|
|
43
44
|
--------------------------------------------------
|
44
45
|
|
45
46
|
- No dot notation access to nested values - Use `Settings.server['host']`
|
46
|
-
instead of `Settings.server.host
|
47
|
+
instead of `Settings.server.host`.
|
47
48
|
- No special generators for Rails.
|
48
49
|
[Usage with rails is still trivial](#using-with-rails).
|
49
50
|
|
@@ -51,6 +52,8 @@ Nonfeatures
|
|
51
52
|
Usage
|
52
53
|
--------------------------------------------------
|
53
54
|
|
55
|
+
### Using as a singleton class
|
56
|
+
|
54
57
|
```ruby
|
55
58
|
require 'sting'
|
56
59
|
|
@@ -62,6 +65,11 @@ Settings = Sting
|
|
62
65
|
Settings << 'one'
|
63
66
|
Settings << 'two.yml'
|
64
67
|
|
68
|
+
# Adding additional files can also be done with `#push`. These two are the
|
69
|
+
# same.
|
70
|
+
Settings << 'one'
|
71
|
+
Settings.push 'one'
|
72
|
+
|
65
73
|
# Merge with another options hash
|
66
74
|
Settings << { port: 3000, host: 'localhost' }
|
67
75
|
|
@@ -92,6 +100,23 @@ Settings.port = 3000
|
|
92
100
|
Settings.reset!
|
93
101
|
```
|
94
102
|
|
103
|
+
### Using as an instance
|
104
|
+
|
105
|
+
All the above operations are also available to instances of `Sting`.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
require 'sting'
|
109
|
+
|
110
|
+
# Create an instance.
|
111
|
+
config = Sting.new
|
112
|
+
|
113
|
+
# Or, create an instance, and provide the first source file to it.
|
114
|
+
config = Sting.new 'settings'
|
115
|
+
|
116
|
+
# Load additional YAML files.
|
117
|
+
config << 'local_settings'
|
118
|
+
```
|
119
|
+
|
95
120
|
|
96
121
|
Using with Rails
|
97
122
|
--------------------------------------------------
|
@@ -122,4 +147,4 @@ Create four config files:
|
|
122
147
|
- config/settings/**test**.yml
|
123
148
|
|
124
149
|
|
125
|
-
[1]: https://github.com/DannyBen/sting/blob/master/lib/sting.rb
|
150
|
+
[1]: https://github.com/DannyBen/sting/blob/master/lib/sting/sting_operations.rb
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
class Sting
|
5
|
+
module StingOperations
|
6
|
+
def initialize(source = nil)
|
7
|
+
self << source if source
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(source)
|
11
|
+
if source.is_a? Hash
|
12
|
+
content = source.collect{ |k,v| [k.to_s, v] }.to_h
|
13
|
+
else
|
14
|
+
source = "#{source}.yml" unless source =~ /\.ya?ml$/
|
15
|
+
content = File.read source
|
16
|
+
content = YAML.load(ERB.new(content).result)
|
17
|
+
end
|
18
|
+
settings.merge! content if content
|
19
|
+
end
|
20
|
+
alias_method :push, :<<
|
21
|
+
|
22
|
+
def [](key)
|
23
|
+
settings[key.to_s]
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(name, *args, &blk)
|
27
|
+
name = name.to_s
|
28
|
+
return settings[name] if has_key? name
|
29
|
+
|
30
|
+
suffix = nil
|
31
|
+
|
32
|
+
if name.end_with? *['=', '!', '?']
|
33
|
+
suffix = name[-1]
|
34
|
+
name = name[0..-2]
|
35
|
+
end
|
36
|
+
|
37
|
+
case suffix
|
38
|
+
when "="
|
39
|
+
settings[name] = args.first
|
40
|
+
|
41
|
+
when "?"
|
42
|
+
!!settings[name]
|
43
|
+
|
44
|
+
when "!"
|
45
|
+
if has_key? name
|
46
|
+
return settings[name]
|
47
|
+
else
|
48
|
+
raise ArgumentError, "Key '#{name}' does not exist"
|
49
|
+
end
|
50
|
+
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def settings
|
59
|
+
@settings ||= {}
|
60
|
+
end
|
61
|
+
|
62
|
+
def reset!
|
63
|
+
@settings = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def has_key?(key)
|
67
|
+
settings.has_key? key.to_s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/sting/version.rb
CHANGED
data/lib/sting.rb
CHANGED
@@ -1,65 +1,11 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'erb'
|
3
|
+
require 'sting/sting_operations'
|
3
4
|
|
4
5
|
class Sting
|
5
|
-
|
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
|
14
|
-
settings.merge! content if content
|
15
|
-
end
|
16
|
-
|
17
|
-
def [](key)
|
18
|
-
settings[key.to_s]
|
19
|
-
end
|
20
|
-
|
21
|
-
def method_missing(name, *args, &blk)
|
22
|
-
name = name.to_s
|
23
|
-
return settings[name] if has_key? name
|
24
|
-
|
25
|
-
suffix = nil
|
26
|
-
|
27
|
-
if name.end_with? *['=', '!', '?']
|
28
|
-
suffix = name[-1]
|
29
|
-
name = name[0..-2]
|
30
|
-
end
|
31
|
-
|
32
|
-
case suffix
|
33
|
-
when "="
|
34
|
-
settings[name] = args.first
|
35
|
-
|
36
|
-
when "?"
|
37
|
-
!!settings[name]
|
6
|
+
include StingOperations
|
38
7
|
|
39
|
-
|
40
|
-
|
41
|
-
return settings[name]
|
42
|
-
else
|
43
|
-
raise ArgumentError, "Key '#{name}' does not exist"
|
44
|
-
end
|
45
|
-
|
46
|
-
else
|
47
|
-
nil
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
def settings
|
54
|
-
@settings ||= {}
|
55
|
-
end
|
56
|
-
|
57
|
-
def reset!
|
58
|
-
@settings = nil
|
59
|
-
end
|
60
|
-
|
61
|
-
def has_key?(key)
|
62
|
-
settings.has_key? key.to_s
|
63
|
-
end
|
8
|
+
class << self
|
9
|
+
include StingOperations
|
64
10
|
end
|
65
11
|
end
|
metadata
CHANGED
@@ -1,99 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: byebug
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '10.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '10.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.6'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec_fixtures
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.3'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.3'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: runfile
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.10'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.10'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: runfile-tasks
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.4'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.4'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: simplecov
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.15'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.15'
|
11
|
+
date: 2019-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
97
13
|
description: Minimal, lightweight, multi-YAML settings
|
98
14
|
email: db@dannyben.com
|
99
15
|
executables: []
|
@@ -102,6 +18,7 @@ extra_rdoc_files: []
|
|
102
18
|
files:
|
103
19
|
- README.md
|
104
20
|
- lib/sting.rb
|
21
|
+
- lib/sting/sting_operations.rb
|
105
22
|
- lib/sting/version.rb
|
106
23
|
homepage: https://github.com/dannyben/sting
|
107
24
|
licenses:
|