Class: Esse::Config

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

Overview

Provides all configurations

Example

Esse.config do |conf|
  conf.indices_directory = 'app/indices'
end

Constant Summary collapse

DEFAULT_CLUSTER_ID =
:default
ATTRIBUTES =
%i[indices_directory bulk_wait_interval bulk_retry_on_failure_max_retries bulk_retry_on_failure_wait].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

def initialize
  self.indices_directory = 'app/indices'
  self.bulk_wait_interval = 0.1
  self.bulk_retry_on_failure_max_retries = 3
  self.bulk_retry_on_failure_wait = 2.0
  @clusters = {}
  cluster(DEFAULT_CLUSTER_ID) # initialize the :default client
end

Instance Attribute Details

#bulk_retry_on_failure_max_retriesObject

number of retries on transient server errors (502, 503, 504, 429) before raising



55
56
57
# File 'lib/esse/config.rb', line 55

def bulk_retry_on_failure_max_retries
  @bulk_retry_on_failure_max_retries
end

#bulk_retry_on_failure_waitObject

base wait in seconds between transient-error retries (doubles each attempt)



58
59
60
# File 'lib/esse/config.rb', line 58

def bulk_retry_on_failure_wait
  @bulk_retry_on_failure_wait
end

#bulk_wait_intervalObject

wait a given period between posting pages to give Elasticsearch time to catch up.



52
53
54
# File 'lib/esse/config.rb', line 52

def bulk_wait_interval
  @bulk_wait_interval
end

#indices_directoryObject

The location of the indices. Defaults to the ‘app/indices`



49
50
51
# File 'lib/esse/config.rb', line 49

def indices_directory
  @indices_directory
end

Instance Method Details

#cli_event_listeners?Boolean

:nodoc: This is only used by rspec to disable the CLI print out.

Returns:

  • (Boolean)


117
118
119
# File 'lib/esse/config.rb', line 117

def cli_event_listeners?
  true
end

#cluster(key = DEFAULT_CLUSTER_ID, **options) ⇒ Object Also known as: clusters



73
74
75
76
77
78
79
80
81
# File 'lib/esse/config.rb', line 73

def cluster(key = DEFAULT_CLUSTER_ID, **options)
  return unless key

  id = key.to_sym
  (@clusters[id] ||= Cluster.new(id: id)).tap do |c|
    c.assign(options) if options
    yield c if block_given?
  end
end

#cluster_idsObject



69
70
71
# File 'lib/esse/config.rb', line 69

def cluster_ids
  @clusters.keys
end

#load(arg) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/esse/config.rb', line 100

def load(arg)
  case arg
  when Hash
    assign(arg)
  when File, Pathname
    assign(YAML.load_file(arg))
  when String
    return load(Pathname.new(arg)) if File.exist?(arg)

    assign(YAML.safe_load(arg))
  else
    raise ArgumentError, printf('could not load configuration using: %p', val)
  end
end