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.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
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.
-
#url ⇒ Object
Get a (likely) URL to the solr instance.
-
#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.
30 31 32 |
# File 'lib/solr_wrapper/instance.rb', line 30 def initialize( = {}) @options = 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 @options end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
13 14 15 |
# File 'lib/solr_wrapper/instance.rb', line 13 def pid @pid end |
Instance Method Details
#clean! ⇒ Object
Clean up any files solr_wrapper may have downloaded
127 128 129 130 131 132 133 134 |
# File 'lib/solr_wrapper/instance.rb', line 127 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
90 91 92 93 94 95 96 |
# File 'lib/solr_wrapper/instance.rb', line 90 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
101 102 103 |
# File 'lib/solr_wrapper/instance.rb', line 101 def delete(name, = {}) exec("delete", c: name, p: port) end |
#port ⇒ Object
Get the port this Solr instance is running at
121 122 123 |
# File 'lib/solr_wrapper/instance.rb', line 121 def port .fetch(:port, "8983").to_s end |
#start ⇒ Object
Start Solr and wait for it to become available
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/solr_wrapper/instance.rb', line 43 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?
81 82 83 |
# File 'lib/solr_wrapper/instance.rb', line 81 def started? !!status end |
#status ⇒ Object
Check the status of a managed Solr service
72 73 74 75 76 77 |
# File 'lib/solr_wrapper/instance.rb', line 72 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
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/solr_wrapper/instance.rb', line 57 def stop if managed? && started? exec('stop', p: port) # Wait for solr to stop while status sleep 1 end end @pid = nil end |
#url ⇒ Object
Get a (likely) URL to the solr instance
138 139 140 |
# File 'lib/solr_wrapper/instance.rb', line 138 def url "http://127.0.0.1:#{port}/solr/" end |
#with_collection(options = {}) ⇒ Object
Create a new collection, run the block, and then clean up the collection
110 111 112 113 114 115 116 117 |
# File 'lib/solr_wrapper/instance.rb', line 110 def with_collection( = {}) name = create() begin yield name ensure delete name end end |
#wrap(&_block) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/solr_wrapper/instance.rb', line 34 def wrap(&_block) start yield self ensure stop end |