Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5e99edf
Showing
12 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
languages: | ||
Ruby: true | ||
JavaScript: false | ||
PHP: false | ||
Python: false | ||
engines: | ||
rubocop: | ||
enabled: true | ||
ratings: | ||
paths: | ||
- "**.rb" | ||
exclude_paths: | ||
- docs/**/* | ||
- scripts/**/* | ||
- test/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
*.env | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp | ||
lita_config.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'coveralls' | ||
|
||
SimpleCov.formatter = Coveralls::SimpleCov::Formatter | ||
SimpleCov.start do | ||
add_filter "/test/" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: ruby | ||
sudo: false | ||
cache: bundler | ||
rvm: | ||
- 2.3.1 | ||
- 2.2.2 | ||
script: bundle exec rspec | ||
before_install: | ||
- gem update --system | ||
- gem update bundler | ||
services: | ||
- redis-server | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CHANGELOG | ||
--------- | ||
- **0.0.1** - 2016-09-02 | ||
- Initial commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 John Wang | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
Lita Dotenv Config Loader | ||
========================= | ||
|
||
[![Gem Version][gem-version-svg]][gem-version-link] | ||
[![Dependency Status][dependency-status-svg]][dependency-status-link] | ||
[![Code Climate][codeclimate-status-svg]][codeclimate-status-link] | ||
[![Scrutinizer Code Quality][scrutinizer-status-svg]][scrutinizer-status-link] | ||
[![Downloads][downloads-svg]][downloads-link] | ||
[![Docs][docs-rubydoc-svg]][docs-rubydoc-link] | ||
[![License][license-svg]][license-link] | ||
|
||
`lita_dotenv` is designed to allow storing an entire [Lita bot](https://www.lita.io/)config in an `.env` file. | ||
|
||
## Installation | ||
|
||
Add `lita_dotenv` to your Lita instance's Gemfile: | ||
|
||
``` ruby | ||
gem "lita_dotenv" | ||
``` | ||
|
||
## Configuration | ||
|
||
### .env | ||
|
||
`DotenvConfig` uses a simple parser that follows the following rules for assigning ENV variable names to Lita paths: | ||
|
||
1. all paths begin with `LITA_` | ||
2. all paths are designed to match Lita configure paths | ||
3. optional type coercion is available by setting the type as a suffix: | ||
1. Symbol: `__TYPESYM` | ||
2. Boolean: `__TYPEBOOL` | ||
3. Integer: `__TYPEINT` | ||
4. JSON: `__TYPEJSON` | ||
5. JSON with symbole keys: `__TYPEJSONSYM` | ||
4. underscores are handled in paths by using camelCase starting with a lowercase letter where an underscore is inserted before each uppercase letter | ||
|
||
``` | ||
LITA_ROBOT_NAME=Configbot # config.robot.name = 'Configbot' | ||
LITA_ROBOT_LOCALE__TYPESYM=en # config.robot.locale = :en | ||
LITA_ROBOT_logLevel__TYPESYM=info # config.robot.log_level = :info | ||
``` | ||
|
||
### lita_config.rb | ||
|
||
```ruby | ||
Lita.configure do |config| | ||
config = Lita::Extensions::DotenvConfig.new(config).config | ||
end | ||
``` | ||
|
||
## Change Log | ||
|
||
See [CHANGELOG.md](CHANGELOG.md) | ||
|
||
## Links | ||
|
||
Project Repo | ||
|
||
* https://github.com/grokify/lita_dotenv | ||
|
||
Lita | ||
|
||
* https://www.lita.io/ | ||
|
||
## Contributing | ||
|
||
1. Fork it ( http://github.com/grokify/lita_dotenv/fork ) | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request | ||
|
||
## License | ||
|
||
Lita Dotenv Config Loader is available under the MIT license. See [LICENSE.txt](LICENSE.txt) for details. | ||
|
||
Lita Dotenv Config Loader © 2016 by John Wang | ||
|
||
[gem-version-svg]: https://badge.fury.io/rb/lita_dotenv.svg | ||
[gem-version-link]: http://badge.fury.io/rb/lita_dotenv | ||
[downloads-svg]: http://ruby-gem-downloads-badge.herokuapp.com/lita_dotenv | ||
[downloads-link]: https://rubygems.org/gems/lita_dotenv | ||
[dependency-status-svg]: https://gemnasium.com/grokify/lita_dotenv.svg | ||
[dependency-status-link]: https://gemnasium.com/grokify/lita_dotenv | ||
[codeclimate-status-svg]: https://codeclimate.com/github/grokify/lita_dotenv/badges/gpa.svg | ||
[codeclimate-status-link]: https://codeclimate.com/github/grokify/lita_dotenv | ||
[scrutinizer-status-svg]: https://scrutinizer-ci.com/g/grokify/lita_dotenv/badges/quality-score.png?b=master | ||
[scrutinizer-status-link]: https://scrutinizer-ci.com/g/grokify/lita_dotenv/?branch=master | ||
[docs-rubydoc-svg]: https://img.shields.io/badge/docs-rubydoc-blue.svg | ||
[docs-rubydoc-link]: http://www.rubydoc.info/gems/lita_dotenv/ | ||
[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg | ||
[license-link]: https://github.com/grokify/lita_dotenv/blob/master/LICENSE.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module LitaDotenv | ||
VERSION = '0.0.1' | ||
|
||
autoload :Loader, 'lita_dotenv/loader' | ||
|
||
class << self | ||
def new(config) | ||
LitaDotenv::Loader.new config | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'dotenv' | ||
require 'multi_json' | ||
|
||
module LitaDotenv | ||
class Loader | ||
attr_accessor :config | ||
|
||
def initialize(config) | ||
@config = config | ||
Dotenv.load | ||
config_env | ||
end | ||
|
||
def config_env | ||
ENV.keys.grep(/^LITA_/i) do |key| | ||
val = ENV[key] | ||
slugs = key.split('__') | ||
# Convert value types | ||
if slugs.length==2 | ||
type = slugs[1].downcase | ||
if type=='typesym' | ||
val = val.to_sym | ||
elsif type == 'typebool' | ||
val = val.downcase == 'true' ? true : false | ||
elsif type == 'typeint' && type =~ /^s*[0-9]+\s*$/ | ||
val = val.to_i | ||
elsif type == 'typejson' | ||
val = MultiJson.decode val | ||
elsif type == 'typejsonsym' | ||
val = MultiJson.decode val, symbolize_keys: true | ||
end | ||
end | ||
# Convert path | ||
path = slugs[0].split('_') | ||
path.shift # Remove LITA prefix | ||
path.each_with_index do |part, i| | ||
if part =~ /[a-z]/ | ||
path[i] = part.gsub(/([A-Z])/, '_\1') | ||
end | ||
path[i].downcase! | ||
end | ||
if path.length == 2 | ||
@config.send(path[0]).send("#{path[1]}=",val) | ||
elsif path.length == 3 | ||
@config.send(path[0]).send(path[1]).send("#{path[2]}=",val) | ||
else | ||
raise "Config path length #{path.length} not supported for #{path.join('.')}." | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Gem::Specification.new do |spec| | ||
spec.name = 'lita_dotenv' | ||
spec.date = '2016-09-02' | ||
spec.version = '0.0.1' | ||
spec.authors = ['John Wang'] | ||
spec.email = ['johncwang@gmail.com'] | ||
spec.description = %q{A Lita .env config loader.} | ||
spec.summary = %q{A Lita .env config loader that loads ENV values directly into Lita's configuration.} | ||
spec.homepage = 'https://github.com/grokify/lita-dotenv_config' | ||
spec.license = 'MIT' | ||
|
||
spec.files = Dir['lib/**/**/*'] | ||
spec.files += Dir['[A-Z]*'] + Dir['test/**/*'] | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_runtime_dependency 'dotenv', '>= 2.1.1' | ||
spec.add_runtime_dependency 'lita', '>= 4.4.3' | ||
|
||
spec.add_development_dependency 'bundler', '~> 1.3' | ||
spec.add_development_dependency 'rack-test' | ||
spec.add_development_dependency 'rake' | ||
spec.add_development_dependency 'simplecov', '>= 0.9.2' | ||
spec.add_development_dependency 'coveralls' | ||
end |