Class: Neo4jTest::Installer
- Inherits:
- 
      Object
      
        - Object
- Neo4jTest::Installer
 
- Defined in:
- lib/neo4j_test_server/installer.rb
Constant Summary collapse
- BadEditionError =
- Class.new(RuntimeError) 
Class Method Summary collapse
- .bootstrap(edition) ⇒ Object
- .config(source_text, port) ⇒ Object
- .config_location ⇒ Object
- .download_neo4j(edition) ⇒ Object
- .download_neo4j_unless_exists(edition) ⇒ Object
- .download_to(edition = '') ⇒ Object
- .download_url(edition) ⇒ Object
- .file_name(edition = '') ⇒ Object
- .get_environment ⇒ Object
- 
  
    
      .here  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Defining a method that represents the current location of this file for testing purposes since I cant seem to be able to mock out “__FILE__” in the rspec tests. 
- .install_location ⇒ Object
- .rake_auth_toggle(status) ⇒ Object
- .request_url(url) ⇒ Object
- .set_property(source_text, property, value) ⇒ Object
- 
  
    
      .toggle_auth(status, source_text)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Toggles the status of Neo4j 2.2’s basic auth. 
- .unzip_neo4j(edition) ⇒ Object
Class Method Details
.bootstrap(edition) ⇒ Object
| 10 11 12 13 14 15 16 | # File 'lib/neo4j_test_server/installer.rb', line 10 def bootstrap(edition) raise BadEditionError if edition.empty? download_neo4j_unless_exists edition unzip_neo4j edition rake_auth_toggle :disable end | 
.config(source_text, port) ⇒ Object
| 113 114 115 116 | # File 'lib/neo4j_test_server/installer.rb', line 113 def config(source_text, port) s = set_property(source_text, 'org.neo4j.server.webserver.https.enabled', 'false') set_property(s, 'org.neo4j.server.webserver.port', port) end | 
.config_location ⇒ Object
| 102 103 104 | # File 'lib/neo4j_test_server/installer.rb', line 102 def config_location "#{install_location}/conf/neo4j-server.properties" end | 
.download_neo4j(edition) ⇒ Object
| 39 40 41 42 43 44 45 46 47 48 49 50 | # File 'lib/neo4j_test_server/installer.rb', line 39 def download_neo4j(edition) success = false File.open(download_to(edition), 'wb') do |file| file << request_url(download_url(edition)) success = true end download_to(edition) ensure File.delete(file_name) unless success end | 
.download_neo4j_unless_exists(edition) ⇒ Object
| 34 35 36 37 | # File 'lib/neo4j_test_server/installer.rb', line 34 def download_neo4j_unless_exists(edition) download_neo4j(edition) unless File.exist?(download_to(edition)) download_to(edition) end | 
.download_to(edition = '') ⇒ Object
| 25 26 27 28 | # File 'lib/neo4j_test_server/installer.rb', line 25 def download_to(edition = '') # We want to ensure that we download the Neo4j archive to the gem location. Not the project's location File.join(File.dirname(here), file_name(edition)) end | 
.download_url(edition) ⇒ Object
| 30 31 32 | # File 'lib/neo4j_test_server/installer.rb', line 30 def download_url(edition) "http://dist.neo4j.org/neo4j-#{edition}-#{OS::Underlying.windows? ? 'windows.zip' : 'unix.tar.gz'}" end | 
.file_name(edition = '') ⇒ Object
| 18 19 20 21 22 23 | # File 'lib/neo4j_test_server/installer.rb', line 18 def file_name(edition = '') suffix = OS::Underlying.windows? ? 'neo4j.zip' : 'neo4j-unix.tar.gz' prefix = edition.empty? ? '' : "#{edition}-" [prefix, suffix].join '' end | 
.get_environment ⇒ Object
| 92 93 94 | # File 'lib/neo4j_test_server/installer.rb', line 92 def get_environment 'development' end | 
.here ⇒ Object
Defining a method that represents the current location of this file for testing purposes since I cant seem to be able to mock out “__FILE__” in the rspec tests. I CAN however mock out this method during testing… :-)
| 134 135 136 | # File 'lib/neo4j_test_server/installer.rb', line 134 def here __FILE__ end | 
.install_location ⇒ Object
| 96 97 98 99 100 | # File 'lib/neo4j_test_server/installer.rb', line 96 def install_location path = File.('../../../tmp/db/neo4j', __FILE__) FileUtils.mkdir_p(path) "#{path}/#{get_environment}" end | 
.rake_auth_toggle(status) ⇒ Object
| 106 107 108 109 110 111 | # File 'lib/neo4j_test_server/installer.rb', line 106 def rake_auth_toggle(status) location = config_location text = File.read(location) replace = toggle_auth(status, text) File.open(location, 'w') { |file| file.puts replace } end | 
.request_url(url) ⇒ Object
| 85 86 87 88 89 90 | # File 'lib/neo4j_test_server/installer.rb', line 85 def request_url(url) status = HTTParty.head(url).code fail "#{edition} is not available to download, try a different version" if status < 200 || status >= 300 HTTParty.get(url) end | 
.set_property(source_text, property, value) ⇒ Object
| 118 119 120 | # File 'lib/neo4j_test_server/installer.rb', line 118 def set_property(source_text, property, value) source_text.gsub(/#{property}\s*=\s*(\w+)/, "#{property}=#{value}") end | 
.toggle_auth(status, source_text) ⇒ Object
Toggles the status of Neo4j 2.2’s basic auth
| 123 124 125 126 127 128 129 | # File 'lib/neo4j_test_server/installer.rb', line 123 def toggle_auth(status, source_text) status_string = status == :enable ? 'true' : 'false' %w(dbms.security.authorization_enabled dbms.security.auth_enabled).each do |key| source_text = set_property(source_text, key, status_string) end source_text end | 
.unzip_neo4j(edition) ⇒ Object
| 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | # File 'lib/neo4j_test_server/installer.rb', line 52 def unzip_neo4j(edition) downloaded_file = download_to(edition) if OS::Underlying.windows? # Extract and move to neo4j directory unless File.exist?(install_location) Zip::ZipFile.open(downloaded_file) do |zip_file| zip_file.each do |f| f_path = File.join('.', f.name) FileUtils.mkdir_p(File.dirname(f_path)) begin zip_file.extract(f, f_path) unless File.exist?(f_path) rescue puts "#{f.name} failed to extract." end end end FileUtils.mv "neo4j-#{edition}", install_location end # Install if running with Admin Privileges if `reg query "HKU\\S-1-5-19"`.size > 0 `"#{install_location}/bin/neo4j install"` puts 'Neo4j Installed as a service.' end else `tar -xvf #{downloaded_file}` `mv neo4j-#{edition} #{install_location}` puts 'Neo4j Installed in to neo4j directory.' end end |