dry-configurable 0.9.0 → 0.11.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -21
  3. data/LICENSE +1 -1
  4. data/README.md +15 -27
  5. data/dry-configurable.gemspec +27 -18
  6. data/lib/dry-configurable.rb +2 -0
  7. data/lib/dry/configurable.rb +21 -146
  8. data/lib/dry/configurable/class_methods.rb +103 -0
  9. data/lib/dry/configurable/compiler.rb +45 -0
  10. data/lib/dry/configurable/config.rb +79 -136
  11. data/lib/dry/configurable/constants.rb +12 -0
  12. data/lib/dry/configurable/dsl.rb +62 -0
  13. data/lib/dry/configurable/dsl/args.rb +58 -0
  14. data/lib/dry/configurable/{error.rb → errors.rb} +5 -1
  15. data/lib/dry/configurable/instance_methods.rb +46 -0
  16. data/lib/dry/configurable/methods.rb +32 -0
  17. data/lib/dry/configurable/setting.rb +91 -17
  18. data/lib/dry/configurable/settings.rb +42 -87
  19. data/lib/dry/configurable/test_interface.rb +3 -5
  20. data/lib/dry/configurable/version.rb +3 -1
  21. metadata +30 -25
  22. data/.codeclimate.yml +0 -12
  23. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
  24. data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -34
  25. data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
  26. data/.github/workflows/ci.yml +0 -70
  27. data/.github/workflows/docsite.yml +0 -34
  28. data/.github/workflows/sync_configs.yml +0 -30
  29. data/.gitignore +0 -9
  30. data/.rspec +0 -4
  31. data/.rubocop.yml +0 -89
  32. data/CODE_OF_CONDUCT.md +0 -13
  33. data/CONTRIBUTING.md +0 -29
  34. data/Gemfile +0 -20
  35. data/Rakefile +0 -12
  36. data/docsite/source/index.html.md +0 -55
  37. data/docsite/source/testing.html.md +0 -27
  38. data/lib/dry/configurable/settings/argument_parser.rb +0 -50
  39. data/rakelib/rubocop.rake +0 -18
data/CODE_OF_CONDUCT.md DELETED
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.4.0, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct)
data/CONTRIBUTING.md DELETED
@@ -1,29 +0,0 @@
1
- # Issue Guidelines
2
-
3
- ## Reporting bugs
4
-
5
- If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
6
-
7
- ## Reporting feature requests
8
-
9
- Report a feature request **only after discussing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discussion thread, and instead summarize what was discussed.
10
-
11
- ## Reporting questions, support requests, ideas, concerns etc.
12
-
13
- **PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
14
-
15
- # Pull Request Guidelines
16
-
17
- A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
18
-
19
- Other requirements:
20
-
21
- 1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
22
- 2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
23
- 3) Add API documentation if it's a new feature
24
- 4) Update API documentation if it changes an existing feature
25
- 5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
26
-
27
- # Asking for help
28
-
29
- If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org) or join [our chat](https://dry-rb.zulipchat.com).
data/Gemfile DELETED
@@ -1,20 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :test do
6
- platforms :mri do
7
- gem 'codeclimate-test-reporter', require: false
8
- gem 'simplecov', require: false
9
- end
10
-
11
- gem 'warning'
12
- end
13
-
14
- group :tools do
15
- gem 'guard'
16
- gem 'guard-rspec'
17
- gem 'listen', '3.0.6'
18
- gem 'pry-byebug', platform: :mri
19
- gem "ossy", git: "https://github.com/solnic/ossy.git", branch: "master"
20
- end
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
-
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
5
-
6
- require 'rspec/core'
7
- require 'rspec/core/rake_task'
8
-
9
- task default: :spec
10
-
11
- desc 'Run all specs in spec directory'
12
- RSpec::Core::RakeTask.new(:spec)
@@ -1,55 +0,0 @@
1
- ---
2
- title: Introduction & Usage
3
- description: Thread-safe configuration mixin
4
- layout: gem-single
5
- order: 7
6
- type: gem
7
- name: dry-configurable
8
- sections:
9
- - testing
10
- ---
11
-
12
- ### Introduction
13
-
14
- `dry-configurable` is a simple mixin to add thread-safe configuration behaviour to your classes. There are many libraries that make use of configuration, and each seemed to have their own implementation with a similar or duplicate interface, so we thought it was strange that this behaviour had not already been encapsulated into a reusable gem, hence `dry-configurable` was born.
15
-
16
- ### Usage
17
-
18
- `dry-configurable` is extremely simple to use, just extend the mixin and use the `setting` macro to add configuration options:
19
-
20
- ```ruby
21
- class App
22
- extend Dry::Configurable
23
-
24
- # Pass a block for nested configuration (works to any depth)
25
- setting :database do
26
- # Can pass a default value
27
- setting :dsn, 'sqlite:memory'
28
- end
29
- # Defaults to nil if no default value is given
30
- setting :adapter
31
- # Pre-process values
32
- setting(:path, 'test') { |value| Pathname(value) }
33
- # Passing the reader option as true will create attr_reader method for the class
34
- setting :pool, 5, reader: true
35
- # Passing the reader attributes works with nested configuration
36
- setting :uploader, reader: true do
37
- setting :bucket, 'dev'
38
- end
39
- end
40
-
41
- App.config.database.dsn
42
- # => "sqlite:memory"
43
-
44
- App.config.database.dsn = 'jdbc:sqlite:memory'
45
- App.config.database.dsn
46
- # => "jdbc:sqlite:memory"
47
- App.config.adapter
48
- # => nil
49
- App.config.path
50
- # => #<Pathname:test>
51
- App.pool
52
- # => 5
53
- App.uploader.bucket
54
- # => 'dev'
55
- ```
@@ -1,27 +0,0 @@
1
- ---
2
- title: Testing
3
- layout: gem-single
4
- name: dry-configurable
5
- ---
6
-
7
- ### How to reset the config to its original state on testing environment
8
-
9
- update `spec_helper.rb` :
10
-
11
- ```ruby
12
- require "dry/configurable/test_interface"
13
-
14
- # this is your module/class that extended by Dry::Configurable
15
- module AwesomeModule
16
- enable_test_interface
17
- end
18
- ```
19
-
20
- and on spec file (`xxx_spec.rb`) :
21
-
22
- ```ruby
23
- before(:all) { AwesomeModule.reset_config }
24
- # or
25
- before(:each) { AwesomeModule.reset_config }
26
-
27
- ```
@@ -1,50 +0,0 @@
1
- module Dry
2
- # Argument parser
3
- #
4
- # Passing and array or arguments, it will decide which one are arguments
5
- # and which one are options.
6
- #
7
- # We have a limitation if setting the value without options, as a hash
8
- # having the same key as one of the valid options, will parse the value
9
- # as options. In this case, all unknown options will be reject with an exception.
10
- #
11
- # @example
12
- # p = Dry::Configurable::ArgumentParser.new.('db:sqlite', reader: true)
13
- #
14
- # p[0] # => 'db:sqlite'
15
- # p[1] # => ArgumentParser::DEFAULT_PROCESSOR
16
- # p[2] # => { reader: true }
17
- module Configurable
18
- class Settings
19
- # @private
20
- class ArgumentParser
21
- DEFAULT_PROCESSOR = ->(v) { v }
22
-
23
- # @private
24
- def call(val, opts, block)
25
- if block && block.parameters.empty?
26
- raise ArgumentError unless Undefined.equal?(opts)
27
-
28
- processor = DEFAULT_PROCESSOR
29
-
30
- value, options = Settings.capture(&block), val
31
- else
32
- processor = block || DEFAULT_PROCESSOR
33
-
34
- if Undefined.equal?(opts) && val.is_a?(Hash) && val.key?(:reader)
35
- value, options = Undefined, val
36
- else
37
- value, options = val, opts
38
- end
39
- end
40
-
41
- [value, processor, options(**Undefined.default(options, EMPTY_HASH))]
42
- end
43
-
44
- def options(reader: false)
45
- { reader: reader }
46
- end
47
- end
48
- end
49
- end
50
- end
data/rakelib/rubocop.rake DELETED
@@ -1,18 +0,0 @@
1
- begin
2
- require 'rubocop/rake_task'
3
-
4
- Rake::Task[:default].enhance [:rubocop]
5
-
6
- RuboCop::RakeTask.new do |task|
7
- task.options << '--display-cop-names'
8
- end
9
-
10
- namespace :rubocop do
11
- desc 'Generate a configuration file acting as a TODO list.'
12
- task :auto_gen_config do
13
- exec 'bundle exec rubocop --auto-gen-config'
14
- end
15
- end
16
-
17
- rescue LoadError
18
- end