Class: Strict::Attributes::Dsl

Inherits:
BasicObject
Includes:
Dsl::Coercible, Dsl::Validatable
Defined in:
lib/strict/attributes/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.



19
20
21
# File 'lib/strict/attributes/dsl.rb', line 19

def initialize
  @__strict_dsl_internal_attributes = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



29
30
31
32
33
34
35
# File 'lib/strict/attributes/dsl.rb', line 29

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

Instance Attribute Details

#__strict_dsl_internal_attributesObject (readonly)

Returns the value of attribute __strict_dsl_internal_attributes.



17
18
19
# File 'lib/strict/attributes/dsl.rb', line 17

def __strict_dsl_internal_attributes
  @__strict_dsl_internal_attributes
end

Class Method Details

.run(&block) ⇒ Object



7
8
9
10
11
# File 'lib/strict/attributes/dsl.rb', line 7

def run(&block)
  dsl = new
  dsl.instance_eval(&block)
  ::Strict::Attributes::Configuration.new(attributes: dsl.__strict_dsl_internal_attributes.values)
end

Instance Method Details

#respond_to_missing?(method_name, _include_private = nil) ⇒ Boolean

Returns:



37
38
39
40
# File 'lib/strict/attributes/dsl.rb', line 37

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

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



23
24
25
26
27
# File 'lib/strict/attributes/dsl.rb', line 23

def strict_attribute(*args, **kwargs)
  attribute = ::Strict::Attribute.make(*args, **kwargs)
  __strict_dsl_internal_attributes[attribute.name] = attribute
  nil
end