Module: SmartCore::Validator::DSL Private

Included in:
SmartCore::Validator
Defined in:
lib/smart_core/validator/dsl.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base_klass) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • base_klass (Class)

Since:

  • 0.1.0



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/smart_core/validator/dsl.rb', line 13

def extended(base_klass)
  base_klass.instance_variable_set(:@__commands__, CommandSet.new)
  base_klass.instance_variable_set(:@__attributes__, AttributeSet.new)

  base_klass.singleton_class.prepend(Module.new do
    def inherited(child_klass)
      child_klass.instance_variable_set(:@__commands__, CommandSet.new)
      child_klass.instance_variable_set(:@__attributes__, AttributeSet.new)

      child_klass.commands.concat(commands)
      child_klass.attributes.concat(attributes)

      super(child_klass)
    end
  end)
end

Instance Method Details

#attribute(attribute_name, default: nil) ⇒ void

This method returns an undefined value.

Parameters:

  • attribute_name (String, Symbol)

Since:

  • 0.1.0



36
37
38
39
40
# File 'lib/smart_core/validator/dsl.rb', line 36

def attribute(attribute_name, default: nil)
  attribute = SmartCore::Validator::Attribute.new(attribute_name, default)
  attributes << attribute
  attr_reader attribute.name
end

#attributesSmartCore::Validator::AttributeSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 0.1.0



46
47
48
# File 'lib/smart_core/validator/dsl.rb', line 46

def attributes
  @__attributes__
end

#clear_commandsvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Since:

  • 0.1.0



62
63
64
# File 'lib/smart_core/validator/dsl.rb', line 62

def clear_commands
  commands.clear
end

#commandsSmartCore::Validator::CommandSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 0.1.0



54
55
56
# File 'lib/smart_core/validator/dsl.rb', line 54

def commands
  @__commands__
end

#validate(validating_method, &nested_validations) ⇒ void

This method returns an undefined value.

Parameters:

  • validating_method (Symbol, String)
  • nested_validations (Proc)

See Also:

Since:

  • 0.1.0



75
76
77
78
79
80
81
# File 'lib/smart_core/validator/dsl.rb', line 75

def validate(validating_method, &nested_validations)
  if block_given?
    commands << Commands::AddNestedValidations.new(validating_method, nested_validations)
  else
    commands << Commands::AddValidation.new(validating_method)
  end
end

#validate_with(validating_klass, &nested_validations) ⇒ void

This method returns an undefined value.

Parameters:

See Also:

Since:

  • 0.1.0



91
92
93
# File 'lib/smart_core/validator/dsl.rb', line 91

def validate_with(validating_klass, &nested_validations)
  commands << Commands::ValidateWith.new(validating_klass, nested_validations)
end