Class: Diogenes::DSL::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/diogenes/dsl/hook.rb,
sig/generated/diogenes/dsl/hook.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Hook

: (String, ?Proc) -> void

Parameters:

  • (String)
  • (Proc)


10
11
12
13
14
# File 'lib/diogenes/dsl/hook.rb', line 10

def initialize(name, &block)
  @name = name #: String
  instance_eval(&block) if block_given?
  validate!
end

Instance Attribute Details

#nameString (readonly)

: String

Returns:

  • (String)


7
8
9
# File 'lib/diogenes/dsl/hook.rb', line 7

def name
  @name
end

Instance Method Details

#prompt(value = nil) ⇒ String?

: (?String?) -> String?

Parameters:

  • (String, nil)

Returns:

  • (String, nil)


23
24
25
26
# File 'lib/diogenes/dsl/hook.rb', line 23

def prompt(value = nil)
  @prompt = value unless value.nil?
  @prompt
end

#trigger(value = nil) ⇒ String?

: (?String?) -> String?

Parameters:

  • (String, nil)

Returns:

  • (String, nil)


17
18
19
20
# File 'lib/diogenes/dsl/hook.rb', line 17

def trigger(value = nil)
  @trigger = value unless value.nil?
  @trigger
end

#validate!void

This method returns an undefined value.

: () -> void



31
32
33
34
35
36
37
38
39
# File 'lib/diogenes/dsl/hook.rb', line 31

def validate!
  missing = %i[trigger prompt].reject { |f| instance_variable_get(:"@#{f}") }
  return if missing.empty?

  raise Diogenes::ConfigurationError,
    "Hook #{@name.inspect} is missing required " \
    "field#{"s" if missing.size > 1}: #{missing.join(", ")}. " \
    "A hook requires: trigger and prompt."
end