Class: SmartCore::Validator::Attribute Private

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_core/validator/attribute.rb

Overview

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

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default_value = nil) ⇒ 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.

Parameters:

  • name (String, Symbol)
  • default_value (Proc, Object) (defaults to: nil)

Since:

  • 0.1.0



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/smart_core/validator/attribute.rb', line 18

def initialize(name, default_value = nil)
  unless name.is_a?(Symbol) || name.is_a?(String)
    raise(
      SmartCore::Validator::IncorrectAttributeNameError,
      'Attribute name should be a symbol or a string'
    )
  end

  @name = name.to_sym
  @default_value = default_value
end

Instance Attribute Details

#nameSymbol (readonly)

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:

  • (Symbol)

Since:

  • 0.1.0



10
11
12
# File 'lib/smart_core/validator/attribute.rb', line 10

def name
  @name
end

Instance Method Details

#default_valueAny

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:

  • (Any)

Since:

  • 0.1.0



34
35
36
# File 'lib/smart_core/validator/attribute.rb', line 34

def default_value
  @default_value.is_a?(Proc) ? @default_value.call : @default_value
end

#dupSmartCore::Validator::Attribute

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



42
43
44
# File 'lib/smart_core/validator/attribute.rb', line 42

def dup
  self.class.new(name, @default_value)
end