Class: Featurevisor::Hooks::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/featurevisor/hooks.rb

Overview

Hook interface for extending evaluation behavior

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Hook

Initialize a new hook

Parameters:

  • options (Hash)

    Hook options

Options Hash (options):

  • :name (String)

    Hook name

  • :before (Proc, nil)

    Before evaluation hook

  • :bucket_key (Proc, nil)

    Bucket key configuration hook

  • :bucket_value (Proc, nil)

    Bucket value configuration hook

  • :after (Proc, nil)

    After evaluation hook



17
18
19
20
21
22
23
# File 'lib/featurevisor/hooks.rb', line 17

def initialize(options)
  @name = options[:name]
  @before = options[:before]
  @bucket_key = options[:bucket_key]
  @bucket_value = options[:bucket_value]
  @after = options[:after]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/featurevisor/hooks.rb', line 8

def name
  @name
end

Instance Method Details

#call_after(evaluation, options) ⇒ Hash

Call the after hook if defined

Parameters:

  • evaluation (Hash)

    Evaluation result

  • options (Hash)

    Evaluation options

Returns:

  • (Hash)

    Modified evaluation result



56
57
58
59
60
# File 'lib/featurevisor/hooks.rb', line 56

def call_after(evaluation, options)
  return evaluation unless @after

  @after.call(evaluation, options)
end

#call_before(options) ⇒ Hash

Call the before hook if defined

Parameters:

  • options (Hash)

    Evaluation options

Returns:

  • (Hash)

    Modified evaluation options



28
29
30
31
32
# File 'lib/featurevisor/hooks.rb', line 28

def call_before(options)
  return options unless @before

  @before.call(options)
end

#call_bucket_key(options) ⇒ String

Call the bucket key hook if defined

Parameters:

  • options (Hash)

    Bucket key options

Returns:

  • (String)

    Modified bucket key



37
38
39
40
41
# File 'lib/featurevisor/hooks.rb', line 37

def call_bucket_key(options)
  return options[:bucket_key] unless @bucket_key

  @bucket_key.call(options)
end

#call_bucket_value(options) ⇒ Integer

Call the bucket value hook if defined

Parameters:

  • options (Hash)

    Bucket value options

Returns:

  • (Integer)

    Modified bucket value



46
47
48
49
50
# File 'lib/featurevisor/hooks.rb', line 46

def call_bucket_value(options)
  return options[:bucket_value] unless @bucket_value

  @bucket_value.call(options)
end