Class: Esse::Index::RequestConfigurable::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/esse/index/request_configurable.rb

Instance Method Summary collapse

Constructor Details

#initializeContainer

Returns a new instance of Container.



41
42
43
44
# File 'lib/esse/index/request_configurable.rb', line 41

def initialize
  @mutex = Mutex.new
  @entries = {}.freeze
end

Instance Method Details

#add(operation, entry) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/esse/index/request_configurable.rb', line 46

def add(operation, entry)
  @mutex.synchronize do
    hash = @entries.dup
    arr = (hash[operation] || []).dup
    arr << entry
    hash[operation] = arr.freeze
    @entries = hash.freeze
  end
end

#key?(operation) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/esse/index/request_configurable.rb', line 56

def key?(operation)
  @entries.key?(operation)
end

#retrieve(operation, doc) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/esse/index/request_configurable.rb', line 60

def retrieve(operation, doc)
  return {} unless @entries[operation]

  @entries[operation].each_with_object({}) do |entry, hash|
    hash.merge!(entry.call(doc))
  end
end