Class: Strict::Methods::Dsl

Inherits:
BasicObject
Includes:
Dsl::Coercible, Dsl::Validatable
Defined in:
lib/strict/methods/dsl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dsl::Validatable

#AllOf, #AnyOf, #Anything, #ArrayOf, #Boolean, #HashOf, #RangeOf

Methods included from Dsl::Coercible

#ToArray, #ToHash

Constructor Details

#initializeDsl

Returns a new instance of Dsl.



22
23
24
25
# File 'lib/strict/methods/dsl.rb', line 22

def initialize
  @__strict_dsl_internal_parameters = {}
  @__strict_dsl_internal_returns = ::Strict::Return.make
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/strict/methods/dsl.rb', line 38

def method_missing(name, *args, **kwargs)
  if respond_to_missing?(name)
    strict_parameter(name, *args, **kwargs)
  else
    super
  end
end

Instance Attribute Details

#__strict_dsl_internal_parametersObject (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_returnsObject

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(&block) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/strict/methods/dsl.rb', line 7

def run(&block)
  dsl = new
  dsl.instance_eval(&block)
  ::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

Returns:



46
47
48
49
# File 'lib/strict/methods/dsl.rb', line 46

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(*args, **kwargs) ⇒ Object



27
28
29
30
# File 'lib/strict/methods/dsl.rb', line 27

def returns(*args, **kwargs)
  self.__strict_dsl_internal_returns = ::Strict::Return.make(*args, **kwargs)
  nil
end

#strict_parameter(*args, **kwargs) ⇒ Object



32
33
34
35
36
# File 'lib/strict/methods/dsl.rb', line 32

def strict_parameter(*args, **kwargs)
  parameter = ::Strict::Parameter.make(*args, **kwargs)
  __strict_dsl_internal_parameters[parameter.name] = parameter
  nil
end