captain_config 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/LICENSE +25 -0
- data/README.md +68 -0
- data/captain_config.gemspec +50 -0
- data/lib/captain_config.rb +21 -0
- data/lib/captain_config/configured_entry.rb +20 -0
- data/lib/captain_config/middlewares/puma_middleware.rb +23 -0
- data/lib/captain_config/models/base_config.rb +7 -0
- data/lib/captain_config/models/boolean_config.rb +33 -0
- data/lib/captain_config/models/integer_config.rb +19 -0
- data/lib/captain_config/models/string_config.rb +15 -0
- data/lib/captain_config/service.rb +103 -0
- data/lib/captain_config/service/dsl.rb +33 -0
- data/lib/captain_config/version.rb +3 -0
- data/lib/generators/captain_config_generator.rb +13 -0
- data/lib/generators/templates/create_captain_configs.rb.tt +11 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5493e2fcb8ce58f2bc41f302ea1f4ffddffaa3b5ed47a140a0224e8b684d0ca
|
4
|
+
data.tar.gz: 1f01c90101896d6703b97fb98d48fce1fb69e8b1640bf1fa372194f9c9cfbecb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4877a1a5d325b23775c32fae6b48fd6462781aff286e4b06398d68b81d3f6eae541cd32e7fb5d7f22d5631b6e10e017f4a5a7ad7faf671e932aba803ccc1bdad
|
7
|
+
data.tar.gz: bf9d708d0e801b2dd39c2b975c06ea674a84be9d7a7317cf2ffde8b95d1159116f5ba496d31d2ba35827a3aa7e64d6445be7039555a16816dad9cae6305fe341
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at dirk@esherido.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2019, Dirk Gadsden
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
13
|
+
may be used to endorse or promote products derived from this software
|
14
|
+
without specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
17
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# CaptainConfig
|
2
|
+
|
3
|
+
`CaptainConfig` makes it easy to add developer-friendly configuration to control your application's behavior.
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
Add the gem to your application's Gemfile:
|
8
|
+
|
9
|
+
```rb
|
10
|
+
gem 'captain_config'
|
11
|
+
```
|
12
|
+
|
13
|
+
Run the generator to create the migration for the `captain_configs` table:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
bundle exec rails generate captain_config
|
17
|
+
```
|
18
|
+
|
19
|
+
**Not on Rails?** Check out the [template](https://github.com/dirk/captain_config/blob/master/lib/generators/templates/create_captain_configs.rb.tt) for the ActiveRecord migration that would have been generated; that describes how this gem expects that table to look.
|
20
|
+
|
21
|
+
Then—assuming you're using Rails—set up some configuration in your config:
|
22
|
+
|
23
|
+
```rb
|
24
|
+
# config/initializers/captain_config.rb
|
25
|
+
CONFIG = CaptainConfig::Service.new do
|
26
|
+
new_feature_enabled :boolean, default: false
|
27
|
+
important_user_points_threshold :integer, default: 9000
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Add the Puma middleware so that the configuration is reloaded out-of-band in between requests:
|
32
|
+
|
33
|
+
```rb
|
34
|
+
# config.ru
|
35
|
+
require_relative 'config/environment'
|
36
|
+
|
37
|
+
use CaptainConfig::PumaMiddleware
|
38
|
+
|
39
|
+
run Rails.application
|
40
|
+
```
|
41
|
+
|
42
|
+
Now you can read the configuration anywhere! The configuration will be reloaded in between requests, so reading it in your application is a fast hash lookup.
|
43
|
+
|
44
|
+
```rb
|
45
|
+
class User < Application
|
46
|
+
def met_threshold?
|
47
|
+
points >= CONFIG[:important_user_points_threshold]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
```erb
|
53
|
+
<% if CONFIG[:new_feature_enabled] %>
|
54
|
+
<%= link_to 'New Stuff!', new_feature_path %>
|
55
|
+
<% end >
|
56
|
+
```
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on [the GitHub repository](https://github.com/dirk/captain_config).
|
61
|
+
|
62
|
+
## Code of Conduct
|
63
|
+
|
64
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. Everyone interacting in the project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dirk/captain_config/blob/master/CODE_OF_CONDUCT.md).
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
Released under the Modified BSD license, see [LICENSE](LICENSE) for details.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "captain_config/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "captain_config"
|
7
|
+
spec.version = CaptainConfig::VERSION
|
8
|
+
spec.authors = ["Dirk Gadsden"]
|
9
|
+
spec.email = ["dirk@esherido.com"]
|
10
|
+
|
11
|
+
spec.summary = 'Fast, safe configuration for Ruby on Rails applications.'
|
12
|
+
spec.homepage = 'https://github.com/dirk/captain_config'
|
13
|
+
|
14
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
15
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
16
|
+
if spec.respond_to?(:metadata)
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/dirk/captain_config'
|
21
|
+
# spec.metadata['changelog_uri'] = 'TODO: Put your gem's CHANGELOG.md URL here.'
|
22
|
+
else
|
23
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
24
|
+
'public gem pushes.'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Specify which files should be added to the gem when it is released.
|
28
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
29
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
30
|
+
`git ls-files -z`.split("\x0").reject do |file|
|
31
|
+
file.match(%r{^(bin|spec)/}) ||
|
32
|
+
file.match(%r{^\.[.\w]+$}) ||
|
33
|
+
%[Gemfile Rakefile].include?(file)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
spec.bindir = "exe"
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ["lib"]
|
39
|
+
|
40
|
+
spec.add_dependency 'rails', '>= 4.0.0'
|
41
|
+
spec.add_dependency 'concurrent-ruby', '>= 1.0.0'
|
42
|
+
|
43
|
+
spec.add_development_dependency 'bundler', '>= 1.16'
|
44
|
+
spec.add_development_dependency 'httparty', '~> 0.16'
|
45
|
+
spec.add_development_dependency 'pry', '~> 0.12'
|
46
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
47
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
48
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
49
|
+
spec.add_development_dependency 'wait_for_it', '~> 0.2'
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/dependencies/autoload'
|
2
|
+
|
3
|
+
require 'captain_config/version'
|
4
|
+
|
5
|
+
module CaptainConfig
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
|
8
|
+
autoload :ConfiguredEntry
|
9
|
+
autoload :Service
|
10
|
+
|
11
|
+
autoload_under 'middlewares' do
|
12
|
+
autoload :PumaMiddleware
|
13
|
+
end
|
14
|
+
|
15
|
+
autoload_under 'models' do
|
16
|
+
autoload :BaseConfig
|
17
|
+
autoload :BooleanConfig
|
18
|
+
autoload :IntegerConfig
|
19
|
+
autoload :StringConfig
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CaptainConfig::ConfiguredEntry
|
2
|
+
attr_reader :key
|
3
|
+
# Class of the model (eg. `CaptainConfig::BooleanConfig`).
|
4
|
+
attr_reader :model
|
5
|
+
attr_accessor :default
|
6
|
+
|
7
|
+
def initialize(key, model)
|
8
|
+
@key = key
|
9
|
+
@model = model
|
10
|
+
@default = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_value
|
14
|
+
if default.respond_to?(:call)
|
15
|
+
default.call
|
16
|
+
else
|
17
|
+
default
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Using the `rack.after_reply` hook provided by Puma for running code after
|
2
|
+
# the response has been sent to the client.
|
3
|
+
class CaptainConfig::PumaMiddleware
|
4
|
+
RACK_AFTER_REPLY = ::Puma::Const::RACK_AFTER_REPLY
|
5
|
+
|
6
|
+
def initialize(app)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
service = CaptainConfig::Service.last_created_service
|
12
|
+
|
13
|
+
if service
|
14
|
+
# Load if it hasn't already been loaded (eg. first request).
|
15
|
+
service.load unless service.loaded?
|
16
|
+
|
17
|
+
# Then reload after every request.
|
18
|
+
env[RACK_AFTER_REPLY] << lambda { service.load }
|
19
|
+
end
|
20
|
+
|
21
|
+
@app.call env
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'captain_config/models/base_config'
|
2
|
+
|
3
|
+
class CaptainConfig::BooleanConfig < CaptainConfig::BaseConfig
|
4
|
+
def value
|
5
|
+
case self.text
|
6
|
+
when 'true'
|
7
|
+
true
|
8
|
+
when 'false'
|
9
|
+
false
|
10
|
+
else
|
11
|
+
raise "Invalid text: #{text.inspect}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def value=(new_value)
|
16
|
+
if new_value != true && new_value != false
|
17
|
+
raise ArgumentError.new("Invalid value: #{new_value.inspect}")
|
18
|
+
end
|
19
|
+
|
20
|
+
self.text = new_value.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.coerce(value)
|
24
|
+
case value
|
25
|
+
when 'true'
|
26
|
+
true
|
27
|
+
when 'false'
|
28
|
+
false
|
29
|
+
else
|
30
|
+
raise ArgumentError.new("Cannot coerce value: #{value.inspect}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'captain_config/models/base_config'
|
2
|
+
|
3
|
+
class CaptainConfig::IntegerConfig < CaptainConfig::BaseConfig
|
4
|
+
def value
|
5
|
+
Integer(self.text)
|
6
|
+
end
|
7
|
+
|
8
|
+
def value=(new_value)
|
9
|
+
unless new_value.is_a?(Integer)
|
10
|
+
raise ArgumentError.new("Invalid value: #{new_value.inspect}")
|
11
|
+
end
|
12
|
+
|
13
|
+
self.text = new_value.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.coerce(value)
|
17
|
+
Integer(value)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'captain_config/models/base_config'
|
2
|
+
|
3
|
+
class CaptainConfig::StringConfig < CaptainConfig::BaseConfig
|
4
|
+
def value
|
5
|
+
self.text
|
6
|
+
end
|
7
|
+
|
8
|
+
def value=(new_value)
|
9
|
+
self.text = new_value.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.coerce(value)
|
13
|
+
value.to_s
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
require 'concurrent/atomic/thread_local_var'
|
3
|
+
|
4
|
+
class CaptainConfig::Service
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
|
7
|
+
autoload :DSL
|
8
|
+
|
9
|
+
# The statically-defined entries that this service should support.
|
10
|
+
attr_reader :configured_entries
|
11
|
+
|
12
|
+
# The keys and values read from the database (or defaults).
|
13
|
+
attr_reader :configs
|
14
|
+
|
15
|
+
# Used by middlewares to automatically find the configuration service.
|
16
|
+
cattr_accessor :last_created_service,
|
17
|
+
instance_reader: false,
|
18
|
+
instance_writer: false
|
19
|
+
|
20
|
+
def initialize(load_after_initialize: true, &block)
|
21
|
+
@configured_entries = {}
|
22
|
+
@configs = Concurrent::ThreadLocalVar.new(nil)
|
23
|
+
|
24
|
+
DSL.new(self).instance_eval(&block)
|
25
|
+
|
26
|
+
# The last service to be initialized will always win.
|
27
|
+
self.class.last_created_service = self
|
28
|
+
|
29
|
+
# Make the service immediately available after it's declared.
|
30
|
+
load if load_after_initialize
|
31
|
+
end
|
32
|
+
|
33
|
+
def <<(configured_entry)
|
34
|
+
@configured_entries[configured_entry.key] = configured_entry
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(key)
|
38
|
+
assert_loaded!
|
39
|
+
|
40
|
+
configs.value.fetch key
|
41
|
+
end
|
42
|
+
|
43
|
+
def set(key, new_value, coerce: false)
|
44
|
+
assert_loaded!
|
45
|
+
|
46
|
+
record = configured_entries.fetch(key).model.find_or_create_by!(key: key)
|
47
|
+
record.value = coerce ? record.class.coerce(new_value) : new_value
|
48
|
+
record.save!
|
49
|
+
|
50
|
+
# Read the value back out of the record because the model/record
|
51
|
+
# is authoritative.
|
52
|
+
authoritative_new_value = record.value
|
53
|
+
configs.value[key] = authoritative_new_value
|
54
|
+
authoritative_new_value
|
55
|
+
end
|
56
|
+
|
57
|
+
alias_method :[], :get
|
58
|
+
alias_method :[]=, :set
|
59
|
+
|
60
|
+
def loaded?
|
61
|
+
!configs.value.nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
# Load new values from the database (or default values from the
|
65
|
+
# configured entries).
|
66
|
+
def load
|
67
|
+
new_configs = {}
|
68
|
+
|
69
|
+
records = CaptainConfig::BaseConfig
|
70
|
+
.where(key: configured_entries.keys)
|
71
|
+
.map { |record| [record.key.to_sym, record] }
|
72
|
+
.to_h
|
73
|
+
|
74
|
+
configured_entries.each do |key, configured_entry|
|
75
|
+
record = records[key]
|
76
|
+
|
77
|
+
value = if record
|
78
|
+
# Check that it's the type we're expecting.
|
79
|
+
actual = record.class
|
80
|
+
expected = configured_entry.model
|
81
|
+
if expected != actual
|
82
|
+
raise(
|
83
|
+
"Error loading #{key}: record class from database doesn't match " \
|
84
|
+
"configured class (expected: #{expected}, got: #{actual})",
|
85
|
+
)
|
86
|
+
end
|
87
|
+
record.value
|
88
|
+
else
|
89
|
+
configured_entry.default_value.dup
|
90
|
+
end
|
91
|
+
|
92
|
+
new_configs[key] = value
|
93
|
+
end
|
94
|
+
|
95
|
+
@configs.value = new_configs
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def assert_loaded!
|
101
|
+
raise 'Not loaded' unless loaded?
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'active_support/proxy_object'
|
2
|
+
|
3
|
+
class CaptainConfig::Service::DSL < ActiveSupport::ProxyObject
|
4
|
+
attr_reader :service
|
5
|
+
|
6
|
+
def initialize(service)
|
7
|
+
@service = service
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(key, *args)
|
11
|
+
type, opts, *_rest = args
|
12
|
+
|
13
|
+
model = case type
|
14
|
+
when :boolean
|
15
|
+
::CaptainConfig::BooleanConfig
|
16
|
+
when :integer
|
17
|
+
::CaptainConfig::IntegerConfig
|
18
|
+
when :string
|
19
|
+
::CaptainConfig::StringConfig
|
20
|
+
else
|
21
|
+
raise ArgumentError.new("Unrecognized type: #{type.inspect}")
|
22
|
+
end
|
23
|
+
|
24
|
+
entry = ::CaptainConfig::ConfiguredEntry.new(key, model)
|
25
|
+
if opts
|
26
|
+
opts.each do |opt, value|
|
27
|
+
entry.send("#{opt}=", value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
service << entry
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators/active_record/migration'
|
2
|
+
|
3
|
+
class CaptainConfigGenerator < Rails::Generators::Base
|
4
|
+
include ActiveRecord::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
desc "Creates the migration for the `captain_configs' table."
|
9
|
+
|
10
|
+
def create_captain_configs_migration
|
11
|
+
migration_template 'create_captain_configs.rb.tt', "#{db_migrate_path}/create_captain_configs.rb"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateCaptainConfigs < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
2
|
+
def change
|
3
|
+
create_table :captain_configs do |t|
|
4
|
+
t.string :type, null: false
|
5
|
+
t.string :key, null: false
|
6
|
+
t.text :text
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: captain_config
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dirk Gadsden
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: concurrent-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.12'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.3'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: wait_for_it
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.2'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.2'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- dirk@esherido.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- CODE_OF_CONDUCT.md
|
147
|
+
- LICENSE
|
148
|
+
- README.md
|
149
|
+
- captain_config.gemspec
|
150
|
+
- lib/captain_config.rb
|
151
|
+
- lib/captain_config/configured_entry.rb
|
152
|
+
- lib/captain_config/middlewares/puma_middleware.rb
|
153
|
+
- lib/captain_config/models/base_config.rb
|
154
|
+
- lib/captain_config/models/boolean_config.rb
|
155
|
+
- lib/captain_config/models/integer_config.rb
|
156
|
+
- lib/captain_config/models/string_config.rb
|
157
|
+
- lib/captain_config/service.rb
|
158
|
+
- lib/captain_config/service/dsl.rb
|
159
|
+
- lib/captain_config/version.rb
|
160
|
+
- lib/generators/captain_config_generator.rb
|
161
|
+
- lib/generators/templates/create_captain_configs.rb.tt
|
162
|
+
homepage: https://github.com/dirk/captain_config
|
163
|
+
licenses: []
|
164
|
+
metadata:
|
165
|
+
allowed_push_host: https://rubygems.org
|
166
|
+
homepage_uri: https://github.com/dirk/captain_config
|
167
|
+
source_code_uri: https://github.com/dirk/captain_config
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
requirements: []
|
183
|
+
rubygems_version: 3.0.3
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: Fast, safe configuration for Ruby on Rails applications.
|
187
|
+
test_files: []
|