dry-initializer 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +1 -1
- data/dry-initializer.gemspec +1 -1
- data/lib/dry/initializer/builders/attribute.rb +2 -2
- data/lib/dry/initializer/config.rb +12 -0
- data/lib/dry/initializer/definition.rb +14 -2
- data/spec/public_attributes_utility_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1ca51134d5d589e28d742d78ea453809ef53ea0
|
4
|
+
data.tar.gz: e1c9fe841d80609eb35a17f2d5742bae2f9dd026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb91104134574f2c106b813076de9798788f558c25cdd0bdadc0098fc6f90cea915d15e742d4805fcd32aed28c5e53a4801ed04397a51c8a668d69989f4dc8d4
|
7
|
+
data.tar.gz: b104ca6bd0b5b46de69036754a7669b162bc88856aec29a298571bf5a988d8eee1c54c15aa0a0b774b872e12f2a596f190796a62f43ea36f333fe5fb4d3a4802
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,28 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## [2.2.0] [2017-09-13]
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Option `:desc` for option/param to add a description (nepalez)
|
12
|
+
|
13
|
+
- Methods `Definition#inch` and `Config#inch` to inspect definitions (nepalez)
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
class User
|
17
|
+
extend Dry::Initializer
|
18
|
+
option :name, proc(&:to_s), optional: true, desc: "User name"
|
19
|
+
option :email, optional: true, desc: "user email"
|
20
|
+
end
|
21
|
+
|
22
|
+
User.dry_initializer.inch
|
23
|
+
# @!method initialize(*, **options)
|
24
|
+
# Initializes an instance of User
|
25
|
+
# @option [Object] :name (optional) User name
|
26
|
+
# @option [Object] :email (optional) User email
|
27
|
+
# @return [User]
|
28
|
+
```
|
29
|
+
|
8
30
|
## [2.1.0] [2017-09-11]
|
9
31
|
|
10
32
|
### Added
|
@@ -687,3 +709,5 @@ First public release
|
|
687
709
|
[1.4.0]: https://github.com/dry-rb/dry-initializer/compare/v1.3.0...v1.4.0
|
688
710
|
[1.4.1]: https://github.com/dry-rb/dry-initializer/compare/v1.4.0...v1.4.1
|
689
711
|
[2.0.0]: https://github.com/dry-rb/dry-initializer/compare/v1.4.1...v2.0.0
|
712
|
+
[2.1.0]: https://github.com/dry-rb/dry-initializer/compare/v2.0.0...v2.1.0
|
713
|
+
[2.2.0]: https://github.com/dry-rb/dry-initializer/compare/v2.1.0...v2.2.0
|
data/README.md
CHANGED
data/dry-initializer.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "dry-initializer"
|
3
|
-
gem.version = "2.
|
3
|
+
gem.version = "2.2.0"
|
4
4
|
gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
|
5
5
|
gem.email = "andrew.kozin@gmail.com"
|
6
6
|
gem.homepage = "https://github.com/dryrb/dry-initializer"
|
@@ -11,7 +11,7 @@ module Dry::Initializer::Builders
|
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
# rubocop: disable
|
14
|
+
# rubocop: disable Metrics/MethodLength
|
15
15
|
def initialize(definition)
|
16
16
|
@definition = definition
|
17
17
|
@option = definition.option
|
@@ -26,7 +26,7 @@ module Dry::Initializer::Builders
|
|
26
26
|
@item = "__dry_initializer_definition__"
|
27
27
|
@val = @option ? "__dry_initializer_value__" : @source
|
28
28
|
end
|
29
|
-
# rubocop: enable
|
29
|
+
# rubocop: enable Metrics/MethodLength
|
30
30
|
|
31
31
|
def lines
|
32
32
|
[
|
@@ -111,6 +111,18 @@ module Dry::Initializer
|
|
111
111
|
self
|
112
112
|
end
|
113
113
|
|
114
|
+
# Human-readable representation of configured params and options
|
115
|
+
# @return [String]
|
116
|
+
def inch
|
117
|
+
line = Builders::Signature[self]
|
118
|
+
line = line.gsub("__dry_initializer_options__", "options")
|
119
|
+
lines = ["@!method initialize(#{line})"]
|
120
|
+
lines += ["Initializes an instance of #{extended_class}"]
|
121
|
+
lines += definitions.values.map(&:inch)
|
122
|
+
lines += ["@return [#{extended_class}]"]
|
123
|
+
lines.join("\n")
|
124
|
+
end
|
125
|
+
|
114
126
|
private
|
115
127
|
|
116
128
|
def initialize(extended_class = nil, null: UNDEFINED)
|
@@ -9,7 +9,8 @@ module Dry::Initializer
|
|
9
9
|
#
|
10
10
|
class Definition
|
11
11
|
attr_reader :option, :null, :source, :target, :ivar,
|
12
|
-
:type, :optional, :default, :reader
|
12
|
+
:type, :optional, :default, :reader,
|
13
|
+
:desc
|
13
14
|
|
14
15
|
def options
|
15
16
|
{
|
@@ -17,7 +18,8 @@ module Dry::Initializer
|
|
17
18
|
type: type,
|
18
19
|
optional: optional,
|
19
20
|
default: default,
|
20
|
-
reader: reader
|
21
|
+
reader: reader,
|
22
|
+
desc: desc
|
21
23
|
}.reject { |_, value| value.nil? }
|
22
24
|
end
|
23
25
|
|
@@ -36,6 +38,15 @@ module Dry::Initializer
|
|
36
38
|
Builders::Reader[self]
|
37
39
|
end
|
38
40
|
|
41
|
+
def inch
|
42
|
+
@inch ||= (option ? "@option" : "@param ").tap do |text|
|
43
|
+
text << " [Object]"
|
44
|
+
text << (option ? " :#{source}" : " #{source}")
|
45
|
+
text << (optional ? " (optional)" : " (required)")
|
46
|
+
text << " #{desc}" if desc
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
39
50
|
private
|
40
51
|
|
41
52
|
def initialize(option, null, source, coercer = nil, **options)
|
@@ -48,6 +59,7 @@ module Dry::Initializer
|
|
48
59
|
@reader = prepare_reader options.fetch(:reader, true)
|
49
60
|
@default = check_default options[:default]
|
50
61
|
@optional = options.fetch(:optional, @default)
|
62
|
+
@desc = options[:desc]&.to_s&.capitalize
|
51
63
|
end
|
52
64
|
|
53
65
|
def check_source(value)
|
@@ -5,7 +5,7 @@ describe Dry::Initializer, ".dry_initializer.public_attributes" do
|
|
5
5
|
before do
|
6
6
|
class Test::Foo
|
7
7
|
extend Dry::Initializer
|
8
|
-
param :foo, proc(&:to_s)
|
8
|
+
param :foo, proc(&:to_s), desc: "a weird parameter"
|
9
9
|
option :moo, optional: true
|
10
10
|
option :bar, default: proc { 1 }, reader: false
|
11
11
|
option :baz, optional: true, reader: :protected
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-initializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kochnev (marshall-lee)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-09-
|
12
|
+
date: 2017-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|