Class: GuardrailsRuby::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/guardrails_ruby/check.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Check

Returns a new instance of Check.



35
36
37
# File 'lib/guardrails_ruby/check.rb', line 35

def initialize(**options)
  @options = options
end

Class Attribute Details

.registry ⇒ Object (readonly)

Returns the value of attribute registry.



8
9
10
# File 'lib/guardrails_ruby/check.rb', line 8

def registry
  @registry
end

Instance Attribute Details

#options ⇒ Object (readonly)

Returns the value of attribute options.



33
34
35
# File 'lib/guardrails_ruby/check.rb', line 33

def options
  @options
end

Class Method Details

.check_name(name = nil) ⇒ Object

DSL: set or get the check name



11
12
13
14
15
16
17
# File 'lib/guardrails_ruby/check.rb', line 11

def check_name(name = nil)
  if name
    @check_name = name.to_sym
    Check.registry[name.to_sym] = self
  end
  @check_name
end

.direction(dir = nil) ⇒ Object

DSL: set or get the direction



20
21
22
23
24
25
# File 'lib/guardrails_ruby/check.rb', line 20

def direction(dir = nil)
  if dir
    @direction = dir.to_sym
  end
  @direction || :both
end

.lookup(name) ⇒ Object

Look up a check class by its registered name



28
29
30
# File 'lib/guardrails_ruby/check.rb', line 28

def lookup(name)
  registry[name.to_sym]
end

Instance Method Details

#call(text, context: {}) ⇒ Object

Override in subclasses

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/guardrails_ruby/check.rb', line 40

def call(text, context: {})
  raise NotImplementedError, "#{self.class}#call must be implemented"
end