Class: Strict::Methods::Dsl
- Inherits:
- BasicObject
- Includes:
- Dsl::Coercible, Dsl::Validatable
- Defined in:
- lib/strict/methods/dsl.rb
Instance Attribute Summary collapse
-
#__strict_dsl_internal_parameters ⇒ Object
readonly
Returns the value of attribute __strict_dsl_internal_parameters.
-
#__strict_dsl_internal_returns ⇒ Object
readonly
Returns the value of attribute __strict_dsl_internal_returns.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Dsl
constructor
A new instance of Dsl.
- #method_missing(name) ⇒ Object
- #respond_to_missing?(method_name, _include_private = nil) ⇒ Boolean
- #returns ⇒ Object
- #strict_parameter ⇒ Object
Methods included from Dsl::Validatable
#AllOf, #AnyOf, #Anything, #ArrayOf, #Boolean, #HashOf, #RangeOf
Methods included from Dsl::Coercible
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/strict/methods/dsl.rb', line 46 def method_missing(name, *, **) if respond_to_missing?(name) strict_parameter(name, *, **) else super end end |
Instance Attribute Details
#__strict_dsl_internal_parameters ⇒ Object (readonly)
Returns the value of attribute __strict_dsl_internal_parameters.
20 21 22 |
# File 'lib/strict/methods/dsl.rb', line 20 def __strict_dsl_internal_parameters @__strict_dsl_internal_parameters end |
#__strict_dsl_internal_returns ⇒ Object
Returns the value of attribute __strict_dsl_internal_returns.
20 21 22 |
# File 'lib/strict/methods/dsl.rb', line 20 def __strict_dsl_internal_returns @__strict_dsl_internal_returns end |
Class Method Details
.run ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/strict/methods/dsl.rb', line 7 def run(&) dsl = new dsl.instance_eval(&) ::Strict::Methods::Configuration.new( parameters: dsl.__strict_dsl_internal_parameters.values, returns: dsl.__strict_dsl_internal_returns ) end |
Instance Method Details
#respond_to_missing?(method_name, _include_private = nil) ⇒ Boolean
54 55 56 57 |
# File 'lib/strict/methods/dsl.rb', line 54 def respond_to_missing?(method_name, _include_private = nil) first_letter = method_name.to_s.each_char.first first_letter.eql?(first_letter.downcase) end |
#returns ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/strict/methods/dsl.rb', line 28 def returns(*, **) ::Kernel.raise ::ArgumentError, "Return value is already declared" if @__strict_dsl_internal_returns_declared self.__strict_dsl_internal_returns = ::Strict::Return.make(*, **) @__strict_dsl_internal_returns_declared = true nil end |
#strict_parameter ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/strict/methods/dsl.rb', line 36 def strict_parameter(*, **) parameter = ::Strict::Parameter.make(*, **) if __strict_dsl_internal_parameters.key?(parameter.name) ::Kernel.raise ::ArgumentError, "Parameter #{parameter.name.inspect} is already declared" end __strict_dsl_internal_parameters[parameter.name] = parameter nil end |