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].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



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

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

Instance Attribute Details

#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)


101
102
103
# File 'lib/esse/config.rb', line 101

def cli_event_listeners?
  true
end

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



65
66
67
68
69
70
71
72
73
# File 'lib/esse/config.rb', line 65

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



61
62
63
# File 'lib/esse/config.rb', line 61

def cluster_ids
  @clusters.keys
end

#load(arg) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/esse/config.rb', line 84

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