Module: Calls::ClassMethods
- Defined in:
- lib/calls.rb
Overview
Methods that are added to your class.
Instance Method Summary collapse
- #__check_for_unknown_options(*args, **kwargs) ⇒ Object
- #__defined_options ⇒ Object
- #__defined_params ⇒ Object
- #call(*args, **kwargs, &block) ⇒ Object
-
#param(name, type = nil, **opts, &block) ⇒ Object
Overriding the implementation of ‘#param` in the `dry-initializer` gem.
Instance Method Details
#__check_for_unknown_options(*args, **kwargs) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/calls.rb', line 36 def (*args, **kwargs) return if .empty? # Checking params opts = args.drop(__defined_params.length).first || kwargs raise ArgumentError, "Unexpected argument #{opts}" unless opts.is_a? Hash # Checking options = opts.keys - = "Key(s) #{} not found in #{}" raise KeyError, if .any? end |
#__defined_options ⇒ Object
49 50 51 |
# File 'lib/calls.rb', line 49 def dry_initializer..map(&:source) end |
#__defined_params ⇒ Object
53 54 55 |
# File 'lib/calls.rb', line 53 def __defined_params dry_initializer.params.map(&:source) end |
#call(*args, **kwargs, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/calls.rb', line 15 def call(*args, **kwargs, &block) (*args, **kwargs) if kwargs.empty? # Preventing the warning "Passing the keyword argument as the last hash parameter is deprecated" new(*args).call(&block) else new(*args, **kwargs).call(&block) end end |
#param(name, type = nil, **opts, &block) ⇒ Object
Overriding the implementation of ‘#param` in the `dry-initializer` gem. Because of the positioning of multiple params, params can never be omitted in a method object. See github.com/dry-rb/dry-initializer/blob/main/lib/dry/initializer.rb
29 30 31 32 33 34 |
# File 'lib/calls.rb', line 29 def param(name, type = nil, **opts, &block) raise ArgumentError, "Default value for param not allowed - #{name}" if opts.key? :default raise ArgumentError, "Optional params not supported - #{name}" if opts.fetch(:optional, false) super end |