Class: Pakyow::Validations::Inline Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pakyow/validations/inline.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.

Wraps an inline validation proc so that we know its given name.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, block) ⇒ Inline

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 a new instance of Inline.


15
16
17
# File 'lib/pakyow/validations/inline.rb', line 15

def initialize(name, block)
  @name, @block = name, block
end

Instance Attribute Details

#nameObject (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.


13
14
15
# File 'lib/pakyow/validations/inline.rb', line 13

def name
  @name
end

Instance Method Details

#messageObject

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.


19
20
21
# File 'lib/pakyow/validations/inline.rb', line 19

def message(**)
  "is invalid"
end

#valid?(value, context: nil) ⇒ Boolean

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:

  • (Boolean)

23
24
25
26
27
28
29
# File 'lib/pakyow/validations/inline.rb', line 23

def valid?(value, context: nil, **)
  if context
    context.instance_exec(value, &@block)
  else
    @block.call(value)
  end
end