dry-configurable 0.8.3 → 0.9.0

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
  SHA256:
3
- metadata.gz: e2952b22a9581b91b77a416925a150088ea715be486638e293beae10d5b493a8
4
- data.tar.gz: 6cf8073234d53e391e25d03eb0b3548694ebbaa30742169895b8f1d519f258d7
3
+ metadata.gz: e2803e976eb7d92b67ba2a5fbc79b8419340b6ea1f0dd7ea752327762989507a
4
+ data.tar.gz: 4da9d2ab7b1c7914bff8e7e82edc16dea3b55ea889cff85df5bb75dd8ba8e260
5
5
  SHA512:
6
- metadata.gz: 441ba5b074dd577bd0e0d37b5a99e76dc1ab85068885832e791eba4cd7a61e5691683f96c93e930a29d59e838b294d82248074433c670466ad31f773e1994dab
7
- data.tar.gz: 02f13c05320aca5bb6900dd831966c3edc760fd66b9bfe40f94d079da0f3af30ecbdd07cdd024807d305296caf55f1b1613c285cdec86db97fb57659c42c11a0
6
+ metadata.gz: e2d4aa78ddd0a048ab064c063ba502ab4c3e4bfc6631c2bf5d1399255bbf89916af1f8e2042dd7845d01879738589491991b2a101b6703b8ebc5626f41690a1e
7
+ data.tar.gz: c9145ff55bf902b0dbb633c76c7511aa6af862fd4b31db3da5b83b5bc7990a63bc3c8afa525b43bd081cbb9c710583e111e9ef9c0c795407b10398dfa75fe2e5
@@ -1,23 +1,12 @@
1
- engines:
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ version: "2"
4
+
5
+ exclude_patterns:
6
+ - "benchmarks/"
7
+ - "examples/"
8
+ - "spec/"
9
+
10
+ plugins:
2
11
  rubocop:
3
12
  enabled: true
4
- checks:
5
- Rubocop/Metrics/LineLength:
6
- enabled: true
7
- max: 120
8
- Rubocop/Style/Documentation:
9
- enabled: false
10
- Rubocop/Lint/HandleExceptions:
11
- enabled: true
12
- exclude:
13
- - rakelib/*.rake
14
- Rubocop/Style/FileName:
15
- enabled: true
16
- exclude:
17
- - lib/dry-configurable.rb
18
- ratings:
19
- paths:
20
- - lib/**/*.rb
21
- exclude_paths:
22
- - spec/**/*
23
- - examples/**/*
@@ -0,0 +1,10 @@
1
+ ---
2
+ name: "⚠️ Please don't ask for support via issues"
3
+ about: See CONTRIBUTING.md for more information
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: "\U0001F41B Bug report"
3
+ about: See CONTRIBUTING.md for more information
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
11
+
12
+ For more information see [our contribution guidelines](https://github.com/rom-rb/rom/blob/master/CONTRIBUTING.md)
13
+
14
+ **Before you report**
15
+
16
+ :warning: If you have a problem related to a schema, please **report it under [dry-schema issues](https://github.com/dry-rb/dry-schema/issues/new?assignees=&labels=bug&template=---bug-report.md&title=)** instead.
17
+
18
+ **Describe the bug**
19
+
20
+ A clear and concise description of what the bug is.
21
+
22
+ **To Reproduce**
23
+
24
+ Provide detailed steps to reproduce, an executable script would be best.
25
+
26
+ **Expected behavior**
27
+
28
+ A clear and concise description of what you expected to happen.
29
+
30
+ **Your environment**
31
+
32
+ - Affects my production application: **YES/NO**
33
+ - Ruby version: ...
34
+ - OS: ...
@@ -0,0 +1,18 @@
1
+ ---
2
+ name: "\U0001F6E0 Feature request"
3
+ about: See CONTRIBUTING.md for more information
4
+ title: ''
5
+ labels: feature
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ Summary of what the feature is supposed to do.
11
+
12
+ ## Examples
13
+
14
+ Code examples showing how the feature could be used.
15
+
16
+ ## Resources
17
+
18
+ Additional information, like a link to the discussion forum thread where the feature was discussed etc.
@@ -0,0 +1,70 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ paths:
6
+ - .github/workflows/ci.yml
7
+ - lib/**
8
+ - spec/**
9
+
10
+ jobs:
11
+ tests-mri:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ ruby: ["2.6.x", "2.5.x", "2.4.x"]
17
+ include:
18
+ - ruby: "2.6.x"
19
+ coverage: "true"
20
+ steps:
21
+ - uses: actions/checkout@v1
22
+ - name: Set up Ruby
23
+ uses: actions/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{matrix.ruby}}
26
+ - name: Download test reporter
27
+ if: "matrix.coverage == 'true'"
28
+ run: |
29
+ mkdir -p tmp/
30
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
31
+ chmod +x ./tmp/cc-test-reporter
32
+ ./tmp/cc-test-reporter before-build
33
+ - name: Run all tests
34
+ env:
35
+ COVERAGE: ${{matrix.coverage}}
36
+ run: |
37
+ gem install bundler
38
+ bundle install --jobs 4 --retry 3 --without tools docs
39
+ bundle exec rake
40
+ - name: Send coverage results
41
+ if: "matrix.coverage == 'true'"
42
+ env:
43
+ CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
44
+ GIT_COMMIT_SHA: ${{github.sha}}
45
+ GIT_BRANCH: ${{github.ref}}
46
+ GIT_COMMITTED_AT: ${{github.event.head_commit.timestamp}}
47
+ run: |
48
+ GIT_BRANCH=`ruby -e "puts ENV['GITHUB_REF'].split('/', 3).last"` \
49
+ GIT_COMMITTED_AT=`ruby -r time -e "puts Time.iso8601(ENV['GIT_COMMITTED_AT']).to_i"` \
50
+ ./tmp/cc-test-reporter after-build
51
+
52
+ tests-others:
53
+ runs-on: ubuntu-latest
54
+ strategy:
55
+ fail-fast: false
56
+ matrix:
57
+ image: ["jruby:9.2.8", "ruby:rc"]
58
+ container:
59
+ image: ${{matrix.image}}
60
+ steps:
61
+ - uses: actions/checkout@v1
62
+ - name: Install git
63
+ run: |
64
+ apt-get update
65
+ apt-get install -y --no-install-recommends git
66
+ - name: Run all tests
67
+ run: |
68
+ gem install bundler
69
+ bundle install --jobs 4 --retry 3 --without tools docs
70
+ bundle exec rspec
@@ -0,0 +1,34 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ name: docsite
4
+
5
+ on:
6
+ push:
7
+ paths:
8
+ - docsite/**
9
+ - .github/workflows/docsite.yml
10
+ branches:
11
+ - master
12
+ - release-**
13
+ tags:
14
+
15
+ jobs:
16
+ update-docs:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v1
20
+ - name: Set up Ruby
21
+ uses: actions/setup-ruby@v1
22
+ with:
23
+ ruby-version: "2.6.x"
24
+ - name: Install dependencies
25
+ run: |
26
+ gem install bundler
27
+ bundle install --jobs 4 --retry 3 --without benchmarks sql
28
+ - name: Symlink ossy
29
+ run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
30
+ - name: Trigger dry-rb.org deploy
31
+ env:
32
+ GITHUB_LOGIN: dry-bot
33
+ GITHUB_TOKEN: ${{ secrets.GH_PAT }}
34
+ run: bin/ossy github workflow dry-rb/dry-rb.org ci
@@ -0,0 +1,30 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ name: sync_configs
4
+
5
+ on:
6
+ repository_dispatch:
7
+
8
+ jobs:
9
+ sync-configs:
10
+ runs-on: ubuntu-latest
11
+ if: github.event.action == 'sync_configs'
12
+ steps:
13
+ - uses: actions/checkout@v1
14
+ - name: Update configuration files from devtools
15
+ env:
16
+ GITHUB_LOGIN: dry-bot
17
+ GITHUB_TOKEN: ${{ secrets.GH_PAT }}
18
+ run: |
19
+ git clone https://github.com/dry-rb/devtools.git tmp/devtools
20
+
21
+ rsync -av tmp/devtools/shared/ .
22
+
23
+ git config --local user.email "dry-bot@dry-rb.org"
24
+ git config --local user.name "dry-bot"
25
+ git add -A
26
+ git commit -m "[devtools] config sync" || echo "nothing changed"
27
+ - name: Push changes
28
+ uses: ad-m/github-push-action@master
29
+ with:
30
+ github_token: ${{ secrets.GH_PAT }}
data/.rspec CHANGED
@@ -1,2 +1,4 @@
1
1
  --color
2
- --require ./spec/spec_helper.rb
2
+ --require spec_helper
3
+ --order random
4
+
@@ -0,0 +1,89 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
5
+
6
+ Style/EachWithObject:
7
+ Enabled: false
8
+
9
+ Style/StringLiterals:
10
+ Enabled: true
11
+ EnforcedStyle: single_quotes
12
+
13
+ Style/Alias:
14
+ Enabled: false
15
+
16
+ Style/LambdaCall:
17
+ Enabled: false
18
+
19
+ Style/StabbyLambdaParentheses:
20
+ Enabled: false
21
+
22
+ Style/FormatString:
23
+ Enabled: false
24
+
25
+ Style/Documentation:
26
+ Enabled: false
27
+
28
+ Layout/SpaceInLambdaLiteral:
29
+ Enabled: false
30
+
31
+ Layout/MultilineMethodCallIndentation:
32
+ Enabled: true
33
+ EnforcedStyle: indented
34
+
35
+ Metrics/LineLength:
36
+ Max: 100
37
+
38
+ Metrics/MethodLength:
39
+ Max: 22
40
+
41
+ Metrics/ClassLength:
42
+ Max: 150
43
+
44
+ Metrics/AbcSize:
45
+ Max: 20
46
+
47
+ Metrics/BlockLength:
48
+ Enabled: false
49
+
50
+ Metrics/CyclomaticComplexity:
51
+ Enabled: true
52
+ Max: 10
53
+
54
+ Lint/BooleanSymbol:
55
+ Enabled: false
56
+
57
+ Style/AccessModifierDeclarations:
58
+ Enabled: false
59
+
60
+ Style/BlockDelimiters:
61
+ Enabled: false
62
+
63
+ Layout/IndentFirstArrayElement:
64
+ EnforcedStyle: consistent
65
+
66
+ Style/ClassAndModuleChildren:
67
+ Exclude:
68
+ - "spec/**/*_spec.rb"
69
+
70
+ Lint/HandleExceptions:
71
+ Exclude:
72
+ - "spec/spec_helper.rb"
73
+
74
+ Naming/FileName:
75
+ Exclude:
76
+ - "lib/dry-*.rb"
77
+
78
+ Style/SymbolArray:
79
+ Exclude:
80
+ - "spec/**/*_spec.rb"
81
+
82
+ Style/ConditionalAssignment:
83
+ Enabled: false
84
+
85
+ Naming/MethodName:
86
+ Enabled: false
87
+
88
+ Style/AsciiComments:
89
+ Enabled: false
@@ -1,8 +1,18 @@
1
+ ## 0.9.0 - 2019-11-06
2
+
3
+ ## Fixed
4
+
5
+ - Support for reserved names in settings. Some Kernel methods (`public_send` and `class` specifically) are not available if you use access settings via method call. Same for methods of the `Config` class. You can still access them with `[]` and `[]=`. Ruby keywords are fully supported. Invalid names containing special symbols (including `!` and `?`) are rejected. Note that these changes don't affect the `reader` option, if you define a setting named `:class` and pass `reader: true` ... well ... (flash-gordon)
6
+ - Settings can be redefined in subclasses without a warning about overriding exsting methods (flash-gordon)
7
+ - Fix warnings about using keyword arguments in 2.7 (koic)
8
+
9
+ [Compare v0.8.3...0.9.0](https://github.com/dry-rb/dry-configurable/compare/v0.8.3...0.9.0)
10
+
1
11
  ## 0.8.3 - 2019-05-29
2
12
 
3
13
  ## Fixed
4
14
 
5
- * `Configurable#dup` and `Configurable#clone` make a copy of instance-level config so that it doesn't get mutated/shared across instances (flash-gordon)
15
+ - `Configurable#dup` and `Configurable#clone` make a copy of instance-level config so that it doesn't get mutated/shared across instances (flash-gordon)
6
16
 
7
17
  [Compare v0.8.2...v0.8.3](https://github.com/dry-rb/dry-configurable/compare/v0.8.2...v0.8.3)
8
18
 
@@ -10,7 +20,7 @@
10
20
 
11
21
  ## Fixed
12
22
 
13
- * Test interface support for modules ([Neznauy](https://github.com/Neznauy))
23
+ - Test interface support for modules ([Neznauy](https://github.com/Neznauy))
14
24
 
15
25
  [Compare v0.8.1...v0.8.2](https://github.com/dry-rb/dry-configurable/compare/v0.8.1...v0.8.2)
16
26
 
@@ -18,7 +28,7 @@
18
28
 
19
29
  ## Fixed
20
30
 
21
- * `.configure` doesn't require a block, this makes the behavior consistent with the previous versions ([flash-gordon](https://github.com/flash-gordon))
31
+ - `.configure` doesn't require a block, this makes the behavior consistent with the previous versions ([flash-gordon](https://github.com/flash-gordon))
22
32
 
23
33
  [Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-configurable/compare/v0.8.0...v0.8.1)
24
34
 
@@ -26,11 +36,12 @@
26
36
 
27
37
  ## Fixed
28
38
 
29
- * A number of bugs related to inheriting settings from parent class were fixed. Ideally, new behavior will be :100: predictable but if you observe any anomaly, please report ([flash-gordon](https://github.com/flash-gordon))
39
+ - A number of bugs related to inheriting settings from parent class were fixed. Ideally, new behavior will be :100: predictable but if you observe any anomaly, please report ([flash-gordon](https://github.com/flash-gordon))
30
40
 
31
41
  ## Added
32
42
 
33
- * Support for instance-level configuration landed. For usage, `include` the module instead of extending ([flash-gordon](https://github.com/flash-gordon))
43
+ - Support for instance-level configuration landed. For usage, `include` the module instead of extending ([flash-gordon](https://github.com/flash-gordon))
44
+
34
45
  ```ruby
35
46
  class App
36
47
  include Dry::Configurable
@@ -46,7 +57,9 @@
46
57
  development.config.database = 'jdbc:sqlite:memory'
47
58
  development.finalize!
48
59
  ```
49
- * Config values can be set from a hash with `.update`. Nested settings are supported ([flash-gordon](https://github.com/flash-gordon))
60
+
61
+ - Config values can be set from a hash with `.update`. Nested settings are supported ([flash-gordon](https://github.com/flash-gordon))
62
+
50
63
  ```ruby
51
64
  class App
52
65
  extend Dry::Configurable
@@ -62,7 +75,7 @@
62
75
 
63
76
  ## Changed
64
77
 
65
- * [BREAKING] Minimal supported Ruby version is set to 2.3 ([flash-gordon](https://github.com/flash-gordon))
78
+ - [BREAKING] Minimal supported Ruby version is set to 2.3 ([flash-gordon](https://github.com/flash-gordon))
66
79
 
67
80
  [Compare v0.7.0...v0.8.0](https://github.com/dry-rb/dry-configurable/compare/v0.7.0...v0.8.0)
68
81
 
@@ -70,12 +83,12 @@
70
83
 
71
84
  ## Added
72
85
 
73
- * Introduce `Configurable.finalize!` which freezes config and its dependencies ([qcam](https://github.com/qcam))
86
+ - Introduce `Configurable.finalize!` which freezes config and its dependencies ([qcam](https://github.com/qcam))
74
87
 
75
88
  ## Fixed
76
89
 
77
- * Allow for boolean false as default setting value ([yuszuv](https://github.com/yuszuv))
78
- * Convert nested configs to nested hashes with `Config#to_h` ([saverio-kantox](https://github.com/saverio-kantox))
79
- * Disallow modification on frozen config ([qcam](https://github.com/qcam))
90
+ - Allow for boolean false as default setting value ([yuszuv](https://github.com/yuszuv))
91
+ - Convert nested configs to nested hashes with `Config#to_h` ([saverio-kantox](https://github.com/saverio-kantox))
92
+ - Disallow modification on frozen config ([qcam](https://github.com/qcam))
80
93
 
81
94
  [Compare v0.6.2...v0.7.0](https://github.com/dry-rb/dry-configurable/compare/v0.6.2...v0.7.0)
@@ -0,0 +1,13 @@
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)
@@ -6,11 +6,11 @@ If you found a bug, report an issue and describe what's the expected behavior ve
6
6
 
7
7
  ## Reporting feature requests
8
8
 
9
- Report a feature request **only after discussing it first on [discuss.dry-rb.org](https://discuss.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.
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
10
 
11
11
  ## Reporting questions, support requests, ideas, concerns etc.
12
12
 
13
- **PLEASE DON'T** - use [discuss.dry-rb.org](http://discuss.dry-rb.org) instead.
13
+ **PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
14
14
 
15
15
  # Pull Request Guidelines
16
16
 
@@ -26,4 +26,4 @@ Other requirements:
26
26
 
27
27
  # Asking for help
28
28
 
29
- If these guidelines aren't helpful, and you're stuck, please post a message on [discuss.dry-rb.org](https://discuss.dry-rb.org).
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 CHANGED
@@ -7,6 +7,8 @@ group :test do
7
7
  gem 'codeclimate-test-reporter', require: false
8
8
  gem 'simplecov', require: false
9
9
  end
10
+
11
+ gem 'warning'
10
12
  end
11
13
 
12
14
  group :tools do
@@ -14,4 +16,5 @@ group :tools do
14
16
  gem 'guard-rspec'
15
17
  gem 'listen', '3.0.6'
16
18
  gem 'pry-byebug', platform: :mri
19
+ gem "ossy", git: "https://github.com/solnic/ossy.git", branch: "master"
17
20
  end
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2017 dry-rb
3
+ Copyright (c) 2015-2019 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
@@ -0,0 +1,55 @@
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
+ ```
@@ -0,0 +1,27 @@
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
+ ```
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  'changelog_uri' => 'https://github.com/dry-rb/dry-configurable/blob/master/CHANGELOG.md'
20
20
  }
21
21
 
22
- spec.required_ruby_version = ">= 2.3.0"
22
+ spec.required_ruby_version = ">= 2.4.0"
23
23
  spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
24
24
  spec.add_runtime_dependency 'dry-core', '~> 0.4', '>= 0.4.7'
25
25
 
@@ -59,19 +59,18 @@ module Dry
59
59
  #
60
60
  # @yield
61
61
  # If a block is given, it will be evaluated in the context of
62
- # and new configuration class, and bound as the default value
62
+ # a new configuration class, and bound as the default value
63
63
  #
64
64
  # @return [Dry::Configurable::Config]
65
65
  #
66
66
  # @api public
67
67
  def setting(key, value = Undefined, options = Undefined, &block)
68
- extended = singleton_class < Configurable
69
68
  raise_already_defined_config(key) if _settings.config_defined?
70
69
 
71
70
  setting = _settings.add(key, value, options, &block)
72
71
 
73
72
  if setting.reader?
74
- readers = extended ? singleton_class : self
73
+ readers = singleton_class < Configurable ? singleton_class : self
75
74
  readers.send(:define_method, setting.name) { config[setting.name] }
76
75
  end
77
76
  end
@@ -22,6 +22,8 @@ module Dry
22
22
  break if config_defined?
23
23
 
24
24
  settings.each do |setting|
25
+ next if setting.reserved?
26
+
25
27
  define_method(setting.name) do
26
28
  @config[setting.name]
27
29
  end
@@ -96,8 +98,15 @@ module Dry
96
98
  #
97
99
  # @return Config value
98
100
  def [](name)
99
- raise_unknown_setting_error(name) unless key?(name.to_sym)
100
- public_send(name)
101
+ setting = self.class.settings[name.to_sym]
102
+
103
+ if setting.nil?
104
+ raise_unknown_setting_error(name)
105
+ elsif setting.reserved?
106
+ @config[setting.name]
107
+ else
108
+ public_send(name)
109
+ end
101
110
  end
102
111
 
103
112
  # Set config value.
@@ -106,8 +115,15 @@ module Dry
106
115
  # @param [String,Symbol] name
107
116
  # @param [Object] value
108
117
  def []=(name, value)
109
- raise_unknown_setting_error(name) unless key?(name.to_sym)
110
- public_send("#{name}=", value)
118
+ setting = self.class.settings[name.to_sym]
119
+
120
+ if setting.nil?
121
+ raise_unknown_setting_error(name)
122
+ elsif setting.reserved?
123
+ @config[setting.name] = setting.processor.(value)
124
+ else
125
+ public_send("#{name}=", value)
126
+ end
111
127
  end
112
128
 
113
129
  # Whether config has a key
@@ -162,7 +178,7 @@ module Dry
162
178
 
163
179
  # @private
164
180
  def raise_unknown_setting_error(name)
165
- raise ArgumentError, "+#{name}+ is not a setting name"
181
+ ::Kernel.raise ArgumentError, "+#{name}+ is not a setting name"
166
182
  end
167
183
  end
168
184
  end
@@ -4,6 +4,8 @@ module Dry
4
4
  #
5
5
  # @private
6
6
  class Setting
7
+ VALID_NAME = /\A[a-z_]\w*\z/i
8
+
7
9
  attr_reader :name
8
10
 
9
11
  attr_reader :options
@@ -11,6 +13,9 @@ module Dry
11
13
  attr_reader :processor
12
14
 
13
15
  def initialize(name, value, processor, options = EMPTY_HASH)
16
+ unless VALID_NAME =~ name.to_s
17
+ raise ArgumentError, "+#{name}+ is not a valid setting name"
18
+ end
14
19
  @name = name.to_sym
15
20
  @value = value
16
21
  @processor = processor
@@ -32,6 +37,10 @@ module Dry
32
37
  def node?
33
38
  Settings === @value
34
39
  end
40
+
41
+ def reserved?
42
+ options[:reserved]
43
+ end
35
44
  end
36
45
  end
37
46
  end
@@ -40,12 +40,13 @@ module Dry
40
40
 
41
41
  attr_reader :config_class
42
42
 
43
- attr_reader :names
43
+ attr_reader :index
44
+ private :index
44
45
 
45
46
  def initialize(settings = ::Concurrent::Array.new)
46
47
  @settings = settings
47
48
  @config_class = Config[self]
48
- @names = Set.new(settings.map(&:name))
49
+ @index = settings.map { |s| [s.name, s] }.to_h
49
50
  yield(self) if block_given?
50
51
  end
51
52
 
@@ -53,9 +54,13 @@ module Dry
53
54
  extended = singleton_class < Configurable
54
55
  raise_already_defined_config(key) if extended && configured?
55
56
 
56
- Setting.new(key, *Parser.(value, options, block)).tap do |s|
57
+ *args, opts = Parser.(value, options, block)
58
+
59
+ Setting.new(key, *args, { **opts, reserved: reserved?(key) }).tap do |s|
60
+ settings.delete_if { |e| e.name.eql?(s.name) }
57
61
  settings << s
58
- names << s.name
62
+ index[s.name] = s
63
+ @names = nil
59
64
  end
60
65
  end
61
66
 
@@ -63,12 +68,20 @@ module Dry
63
68
  settings.each { |s| yield(s) }
64
69
  end
65
70
 
71
+ def names
72
+ @names ||= index.keys.to_set
73
+ end
74
+
75
+ def [](name)
76
+ index[name]
77
+ end
78
+
66
79
  def empty?
67
80
  settings.empty?
68
81
  end
69
82
 
70
83
  def name?(name)
71
- names.include?(name)
84
+ index.key?(name)
72
85
  end
73
86
 
74
87
  def dup
@@ -87,6 +100,18 @@ module Dry
87
100
  def config_defined?
88
101
  config_class.config_defined?
89
102
  end
103
+
104
+ def reserved?(name)
105
+ reserved_names.include?(name)
106
+ end
107
+
108
+ def reserved_names
109
+ @reserved_names ||= [
110
+ config_class.instance_methods(false),
111
+ config_class.superclass.instance_methods(false),
112
+ %i(class public_send)
113
+ ].reduce(:+)
114
+ end
90
115
  end
91
116
  end
92
117
  end
@@ -38,7 +38,7 @@ module Dry
38
38
  end
39
39
  end
40
40
 
41
- [value, processor, options(Undefined.default(options, EMPTY_HASH))]
41
+ [value, processor, options(**Undefined.default(options, EMPTY_HASH))]
42
42
  end
43
43
 
44
44
  def options(reader: false)
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  module Configurable
3
3
  # @api public
4
- VERSION = '0.8.3'.freeze
4
+ VERSION = '0.9.0'.freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-configurable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-29 00:00:00.000000000 Z
11
+ date: 2019-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -94,15 +94,24 @@ extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
96
  - ".codeclimate.yml"
97
+ - ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
98
+ - ".github/ISSUE_TEMPLATE/---bug-report.md"
99
+ - ".github/ISSUE_TEMPLATE/---feature-request.md"
100
+ - ".github/workflows/ci.yml"
101
+ - ".github/workflows/docsite.yml"
102
+ - ".github/workflows/sync_configs.yml"
97
103
  - ".gitignore"
98
104
  - ".rspec"
99
- - ".travis.yml"
105
+ - ".rubocop.yml"
100
106
  - CHANGELOG.md
107
+ - CODE_OF_CONDUCT.md
101
108
  - CONTRIBUTING.md
102
109
  - Gemfile
103
110
  - LICENSE
104
111
  - README.md
105
112
  - Rakefile
113
+ - docsite/source/index.html.md
114
+ - docsite/source/testing.html.md
106
115
  - dry-configurable.gemspec
107
116
  - lib/dry-configurable.rb
108
117
  - lib/dry/configurable.rb
@@ -128,14 +137,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
137
  requirements:
129
138
  - - ">="
130
139
  - !ruby/object:Gem::Version
131
- version: 2.3.0
140
+ version: 2.4.0
132
141
  required_rubygems_version: !ruby/object:Gem::Requirement
133
142
  requirements:
134
143
  - - ">="
135
144
  - !ruby/object:Gem::Version
136
145
  version: '0'
137
146
  requirements: []
138
- rubygems_version: 3.0.3
147
+ rubygems_version: 3.0.6
139
148
  signing_key:
140
149
  specification_version: 4
141
150
  summary: A mixin to add configuration functionality to your classes
@@ -1,28 +0,0 @@
1
- language: ruby
2
- dist: trusty
3
- sudo: required
4
- cache: bundler
5
- bundler_args: --without console
6
- after_success:
7
- - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
8
- rvm:
9
- - 2.4.6
10
- - 2.5.5
11
- - 2.6.3
12
- - jruby-9.2.7.0
13
- - truffleruby
14
- matrix:
15
- allow_failures:
16
- - rvm: truffleruby
17
- env:
18
- global:
19
- - JRUBY_OPTS='--dev -J-Xmx1024M'
20
- - COVERAGE='true'
21
- notifications:
22
- email: false
23
- webhooks:
24
- urls:
25
- - https://webhooks.gitter.im/e/19098b4253a72c9796db
26
- on_success: change # options: [always|never|change] default: always
27
- on_failure: always # options: [always|never|change] default: always
28
- on_start: false # default: false