Skip to content

Commit

Permalink
Add :desc option to option/param definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nepalez committed Sep 13, 2017
1 parent c24751a commit 356d6a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/dry/initializer/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ module Dry::Initializer
#
class Definition
attr_reader :option, :null, :source, :target, :ivar,
:type, :optional, :default, :reader
:type, :optional, :default, :reader,
:desc

def options
{
as: target,
type: type,
optional: optional,
default: default,
reader: reader
reader: reader,
desc: desc
}.reject { |_, value| value.nil? }
end

Expand Down Expand Up @@ -48,6 +50,7 @@ def initialize(option, null, source, coercer = nil, **options)
@reader = prepare_reader options.fetch(:reader, true)
@default = check_default options[:default]
@optional = options.fetch(:optional, @default)
@desc = options[:desc]&.to_s&.capitalize
end

def check_source(value)
Expand Down
2 changes: 1 addition & 1 deletion spec/public_attributes_utility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
before do
class Test::Foo
extend Dry::Initializer
param :foo, proc(&:to_s)
param :foo, proc(&:to_s), desc: "a weird parameter"
option :moo, optional: true
option :bar, default: proc { 1 }, reader: false
option :baz, optional: true, reader: :protected
Expand Down

0 comments on commit 356d6a8

Please sign in to comment.