mysticonfig 0.0.1 → 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 +4 -4
- data/README.md +26 -0
- data/lib/mysticonfig.rb +11 -5
- data/lib/mysticonfig/utils.rb +1 -1
- data/lib/mysticonfig/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: 20e1e44f2df29f68de88c7a553a10b761b8528451217636d8ffa7c9f01c04e2a
|
4
|
+
data.tar.gz: 359a08038b71b236b6b4d35ef1e841937fa29c25c8e7e3e446c9f1ec8d57b5ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 378f5488068ed8b63276cb41b81105feaef7e7747b6bab14e6e2c0a738a1dae8def0cda9b345ba989edbb22364cd40ac0852d5d579fc64b36259edbfeed1796e
|
7
|
+
data.tar.gz: 6f9853d8f2ba64230eb75f2c798bf404c046fdd708d421c3f0516f1cfd42bc7fdf28245ee05828142d4e480c4a7405d80827184b971e7f76f36dc54867186797
|
data/README.md
CHANGED
@@ -12,6 +12,9 @@
|
|
12
12
|
|
13
13
|
A library to load `.appnamerc`, `.appnamerc.json` or `.appnamerc.yaml` config file easily.
|
14
14
|
|
15
|
+
`mysticonfig` will lookup for your config file.
|
16
|
+
It keeps traversing up until it **finds the config file** or **reaches your home directory**.
|
17
|
+
|
15
18
|
> Gem's name inspired by [cosmiconfig](https://github.com/davidtheclark/cosmiconfig)
|
16
19
|
|
17
20
|
## Installation
|
@@ -22,6 +25,8 @@ gem install mysticonfig
|
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
28
|
+
### Normal
|
29
|
+
|
25
30
|
```ruby
|
26
31
|
require 'mysticonfig'
|
27
32
|
|
@@ -30,3 +35,24 @@ config = loader.load # Automatically detect and load config
|
|
30
35
|
json_config = loader.load_json # Only load config from JSON file
|
31
36
|
yaml_config = loader.load_yaml # Only load config from YAML file (.yaml or .yml)
|
32
37
|
```
|
38
|
+
|
39
|
+
### With default config fallback
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'mysticonfig'
|
43
|
+
|
44
|
+
DEFAULT_CONFIG = {
|
45
|
+
'a' => 'A',
|
46
|
+
'b' => 'B',
|
47
|
+
'c' => 'C'
|
48
|
+
}
|
49
|
+
|
50
|
+
loader = Mysticonfig::Loader.new('appname', DEFAULT_CONFIG)
|
51
|
+
config = loader.load # Automatically detect and load config
|
52
|
+
json_config = loader.load_json # Only load config from JSON file
|
53
|
+
yaml_config = loader.load_yaml # Only load config from YAML file (.yaml or .yml)
|
54
|
+
```
|
55
|
+
|
56
|
+
## Documentation
|
57
|
+
|
58
|
+
See https://gluons.github.io/mysticonfig/
|
data/lib/mysticonfig.rb
CHANGED
@@ -6,8 +6,9 @@ module Mysticonfig
|
|
6
6
|
##
|
7
7
|
# Configuration loader.
|
8
8
|
class Loader
|
9
|
-
def initialize(appname)
|
9
|
+
def initialize(appname, default_config = {})
|
10
10
|
@filenames = Utils.generate_config_filenames appname
|
11
|
+
@default_config = default_config
|
11
12
|
end
|
12
13
|
|
13
14
|
##
|
@@ -15,7 +16,8 @@ module Mysticonfig
|
|
15
16
|
def load
|
16
17
|
config_file = find_file @filenames
|
17
18
|
|
18
|
-
Utils.load_auto config_file
|
19
|
+
config = Utils.load_auto config_file
|
20
|
+
config.empty? ? @default_config : @default_config.merge(config)
|
19
21
|
end
|
20
22
|
|
21
23
|
##
|
@@ -23,7 +25,8 @@ module Mysticonfig
|
|
23
25
|
def load_json
|
24
26
|
json_config_file = Utils.lookup_file @filenames[:json]
|
25
27
|
|
26
|
-
Utils.load_json json_config_file
|
28
|
+
config = Utils.load_json json_config_file
|
29
|
+
config.empty? ? @default_config : @default_config.merge(config)
|
27
30
|
end
|
28
31
|
|
29
32
|
##
|
@@ -34,10 +37,13 @@ module Mysticonfig
|
|
34
37
|
|
35
38
|
yaml_config_files.each do |file|
|
36
39
|
yaml_config_file = Utils.lookup_file file
|
37
|
-
|
40
|
+
unless yaml_config_file.nil?
|
41
|
+
config = Utils.load_yaml(yaml_config_file)
|
42
|
+
return config.empty? ? @default_config : @default_config.merge(config)
|
43
|
+
end
|
38
44
|
end
|
39
45
|
|
40
|
-
|
46
|
+
@default_config # Return default config when can't load config file
|
41
47
|
end
|
42
48
|
|
43
49
|
private
|
data/lib/mysticonfig/utils.rb
CHANGED
data/lib/mysticonfig/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysticonfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Saran Tanpituckpong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|