Module: SolrMakr::Utility
- Included in:
- AbstractRunner, Commands::AbstractCommand, Commands::Execute, Configsets::Directory, Configsets::GetNodes, Configuration
- Defined in:
- lib/solr_makr/meta/utility.rb
Constant Summary collapse
- REQUIRED_SOLR_NODES =
These are the minimum files required to configure a collection.
%w[schema.xml solrconfig.xml]
Class Method Summary collapse
- .default_table(collection:, if_blank: 'n/a', **table_options) {|t, item| ... } ⇒ Terminal::Table
- .default_table_options!(**table_options) ⇒ Object
- .hash_to_table(hsh, if_blank: 'n/a', **table_options) ⇒ Object
- .looks_like_a_valid_configset?(conf_path) {|name| ... } ⇒ Boolean
-
.path_to_configset(root) ⇒ Pathname?
It’s possible the root directory is not what actually contains the nodes for configuring solr (e.g. files are in a ‘conf` directory).
Class Method Details
.default_table(collection:, if_blank: 'n/a', **table_options) {|t, item| ... } ⇒ Terminal::Table
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/solr_makr/meta/utility.rb', line 26 def default_table(collection:, if_blank: 'n/a', **, &formatter) = () return if_blank if collection.blank? Terminal::Table.new do |t| collection.each do |item| if block_given? if formatter.arity == 2 formatter.call(t, item) else t << yield(item) end elsif item.respond_to? :to_table_row t << item.to_table_row else t << Array(item) end end end end |
.default_table_options!(**table_options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/solr_makr/meta/utility.rb', line 8 def (**) [:style] ||= {} width = .delete(:width) unless width == false [:style].reverse_merge! width: width || 80 end return end |
.hash_to_table(hsh, if_blank: 'n/a', **table_options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/solr_makr/meta/utility.rb', line 48 def hash_to_table(hsh, if_blank: 'n/a', **) hsh = hsh.to_h = () if hsh.present? Terminal::Table.new do |t| hsh.each do |key, value| t << [key.inspect, value.inspect] end end else if_blank end end |
.looks_like_a_valid_configset?(conf_path) {|name| ... } ⇒ Boolean
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/solr_makr/meta/utility.rb', line 83 def looks_like_a_valid_configset?(conf_path) if conf_path.present? && conf_path.try(:exist?) missing = REQUIRED_SOLR_NODES.reject do |file| conf_path.join(file).exist? end missing.each do |name| yield name if block_given? end return missing.none? else false end end |
.path_to_configset(root) ⇒ Pathname?
It’s possible the root directory is not what actually contains the nodes for configuring solr (e.g. files are in a ‘conf` directory). For now let’s use ‘Pathname#find` to figure it out.
71 72 73 74 75 76 77 |
# File 'lib/solr_makr/meta/utility.rb', line 71 def path_to_configset(root) root.find do |path| return path.dirname if path.basename.to_s.in?(REQUIRED_SOLR_NODES) end return nil end |