lita_dotenv 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -22
- data/lib/lita_dotenv/loader.rb +40 -37
- data/lib/lita_dotenv.rb +1 -1
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b275d80993a1353fc6d49c7033642e6105b50cd
|
4
|
+
data.tar.gz: 0970e10281aca86f22b4637c3b5b002418bb2e9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7438de4c3bdf3f2704c93e9cbc7fbcae84ae9240142d8afd6c3e41afdf7d38150d17dc8a1dedcfe9645e64c1098fc46cf687059f7528fa8a833a9dfc55cbcb1b
|
7
|
+
data.tar.gz: 8fb03aa330283f9bc793c1d7c243003cade39ced8eacd161cc5fad17fbfe5e7595b8b46ff4706f62161e722b8dc9ab5f461c915cd3639784bde4813ebc841520
|
data/README.md
CHANGED
@@ -9,14 +9,22 @@ Lita Dotenv Config Loader
|
|
9
9
|
[![Docs][docs-rubydoc-svg]][docs-rubydoc-link]
|
10
10
|
[![License][license-svg]][license-link]
|
11
11
|
|
12
|
-
`
|
12
|
+
`lita_dotenv` is designed to allow storing an entire [Lita bot](https://www.lita.io/) config in an `.env` file. The `lita_config.rb` file should be as simple as:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'lita_dotenv'
|
16
|
+
|
17
|
+
Lita.configure do |config|
|
18
|
+
config = LitaDotenv.new(config).config
|
19
|
+
end
|
20
|
+
```
|
13
21
|
|
14
22
|
## Installation
|
15
23
|
|
16
|
-
Add `
|
24
|
+
Add `lita_dotenv` to your Lita instance's Gemfile:
|
17
25
|
|
18
26
|
``` ruby
|
19
|
-
gem "
|
27
|
+
gem "lita_dotenv"
|
20
28
|
```
|
21
29
|
|
22
30
|
## Configuration
|
@@ -28,10 +36,12 @@ gem "lita-dotenv_config"
|
|
28
36
|
1. all paths begin with `LITA_`
|
29
37
|
2. all paths are designed to match Lita configure paths
|
30
38
|
3. optional type coercion is available by setting the type as a suffix:
|
31
|
-
1. Symbol: __TYPESYM
|
32
|
-
2. Boolean: __TYPEBOOL
|
33
|
-
3. Integer: __TYPEINT
|
34
|
-
4.
|
39
|
+
1. Symbol: `__TYPESYM`
|
40
|
+
2. Boolean: `__TYPEBOOL`
|
41
|
+
3. Integer: `__TYPEINT`
|
42
|
+
4. JSON: `__TYPEJSON`
|
43
|
+
5. JSON with symbole keys: `__TYPEJSONSYM`
|
44
|
+
4. underscores are handled in paths by using camelCase starting with a lowercase letter where an underscore is inserted before each uppercase letter
|
35
45
|
|
36
46
|
```
|
37
47
|
LITA_ROBOT_NAME=Configbot # config.robot.name = 'Configbot'
|
@@ -41,9 +51,13 @@ LITA_ROBOT_logLevel__TYPESYM=info # config.robot.log_level = :info
|
|
41
51
|
|
42
52
|
### lita_config.rb
|
43
53
|
|
54
|
+
In the ideal case, the `lita_config.rb` file should be as simple as:
|
55
|
+
|
44
56
|
```ruby
|
57
|
+
require 'lita_dotenv'
|
58
|
+
|
45
59
|
Lita.configure do |config|
|
46
|
-
config =
|
60
|
+
config = LitaDotenv.new(config).config
|
47
61
|
end
|
48
62
|
```
|
49
63
|
|
@@ -55,7 +69,7 @@ See [CHANGELOG.md](CHANGELOG.md)
|
|
55
69
|
|
56
70
|
Project Repo
|
57
71
|
|
58
|
-
* https://github.com/grokify/
|
72
|
+
* https://github.com/grokify/lita_dotenv
|
59
73
|
|
60
74
|
Lita
|
61
75
|
|
@@ -63,7 +77,7 @@ Lita
|
|
63
77
|
|
64
78
|
## Contributing
|
65
79
|
|
66
|
-
1. Fork it ( http://github.com/grokify/
|
80
|
+
1. Fork it ( http://github.com/grokify/lita_dotenv/fork )
|
67
81
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
82
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
83
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -75,17 +89,17 @@ Lita Dotenv Config Loader is available under the MIT license. See [LICENSE.txt](
|
|
75
89
|
|
76
90
|
Lita Dotenv Config Loader © 2016 by John Wang
|
77
91
|
|
78
|
-
[gem-version-svg]: https://badge.fury.io/rb/
|
79
|
-
[gem-version-link]: http://badge.fury.io/rb/
|
80
|
-
[downloads-svg]: http://ruby-gem-downloads-badge.herokuapp.com/
|
81
|
-
[downloads-link]: https://rubygems.org/gems/
|
82
|
-
[dependency-status-svg]: https://gemnasium.com/grokify/
|
83
|
-
[dependency-status-link]: https://gemnasium.com/grokify/
|
84
|
-
[codeclimate-status-svg]: https://codeclimate.com/github/grokify/
|
85
|
-
[codeclimate-status-link]: https://codeclimate.com/github/grokify/
|
86
|
-
[scrutinizer-status-svg]: https://scrutinizer-ci.com/g/grokify/
|
87
|
-
[scrutinizer-status-link]: https://scrutinizer-ci.com/g/grokify/
|
92
|
+
[gem-version-svg]: https://badge.fury.io/rb/lita_dotenv.svg
|
93
|
+
[gem-version-link]: http://badge.fury.io/rb/lita_dotenv
|
94
|
+
[downloads-svg]: http://ruby-gem-downloads-badge.herokuapp.com/lita_dotenv
|
95
|
+
[downloads-link]: https://rubygems.org/gems/lita_dotenv
|
96
|
+
[dependency-status-svg]: https://gemnasium.com/grokify/lita_dotenv.svg
|
97
|
+
[dependency-status-link]: https://gemnasium.com/grokify/lita_dotenv
|
98
|
+
[codeclimate-status-svg]: https://codeclimate.com/github/grokify/lita_dotenv/badges/gpa.svg
|
99
|
+
[codeclimate-status-link]: https://codeclimate.com/github/grokify/lita_dotenv
|
100
|
+
[scrutinizer-status-svg]: https://scrutinizer-ci.com/g/grokify/lita_dotenv/badges/quality-score.png?b=master
|
101
|
+
[scrutinizer-status-link]: https://scrutinizer-ci.com/g/grokify/lita_dotenv/?branch=master
|
88
102
|
[docs-rubydoc-svg]: https://img.shields.io/badge/docs-rubydoc-blue.svg
|
89
|
-
[docs-rubydoc-link]: http://www.rubydoc.info/gems/
|
103
|
+
[docs-rubydoc-link]: http://www.rubydoc.info/gems/lita_dotenv/
|
90
104
|
[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
|
91
|
-
[license-link]: https://github.com/grokify/
|
105
|
+
[license-link]: https://github.com/grokify/lita_dotenv/blob/master/LICENSE.txt
|
data/lib/lita_dotenv/loader.rb
CHANGED
@@ -1,49 +1,52 @@
|
|
1
1
|
require 'dotenv'
|
2
|
+
require 'multi_json'
|
2
3
|
|
3
4
|
module LitaDotenv
|
4
5
|
class Loader
|
5
|
-
|
6
|
+
attr_accessor :config
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def config_env
|
14
|
-
ENV.keys.grep(/^LITA_/i) do |key|
|
15
|
-
val = ENV[key]
|
16
|
-
slugs = key.split('__')
|
17
|
-
|
18
|
-
# Convert value types
|
19
|
-
if slugs.length==2
|
20
|
-
type = slugs[1].downcase
|
21
|
-
if type=='typesym'
|
22
|
-
val = val.to_sym
|
23
|
-
elsif type == 'typebool'
|
24
|
-
val = val.downcase == 'true' ? true : false
|
25
|
-
elsif type == 'typeint' && type =~ /^s*[0-9]+\s*$/
|
26
|
-
val = val.to_i
|
27
|
-
end
|
28
|
-
end
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
Dotenv.load
|
11
|
+
config_env
|
12
|
+
end
|
29
13
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
14
|
+
def config_env
|
15
|
+
ENV.keys.grep(/^LITA_/i) do |key|
|
16
|
+
val = ENV[key]
|
17
|
+
slugs = key.split('__')
|
18
|
+
# Convert value types
|
19
|
+
if slugs.length==2
|
20
|
+
type = slugs[1].downcase
|
21
|
+
if type=='typesym'
|
22
|
+
val = val.to_sym
|
23
|
+
elsif type == 'typebool'
|
24
|
+
val = val.downcase == 'true' ? true : false
|
25
|
+
elsif type == 'typeint' && type =~ /^s*[0-9]+\s*$/
|
26
|
+
val = val.to_i
|
27
|
+
elsif type == 'typejson'
|
28
|
+
val = MultiJson.decode val
|
29
|
+
elsif type == 'typejsonsym'
|
30
|
+
val = MultiJson.decode val, symbolize_keys: true
|
38
31
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
end
|
33
|
+
# Convert path
|
34
|
+
path = slugs[0].split('_')
|
35
|
+
path.shift # Remove LITA prefix
|
36
|
+
path.each_with_index do |part, i|
|
37
|
+
if part =~ /[a-z]/
|
38
|
+
path[i] = part.gsub(/([A-Z])/, '_\1')
|
45
39
|
end
|
40
|
+
path[i].downcase!
|
41
|
+
end
|
42
|
+
if path.length == 2
|
43
|
+
@config.send(path[0]).send("#{path[1]}=",val)
|
44
|
+
elsif path.length == 3
|
45
|
+
@config.send(path[0]).send(path[1]).send("#{path[2]}=",val)
|
46
|
+
else
|
47
|
+
raise "Config path length #{path.length} not supported for #{path.join('.')}."
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
51
|
+
end
|
49
52
|
end
|
data/lib/lita_dotenv.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita_dotenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wang
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 3.0.0
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 3.0.0
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: simplecov
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|