Class: StubRequests::Concerns::Property::Validator

Inherits:
Object
  • Object
show all
Includes:
ArgumentValidation
Defined in:
lib/stub_requests/concerns/property/validator.rb

Overview

Class Validator provides validation for adding properties

Author:

Since:

  • 0.1.2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ArgumentValidation

#validate!, #validate_type!

Constructor Details

#initialize(name, type, default = nil, properties = {}) ⇒ Validator

Parameters:

  • name (Symbol)

    the name of the property

  • type (Class, Module)

    the type of the property

  • default (Object) (defaults to: nil)

    the default value of the property

  • properties (Hash) (defaults to: {})

    the list of currently defined properties

Since:

  • 0.1.2



70
71
72
73
74
75
# File 'lib/stub_requests/concerns/property/validator.rb', line 70

def initialize(name, type, default = nil, properties = {})
  @type       = Array(type).flatten
  @default    = default
  @name       = name
  @properties = properties || {}
end

Instance Attribute Details

#defaultObject (readonly)

Since:

  • 0.1.2



57
58
59
# File 'lib/stub_requests/concerns/property/validator.rb', line 57

def default
  @default
end

#nameObject (readonly)

Since:

  • 0.1.2



49
50
51
# File 'lib/stub_requests/concerns/property/validator.rb', line 49

def name
  @name
end

#propertiesObject (readonly)

Since:

  • 0.1.2



61
62
63
# File 'lib/stub_requests/concerns/property/validator.rb', line 61

def properties
  @properties
end

#typeObject (readonly)

Since:

  • 0.1.2



53
54
55
# File 'lib/stub_requests/concerns/property/validator.rb', line 53

def type
  @type
end

Class Method Details

.call(name, type, default, properties) ⇒ void

This method returns an undefined value.

Validates that the property can be added to the class

Parameters:

  • name (Symbol)

    the name of the property

  • type (Class, Module)

    the type of the property

  • default (Object)

    the default value of the property

  • properties (Hash)

    the list of currently defined properties

Raises:

Since:

  • 0.1.2



42
43
44
# File 'lib/stub_requests/concerns/property/validator.rb', line 42

def self.call(name, type, default, properties)
  new(name, type, default, properties).run_validations
end

Instance Method Details

#run_validationsvoid

This method returns an undefined value.

Performs all validations

Raises:

Since:

  • 0.1.2



87
88
89
90
91
# File 'lib/stub_requests/concerns/property/validator.rb', line 87

def run_validations
  validate_undefined
  validate_name
  validate_default
end