From 3cd33ac52f7b4425c4bda9c4828621ead6eb48a8 Mon Sep 17 00:00:00 2001 From: "Andrew Kozin (nepalez)" Date: Tue, 23 Mar 2021 10:40:15 +0300 Subject: [PATCH] Fix documentation for unknown arguments (#68) Fixes the issue https://github.com/dry-rb/dry-initializer/issues/68 --- docsite/source/index.html.md | 2 +- docsite/source/options-tolerance.html.md | 27 ------------------- .../tolerance-to-unknown-arguments.html.md | 22 +++++++++++++++ 3 files changed, 23 insertions(+), 28 deletions(-) delete mode 100644 docsite/source/options-tolerance.html.md create mode 100644 docsite/source/tolerance-to-unknown-arguments.html.md diff --git a/docsite/source/index.html.md b/docsite/source/index.html.md index e00d1f0..8991203 100644 --- a/docsite/source/index.html.md +++ b/docsite/source/index.html.md @@ -8,7 +8,7 @@ name: dry-initializer sections: - container-version - params-and-options - - options-tolerance + - tolerance-to-unknown-arguments - optionals-and-defaults - type-constraints - readers diff --git a/docsite/source/options-tolerance.html.md b/docsite/source/options-tolerance.html.md deleted file mode 100644 index 54e239a..0000000 --- a/docsite/source/options-tolerance.html.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: Tolerance to Unknown Options -layout: gem-single -name: dry-initializer ---- - -By default the initializer is strict for params (positional arguments), expecting them to be defined explicitly. - -```ruby -require 'dry-initializer' - -class User - extend Dry::Initializer -end - -user = User.new 'Joe' # raises ArgumentError -``` - -At the same time it is tolerant to unknown options. All unknown options are accepted, but ignored: - -```ruby -# It accepts undefined options... -user = User.new name: 'Joe' - -# ...but ignores them -user.respond_to? :name # => false -``` diff --git a/docsite/source/tolerance-to-unknown-arguments.html.md b/docsite/source/tolerance-to-unknown-arguments.html.md new file mode 100644 index 0000000..23f303e --- /dev/null +++ b/docsite/source/tolerance-to-unknown-arguments.html.md @@ -0,0 +1,22 @@ +--- +title: Tolerance to Unknown Arguments +layout: gem-single +name: dry-initializer +--- + +By default the initializer is tolerant for both params (positional arguments) and options. +All unknown arguments of the initializer are ignored silently. + +```ruby +require 'dry-initializer' + +class User + extend Dry::Initializer +end + +user = User.new 'Joe', role: 'admin' +user.respond_to? :role # => false + +User.dry_initializer.attributes(user) +# => {} +```