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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87394108708b354c9bfc2573e9ac4a6e3a7478ee
4
- data.tar.gz: 15b7cba8cbaecedc1e4312de1031cc0750a5c060
3
+ metadata.gz: 9b275d80993a1353fc6d49c7033642e6105b50cd
4
+ data.tar.gz: 0970e10281aca86f22b4637c3b5b002418bb2e9c
5
5
  SHA512:
6
- metadata.gz: 3c0875868a1e45494736f4936d61952e3fc31cc7f95808c93f796161d23d0ed63868dc623fd1d7aa91a4ae220b155e416df15778d5e7e6172fbb1ce03eabd9c4
7
- data.tar.gz: f71a86d5370df3943aa04e89c6e4114117cc91b54666639eb999f6d533bcffb5ba72e1b9547d263659a1bdcd09e3fa985edd64fe0315ee9a16d57d7ee829360d
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
- `lita-dotenv_config` is `.env` config loader for [Lita](https://www.lita.io/).
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 `lita-dotenv_config` to your Lita instance's Gemfile:
24
+ Add `lita_dotenv` to your Lita instance's Gemfile:
17
25
 
18
26
  ``` ruby
19
- gem "lita-dotenv_config"
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. underscores are handled in paths by using camelCase
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 = Lita::Extensions::DotenvConfig.new(config).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/lita-dotenv_config
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/lita-dotenv_config/fork )
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/lita-dotenv_config.svg
79
- [gem-version-link]: http://badge.fury.io/rb/lita-dotenv_config
80
- [downloads-svg]: http://ruby-gem-downloads-badge.herokuapp.com/lita-dotenv_config
81
- [downloads-link]: https://rubygems.org/gems/lita-dotenv_config
82
- [dependency-status-svg]: https://gemnasium.com/grokify/lita-dotenv_config.svg
83
- [dependency-status-link]: https://gemnasium.com/grokify/lita-dotenv_config
84
- [codeclimate-status-svg]: https://codeclimate.com/github/grokify/lita-dotenv_config/badges/gpa.svg
85
- [codeclimate-status-link]: https://codeclimate.com/github/grokify/lita-dotenv_config
86
- [scrutinizer-status-svg]: https://scrutinizer-ci.com/g/grokify/lita-dotenv_config/badges/quality-score.png?b=master
87
- [scrutinizer-status-link]: https://scrutinizer-ci.com/g/grokify/lita-dotenv_config/?branch=master
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/lita-dotenv_config/
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/lita-dotenv_config/blob/master/LICENSE.txt
105
+ [license-link]: https://github.com/grokify/lita_dotenv/blob/master/LICENSE.txt
@@ -1,49 +1,52 @@
1
1
  require 'dotenv'
2
+ require 'multi_json'
2
3
 
3
4
  module LitaDotenv
4
5
  class Loader
5
- attr_accessor :config
6
+ attr_accessor :config
6
7
 
7
- def initialize(config)
8
- @config = config
9
- Dotenv.load
10
- config_env
11
- end
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
- # Convert path
31
- path = slugs[0].split('_')
32
- path.shift # Remove LITA prefix
33
- path.each_with_index do |part, i|
34
- if part =~ /[a-z]/
35
- path[i] = part.gsub(/([A-Z])/, '_\1')
36
- end
37
- path[i].downcase!
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
- if path.length == 2
40
- @config.send(path[0]).send("#{path[1]}=",val)
41
- elsif path.length == 3
42
- @config.send(path[0]).send(path[1]).send("#{path[2]}=",val)
43
- else
44
- raise "Config path length #{path.length} not supported for #{path.join('.')}."
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
@@ -1,5 +1,5 @@
1
1
  module LitaDotenv
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
 
4
4
  autoload :Loader, 'lita_dotenv/loader'
5
5
 
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.1
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