dry-system 0.9.2 → 0.10.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: dc54fdf54119a26ac5515b45a345e7407a4f5cb4352f8e13d7034828b679c10d
4
- data.tar.gz: 96611520cdc10b6a0732dc8256da6f0182ab8642adccad677ee807426779f860
3
+ metadata.gz: d2a8be3e6a065030a843d21c8940d4869cfda202c1959c7094b601f8d266c499
4
+ data.tar.gz: 1938faa66a1913ca2297d51ad0abd9a4f1f787426c4fe512103a3b9e2ada5394
5
5
  SHA512:
6
- metadata.gz: a6c4bd4ee28b3ca5c6569408ff33ca9aa3b4abbc70b89586a16f214dd2462323282e052cddbc21ef26db81baece8fbe1810ee1abfec577f526d0bfdb84d3deb3
7
- data.tar.gz: 0a778beb32dfcb0a103becf8361f082e539265de5f7290b8009f4e49c31b20cfad79040c5399b11af412182ffb6502ea129b957fb683b5b385d1f1d32c36d7ec
6
+ metadata.gz: 5766837f8f85f7d3ece0107d3f65f0f81501ec00088cf860e1d47ad7e18284c24ff02c6109d80559aa64473cadce187fd6840e81b9a96648b75718d3d571fcbf
7
+ data.tar.gz: e26fd6ffb2d50c7b536a7ba7307ef348efcf6860f13487565975b17b34528fc876788705f655f0a3919b572eb26fc73b91cd2745156fb1d3acd6a737d3b0813c
@@ -1,3 +1,27 @@
1
+ # 0.10.0 - 2018-06-07
2
+
3
+ ### Added
4
+ * You can now set a custom inflector on the container level. As a result, the `Loader`'s constructor accepts two arguments: `path` and `inflector`, update your custom loaders accordingly (flash-gordon)
5
+
6
+ ```ruby
7
+ class MyContainer < Dry::System::Container
8
+ configure do |config|
9
+ config.inflector = Dry::Inflector.new do |inflections|
10
+ inflections.acronym('API')
11
+ end
12
+ end
13
+ end
14
+ ```
15
+
16
+ ### Changed
17
+
18
+ * A helpful error will be raised if an invalid setting value is provided (GustavoCaso)
19
+ * When using setting plugin, will use default values from types (GustavoCaso)
20
+ * Minimal supported ruby version was bump to `2.3` (flash-gordon)
21
+ * `dry-struct` was updated to `~> 0.5` (flash-gordon)
22
+
23
+ [Compare v0.9.2...master](https://github.com/dry-rb/dry-system/compare/v0.9.2...master)
24
+
1
25
  # 0.9.2 - 2018-02-08
2
26
 
3
27
  ### Fixed
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  [gem]: https://rubygems.org/gems/dry-system
2
2
  [travis]: https://travis-ci.org/dry-rb/dry-system
3
- [gemnasium]: https://gemnasium.com/dry-rb/dry-system
4
3
  [codeclimate]: https://codeclimate.com/github/dry-rb/dry-system
5
4
  [coveralls]: https://coveralls.io/r/dry-rb/dry-system
6
5
  [inchpages]: http://inch-ci.org/github/dry-rb/dry-system
@@ -9,7 +8,6 @@
9
8
 
10
9
  [![Gem Version](https://badge.fury.io/rb/dry-system.svg)][gem]
11
10
  [![Build Status](https://travis-ci.org/dry-rb/dry-system.svg?branch=master)][travis]
12
- [![Dependency Status](https://gemnasium.com/dry-rb/dry-system.svg)][gemnasium]
13
11
  [![Code Climate](https://codeclimate.com/github/dry-rb/dry-system/badges/gpa.svg)][codeclimate]
14
12
  [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-system/badges/coverage.svg)][codeclimate]
15
13
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-system.svg?branch=master)][inchpages]
@@ -4,8 +4,8 @@ module Dry
4
4
  # Default auto_registrar configuration
5
5
  #
6
6
  # This is currently configured by default for every System::Container.
7
- # Configuration allows to define custom initializtion logic as well
8
- # as exclusion, for each component that is been register by Dry::System
7
+ # Configuration allows to define custom initialization as well as exclusion
8
+ # logic, for each component that is being registered by Dry::System
9
9
  # auto-registration.
10
10
  #
11
11
  # @api private
@@ -1,6 +1,7 @@
1
1
  require 'concurrent/map'
2
2
 
3
3
  require 'dry-equalizer'
4
+ require 'dry/inflector'
4
5
  require 'dry/system/loader'
5
6
  require 'dry/system/errors'
6
7
  require 'dry/system/constants'
@@ -18,7 +19,11 @@ module Dry
18
19
  class Component
19
20
  include Dry::Equalizer(:identifier, :path)
20
21
 
21
- DEFAULT_OPTIONS = { separator: DEFAULT_SEPARATOR, namespace: nil }.freeze
22
+ DEFAULT_OPTIONS = {
23
+ separator: DEFAULT_SEPARATOR,
24
+ namespace: nil,
25
+ inflector: Dry::Inflector.new
26
+ }.freeze
22
27
 
23
28
  # @!attribute [r] identifier
24
29
  # @return [String] component's unique identifier
@@ -44,13 +49,13 @@ module Dry
44
49
  def self.new(*args, &block)
45
50
  cache.fetch_or_store([*args, block].hash) do
46
51
  name, options = args
47
- options = DEFAULT_OPTIONS.merge(options || {})
52
+ options = DEFAULT_OPTIONS.merge(options || EMPTY_HASH)
48
53
 
49
- ns, sep = options.values_at(:namespace, :separator)
54
+ ns, sep, inflector = options.values_at(:namespace, :separator, :inflector)
50
55
  identifier = extract_identifier(name, ns, sep)
51
56
 
52
57
  path = name.to_s.gsub(sep, PATH_SEPARATOR)
53
- loader = options.fetch(:loader, Loader).new(path)
58
+ loader = options.fetch(:loader, Loader).new(path, inflector)
54
59
 
55
60
  super(identifier, path, options.merge(loader: loader))
56
61
  end
@@ -11,6 +11,23 @@ module Dry
11
11
  WORD_REGEX = /\w+/.freeze
12
12
 
13
13
  DuplicatedComponentKeyError = Class.new(ArgumentError)
14
+ InvalidSettingsError = Class.new(ArgumentError) do
15
+ # @api private
16
+ def initialize(attributes)
17
+ message = <<~EOF
18
+ Could not initialize settings. The following settings were invalid:
19
+
20
+ #{attributes_errors(attributes).join("\n")}
21
+ EOF
22
+ super(message)
23
+ end
24
+
25
+ private
26
+
27
+ def attributes_errors(attributes)
28
+ attributes.map { |key, error| "#{key}: #{error}" }
29
+ end
30
+ end
14
31
 
15
32
  # Exception raise when a plugin dependency failed to load
16
33
  #
@@ -3,6 +3,7 @@ require 'pathname'
3
3
  require 'dry-auto_inject'
4
4
  require 'dry-configurable'
5
5
  require 'dry-container'
6
+ require 'dry/inflector'
6
7
 
7
8
  require 'dry/core/deprecations'
8
9
 
@@ -32,7 +33,7 @@ module Dry
32
33
  # Before finalization, Container can lazy-load components on demand. A
33
34
  # component can be a simple class defined in a single file, or a complex
34
35
  # component which has init/start/stop lifecycle, and it's defined in a boot
35
- # file. Components which specify their dependencies using. Import module can
36
+ # file. Components which specify their dependencies using Import module can
36
37
  # be safely required in complete isolation, and Container will resolve and
37
38
  # load these dependencies automatically.
38
39
  #
@@ -60,7 +61,7 @@ module Dry
60
61
  # end
61
62
  #
62
63
  # # this will configure $LOAD_PATH to include your `lib` dir
63
- # load_paths!('lib)
64
+ # load_paths!('lib')
64
65
  # end
65
66
  #
66
67
  # @api public
@@ -75,6 +76,7 @@ module Dry
75
76
  setting :system_dir, 'system'.freeze
76
77
  setting :registrations_dir, 'container'.freeze
77
78
  setting :auto_register, []
79
+ setting :inflector, Dry::Inflector.new
78
80
  setting :loader, Dry::System::Loader
79
81
  setting :booter, Dry::System::Booter
80
82
  setting :auto_registrar, Dry::System::AutoRegistrar
@@ -129,7 +131,7 @@ module Dry
129
131
  # import core: Core
130
132
  # end
131
133
  #
132
- # @param other [Hash,Dry::Container::Namespace]
134
+ # @param other [Hash, Dry::Container::Namespace]
133
135
  #
134
136
  # @api public
135
137
  def import(other)
@@ -280,7 +282,7 @@ module Dry
280
282
  # # You can put finalization file anywhere you want, ie system/boot.rb
281
283
  # MyApp.finalize!
282
284
  #
283
- # # If you need last-moment adjustements just before the finalization
285
+ # # If you need last-moment adjustments just before the finalization
284
286
  # # you can pass a block and do it there
285
287
  # MyApp.finalize! do |container|
286
288
  # # stuff that only needs to happen for finalization
@@ -350,7 +352,7 @@ module Dry
350
352
  # load_paths!('lib')
351
353
  # end
352
354
  #
353
- # @param [Array<String>] *dirs
355
+ # @param [Array<String>] dirs
354
356
  #
355
357
  # @return [self]
356
358
  #
@@ -375,7 +377,7 @@ module Dry
375
377
  # Typically you want to configure auto_register directories, and it will
376
378
  # work automatically. Use this method in cases where you want to have an
377
379
  # explicit way where some components are auto-registered, or if you want
378
- # to exclude some components from been auto-registered
380
+ # to exclude some components from being auto-registered
379
381
  #
380
382
  # @example
381
383
  # class MyApp < Dry::System::Container
@@ -443,13 +445,13 @@ module Dry
443
445
  # Requires one or more files relative to the container's root
444
446
  #
445
447
  # @example
446
- # # sinle file
448
+ # # single file
447
449
  # MyApp.require_from_root('lib/core')
448
450
  #
449
451
  # # glob
450
452
  # MyApp.require_from_root('lib/**/*')
451
453
  #
452
- # @param *paths [Array<String>] one or more paths, supports globs too
454
+ # @param paths [Array<String>] one or more paths, supports globs too
453
455
  #
454
456
  # @api public
455
457
  def require_from_root(*paths)
@@ -525,6 +527,7 @@ module Dry
525
527
  loader: config.loader,
526
528
  namespace: config.default_namespace,
527
529
  separator: config.namespace_separator,
530
+ inflector: config.inflector,
528
531
  **options,
529
532
  )
530
533
  end
@@ -41,7 +41,7 @@ module Dry
41
41
  #
42
42
  # Provided optional args are passed to object's constructor
43
43
  #
44
- # @param [Array] *args Optional constructor args
44
+ # @param [Array] args Optional constructor args
45
45
  #
46
46
  # @return [Object]
47
47
  #
@@ -3,6 +3,7 @@ require "dry/types"
3
3
  require "dry/struct"
4
4
 
5
5
  require "dry/system/settings/file_loader"
6
+ require "dry/system/constants"
6
7
 
7
8
  module Dry
8
9
  module System
@@ -32,20 +33,25 @@ module Dry
32
33
  end
33
34
 
34
35
  class Configuration < Dry::Struct
35
- constructor_type :strict_with_defaults
36
-
37
36
  def self.setting(*args)
38
37
  attribute(*args)
39
38
  end
40
39
 
41
40
  def self.load(root, env)
42
41
  env_data = load_files(root, env)
42
+ attributes = {}
43
+ errors = {}
43
44
 
44
- attributes = schema.each_with_object({}) do |(key, type), h|
45
+ schema.each do |key, type|
45
46
  value = ENV.fetch(key.to_s.upcase) { env_data[key.to_s.upcase] }
46
- h[key] = value
47
+ type_check = type.try(value || Undefined)
48
+
49
+ attributes[key] = value if value
50
+ errors[key] = type_check if type_check.failure?
47
51
  end
48
52
 
53
+ raise InvalidSettingsError.new(errors) unless errors.empty?
54
+
49
55
  new(attributes)
50
56
  end
51
57
 
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module System
3
- VERSION = '0.9.2'.freeze
3
+ VERSION = '0.10.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-system
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-08 00:00:00.000000000 Z
11
+ date: 2018-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -107,6 +107,9 @@ dependencies:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0.1'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 0.1.2
110
113
  type: :runtime
111
114
  prerelease: false
112
115
  version_requirements: !ruby/object:Gem::Requirement
@@ -114,20 +117,23 @@ dependencies:
114
117
  - - "~>"
115
118
  - !ruby/object:Gem::Version
116
119
  version: '0.1'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 0.1.2
117
123
  - !ruby/object:Gem::Dependency
118
124
  name: dry-struct
119
125
  requirement: !ruby/object:Gem::Requirement
120
126
  requirements:
121
127
  - - "~>"
122
128
  - !ruby/object:Gem::Version
123
- version: '0.3'
129
+ version: '0.5'
124
130
  type: :runtime
125
131
  prerelease: false
126
132
  version_requirements: !ruby/object:Gem::Requirement
127
133
  requirements:
128
134
  - - "~>"
129
135
  - !ruby/object:Gem::Version
130
- version: '0.3'
136
+ version: '0.5'
131
137
  - !ruby/object:Gem::Dependency
132
138
  name: bundler
133
139
  requirement: !ruby/object:Gem::Requirement
@@ -226,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
232
  requirements:
227
233
  - - ">="
228
234
  - !ruby/object:Gem::Version
229
- version: 2.1.0
235
+ version: 2.3.0
230
236
  required_rubygems_version: !ruby/object:Gem::Requirement
231
237
  requirements:
232
238
  - - ">="
@@ -234,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
240
  version: '0'
235
241
  requirements: []
236
242
  rubyforge_project:
237
- rubygems_version: 2.7.4
243
+ rubygems_version: 2.7.6
238
244
  signing_key:
239
245
  specification_version: 4
240
246
  summary: Organize your code into reusable components