Class: SolrWrapper::Instance
- Inherits:
-
Object
- Object
- SolrWrapper::Instance
- Defined in:
- lib/solr_wrapper/instance.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#clean! ⇒ Object
Clean up any files solr_wrapper may have downloaded.
-
#create(options = {}) ⇒ Object
Create a new collection in solr.
-
#delete(name, options = {}) ⇒ Object
Create a new collection in solr.
-
#initialize(options = {}) ⇒ Instance
constructor
A new instance of Instance.
-
#port ⇒ Object
Get the port this Solr instance is running at.
-
#start ⇒ Object
Start Solr and wait for it to become available.
-
#started? ⇒ Boolean
Is Solr running?.
-
#status ⇒ Object
Check the status of a managed Solr service.
-
#stop ⇒ Object
Stop Solr and wait for it to finish exiting.
-
#with_collection(options = {}) ⇒ Object
Create a new collection, run the block, and then clean up the collection.
- #wrap(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Instance
Returns a new instance of Instance.
27 28 29 |
# File 'lib/solr_wrapper/instance.rb', line 27 def initialize = {} = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/solr_wrapper/instance.rb', line 13 def end |
Instance Method Details
#clean! ⇒ Object
Clean up any files solr_wrapper may have downloaded
122 123 124 125 126 127 128 129 |
# File 'lib/solr_wrapper/instance.rb', line 122 def clean! stop FileUtils.remove_entry(download_path) if File.exists? download_path FileUtils.remove_entry(tmp_save_dir, true) if File.exists? tmp_save_dir FileUtils.remove_entry(instance_dir, true) if File.exists? instance_dir FileUtils.remove_entry(md5sum_path) if File.exists? md5sum_path FileUtils.remove_entry(version_file) if File.exists? version_file end |
#create(options = {}) ⇒ Object
Create a new collection in solr
85 86 87 88 89 90 91 |
# File 'lib/solr_wrapper/instance.rb', line 85 def create = {} [:name] ||= SecureRandom.hex exec("create", c: [:name], d: [:dir], p: port) [:name] end |
#delete(name, options = {}) ⇒ Object
Create a new collection in solr
96 97 98 |
# File 'lib/solr_wrapper/instance.rb', line 96 def delete name, = {} exec("delete", c: name, p: port) end |
#port ⇒ Object
Get the port this Solr instance is running at
116 117 118 |
# File 'lib/solr_wrapper/instance.rb', line 116 def port .fetch(:port, "8983").to_s end |
#start ⇒ Object
Start Solr and wait for it to become available
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/solr_wrapper/instance.rb', line 40 def start extract if managed? exec('start', p: port) # Wait for solr to start unless status sleep 1 end end end |
#started? ⇒ Boolean
Is Solr running?
76 77 78 |
# File 'lib/solr_wrapper/instance.rb', line 76 def started? !!status end |
#status ⇒ Object
Check the status of a managed Solr service
67 68 69 70 71 72 |
# File 'lib/solr_wrapper/instance.rb', line 67 def status return true unless managed? out = exec('status', output: true).read out =~ /running on port #{port}/ end |
#stop ⇒ Object
Stop Solr and wait for it to finish exiting
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/solr_wrapper/instance.rb', line 54 def stop if managed? and started? exec('stop', p: port) # Wait for solr to stop while status sleep 1 end end end |
#with_collection(options = {}) ⇒ Object
Create a new collection, run the block, and then clean up the collection
105 106 107 108 109 110 111 112 |
# File 'lib/solr_wrapper/instance.rb', line 105 def with_collection = {} name = create() begin yield name ensure delete name end end |
#wrap(&block) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/solr_wrapper/instance.rb', line 31 def wrap &block start yield self ensure stop end |