Class: Traject::Indexer::Settings
- Inherits:
-
Hash
- Object
- Hash
- Traject::Indexer::Settings
- Includes:
- Hashie::Extensions::IndifferentAccess, Hashie::Extensions::MergeInitializer
- Defined in:
- lib/traject/indexer/settings.rb
Overview
A Hash of settings for a Traject::Indexer, which also ends up passed along to other objects Traject::Indexer interacts with.
Enhanced with a few features from Hashie, to make it for instance string/symbol indifferent
method #provide(key, value) is added, to do like settings[key] ||= value, set only if not already set (but unlike ||=, nil or false can count as already set)
Also has an interesting 'defaults' system, meant to play along with configuration file 'provide' statements. There is a built-in hash of defaults, which will be lazily filled in if accessed and not yet set. (nil can count as set, though!). If they haven't been lazily set yet, then #provide will still fill them in. But you can also call fill_in_defaults! to fill all defaults in, if you know configuration files have all been loaded, and want to fill them in for inspection.
Class Method Summary collapse
Instance Method Summary collapse
- #fill_in_defaults! ⇒ Object
-
#initialize(*args) ⇒ Settings
constructor
A new instance of Settings.
- #inspect ⇒ Object
-
#provide(key, value) ⇒ Object
a cautious store, which only saves key=value if there was not already a value for #key.
-
#reverse_merge(other_hash) ⇒ Object
reverse_merge copied from ActiveSupport, pretty straightforward, modified to make sure we return a Settings.
- #reverse_merge!(other_hash) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Settings
Returns a new instance of Settings.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/traject/indexer/settings.rb', line 28 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
.defaults ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/traject/indexer/settings.rb', line 63 def self.defaults @@defaults ||= { "reader_class_name" => "Traject::MarcReader", "writer_class_name" => "Traject::SolrJWriter", "marc_source.type" => "binary", "marc4j_reader.permissive" => true, "solrj_writer.batch_size" => 200, "solrj_writer.thread_pool" => 1, "processing_thread_pool" => 3, "log.batch_size.severity" => "info" } end |
Instance Method Details
#fill_in_defaults! ⇒ Object
59 60 61 |
# File 'lib/traject/indexer/settings.rb', line 59 def fill_in_defaults! self.reverse_merge!(self.class.defaults) end |
#inspect ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/traject/indexer/settings.rb', line 76 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.
43 44 45 46 47 |
# File 'lib/traject/indexer/settings.rb', line 43 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
51 52 53 |
# File 'lib/traject/indexer/settings.rb', line 51 def reverse_merge(other_hash) self.class.new(other_hash).merge(self) end |
#reverse_merge!(other_hash) ⇒ Object
55 56 57 |
# File 'lib/traject/indexer/settings.rb', line 55 def reverse_merge!(other_hash) replace(reverse_merge(other_hash)) end |