Class: Traject::Indexer::Settings

Inherits:
Hash
  • Object
show all
Includes:
Hashie::Extensions::IndifferentAccess, Hashie::Extensions::MergeInitializer
Defined in:
lib/traject/indexer/settings.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Settings

Returns a new instance of Settings.



27
28
29
30
31
32
33
34
35
36
# File 'lib/traject/indexer/settings.rb', line 27

def initialize(*args)
  super
  self.default_proc = lambda do |hash, key|
    if self.class.defaults.has_key?(key)
      return hash[key] = self.class.defaults[key]
    else
      return nil
    end
  end
end

Class Method Details

.defaultsObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/traject/indexer/settings.rb', line 62

def self.defaults
  @@defaults ||= {
  "reader_class_name"         => "Traject::Marc4JReader",
  "writer_class_name"         => "Traject::SolrJWriter",
  "marc_source.type"          => "binary",
  "marc4j_reader.permissive"  => true,
  "marc4j_reader.source_encoding" => "BESTGUESS",
  "solrj_writer.batch_size"   => 200,
  "solrj_writer.thread_pool"  => 1,
  "processing_thread_pool"    => 3
  }
end

Instance Method Details

#fill_in_defaults!Object



58
59
60
# File 'lib/traject/indexer/settings.rb', line 58

def fill_in_defaults!
  self.reverse_merge!(self.class.defaults)
end

#inspectObject



75
76
77
78
79
80
81
# File 'lib/traject/indexer/settings.rb', line 75

def inspect
  # Keep any key ending in password out of the inspect
  self.inject({}) do |hash, (key, value)|
    hash[key] = (key =~ /password\Z/) ? "[hidden]" : value
    hash
  end.inspect
end

#provide(key, value) ⇒ Object

a cautious store, which only saves key=value if there was not already a value for #key. Can be used to set settings that can be overridden on command line, or general first-set-wins settings.



42
43
44
45
46
# File 'lib/traject/indexer/settings.rb', line 42

def provide(key, value)
  unless has_key? key
    store(key, value)
  end
end

#reverse_merge(other_hash) ⇒ Object

reverse_merge copied from ActiveSupport, pretty straightforward, modified to make sure we return a Settings



50
51
52
# File 'lib/traject/indexer/settings.rb', line 50

def reverse_merge(other_hash)
  self.class.new(other_hash).merge(self)
end

#reverse_merge!(other_hash) ⇒ Object



54
55
56
# File 'lib/traject/indexer/settings.rb', line 54

def reverse_merge!(other_hash)
  replace(reverse_merge(other_hash))
end