Module: Railsmith::BaseService::InputDsl::ClassMethods
- Defined in:
- lib/railsmith/base_service/input_dsl.rb
Overview
Class-level DSL macros for declaring inputs on a service.
Instance Method Summary collapse
-
#filter_inputs(value = :__unset__) ⇒ Object
Controls whether undeclared params are dropped after resolution.
- #inherited(subclass) ⇒ Object
-
#input(name, type, **options) ⇒ Object
Declare an input parameter.
-
#input_registry ⇒ Object
Returns the InputRegistry for this class.
- #normalize_input_options(options) ⇒ Object
Instance Method Details
#filter_inputs(value = :__unset__) ⇒ Object
Controls whether undeclared params are dropped after resolution. Pass false to disable filtering (opt-out). Called with no argument returns the current setting.
49 50 51 52 53 54 55 |
# File 'lib/railsmith/base_service/input_dsl.rb', line 49 def filter_inputs(value = :__unset__) if value == :__unset__ instance_variable_defined?(:@filter_inputs) ? @filter_inputs : true else @filter_inputs = value end end |
#inherited(subclass) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/railsmith/base_service/input_dsl.rb', line 57 def inherited(subclass) super subclass.instance_variable_set(:@input_registry, input_registry.dup) # Propagate filter_inputs setting only if explicitly set on this class. return unless instance_variable_defined?(:@filter_inputs) subclass.instance_variable_set(:@filter_inputs, @filter_inputs) end |
#input(name, type, **options) ⇒ Object
Declare an input parameter.
32 33 34 35 36 37 38 39 |
# File 'lib/railsmith/base_service/input_dsl.rb', line 32 def input(name, type, **) input_registry.register( InputDefinition.new( name, type, **() ) ) end |
#input_registry ⇒ Object
Returns the InputRegistry for this class.
42 43 44 |
# File 'lib/railsmith/base_service/input_dsl.rb', line 42 def input_registry @input_registry ||= InputRegistry.new end |
#normalize_input_options(options) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/railsmith/base_service/input_dsl.rb', line 66 def () { required: .fetch(:required, false), default: .fetch(:default, InputDefinition::UNSET), in: [:in], transform: [:transform] } end |