thinking-sphinx-ports 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 04bfdccc29ef14537c8bd6a55a2493cbfd158cb2
4
+ data.tar.gz: b154701d70bafeb7306115be91013fcb3fe28c13
5
+ SHA512:
6
+ metadata.gz: 414968762671612f16998f4c974052c55d68ff75709a16534f396c171ec2ef0b5135728833c5c1977887321e5fa46ba2f377ef115a66d0d0a66d4a9645ca9741
7
+ data.tar.gz: 59045b2cd011d3c00b74b20eab4bc0e4021381d19677aaf7af0dfc8e58d81a4a96b0c92bd9727ff421f4e982a9f24415bf4489777cfd0beccc3d778197b6dbb8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at pat@freelancing-gods.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,44 @@
1
+ # ThinkingSphinx::Ports
2
+
3
+ Automatically assign Sphinx ports to multiple apps using Thinking Sphinx on the one machine. This is useful if you have many apps on your development machine that use Sphinx and Thinking Sphinx, and you don't want to worry about making sure the port you've assigned for it isn't being used elsewhere.
4
+
5
+ This library is aimed development and test environments - each app and environment gets a unique port, to avoid any conflicts.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'thinking-sphinx-ports', '~> 0.1.0', :groups => [:development, :test]
13
+ ```
14
+
15
+ **This gem is not meant for use in production environments.** Indeed, it may override your environment-specific settings, so make sure you be specific in the environments it should be loaded within.
16
+
17
+ ## Usage
18
+
19
+ Beyond adding it to your Gemfile, there's nothing else you need to do for Rails applications. Thinking Sphinx will automatically be assigned a unique port based on its environment and path.
20
+
21
+ If you have Sphinx daemons running on your machine already, stopping those daemons and then running `rake ts:configure ts:start` is recommended - this will have the daemon using their newly assigned port.
22
+
23
+ If you want to use this gem with non-Rails apps, then you'll want something along the lines of this code to run while you're app is booting up:
24
+
25
+ ```ruby
26
+ # for non-Rails apps only
27
+ ThinkingSphinx::Ports.call [Dir.pwd, ENV['RACK_ENV']]
28
+ ```
29
+
30
+ Modify those variables as you wish - the important part is that overall argument for `ThinkingSphinx::Ports.call` be unique for the given app and environment.
31
+
32
+ For the extra curious, the path/environment and port pairings are saved to `~/.thinking_sphinx_ports.yml`.
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pat/thinking-sphinx-ports. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
41
+
42
+ ## Licence
43
+
44
+ Copyright (c) 2016, ThinkingSphinx::Ports is developed and maintained by Pat Allan, and is released under the open MIT Licence.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "thinking_sphinx/ports"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require 'thinking_sphinx/ports'
@@ -0,0 +1,29 @@
1
+ require 'yaml'
2
+ require 'rails/railtie'
3
+ require 'thinking_sphinx'
4
+
5
+ module ThinkingSphinx::Ports
6
+ PATH = File.expand_path '~/.thinking_sphinx_ports.yml'
7
+
8
+ def self.call(key, collection = nil, configuration = nil)
9
+ collection ||= default_collection
10
+ configuration ||= ThinkingSphinx::Configuration.instance
11
+
12
+ port = collection.call key
13
+
14
+ configuration.settings['mysql41'] = port
15
+ configuration.searchd.mysql41 = port
16
+ end
17
+
18
+ def self.default_collection
19
+ @@default_collection ||= begin
20
+ Collection.new Read.new(PATH), Write.new(PATH)
21
+ end
22
+ end
23
+ end
24
+
25
+ require 'thinking_sphinx/ports/collection'
26
+ require 'thinking_sphinx/ports/key'
27
+ require 'thinking_sphinx/ports/railtie'
28
+ require 'thinking_sphinx/ports/read'
29
+ require 'thinking_sphinx/ports/write'
@@ -0,0 +1,29 @@
1
+ class ThinkingSphinx::Ports::Collection
2
+ FIRST_PORT = 9320
3
+
4
+ def initialize(reader, writer)
5
+ @reader, @writer = reader, writer
6
+ end
7
+
8
+ def call(key)
9
+ mappings[key] || next_port_for(key)
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :reader, :writer
15
+
16
+ def mappings
17
+ @mappings ||= reader.call
18
+ end
19
+
20
+ def next_port_for(key)
21
+ mappings[key] = next_port
22
+ writer.call mappings
23
+ mappings[key]
24
+ end
25
+
26
+ def next_port
27
+ (mappings.values.max || FIRST_PORT) + 1
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ class ThinkingSphinx::Ports::Key
2
+ def self.call(app)
3
+ [Rails.root.to_s, Rails.env.to_s]
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ThinkingSphinx::Ports::Railtie < Rails::Railtie
2
+ initializer "thinking_sphinx_ports.set_port" do |app|
3
+ ThinkingSphinx::Ports.call ThinkingSphinx::Ports::Key.call(app)
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ class ThinkingSphinx::Ports::Read
2
+ def initialize(path)
3
+ @path = path
4
+ end
5
+
6
+ def call
7
+ return {} unless File.exist?(path)
8
+
9
+ YAML.load File.read(path)
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :path
15
+ end
@@ -0,0 +1,13 @@
1
+ class ThinkingSphinx::Ports::Write
2
+ def initialize(path)
3
+ @path = path
4
+ end
5
+
6
+ def call(data)
7
+ File.write path, YAML.dump(data)
8
+ end
9
+
10
+ private
11
+
12
+ attr_reader :path
13
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "thinking-sphinx-ports"
4
+ spec.version = '0.1.0'
5
+ spec.authors = ["Pat Allan"]
6
+ spec.email = ["pat@freelancing-gods.com"]
7
+
8
+ spec.summary = %q{Assign unique ports to Thinking Sphinx automatically.}
9
+ spec.homepage = "http://github.com/pat/thinking-sphinx-ports"
10
+
11
+ spec.files = `git ls-files -z`.split("\x0").reject { |file|
12
+ file.match(%r{^(test|spec|features)/})
13
+ }
14
+ spec.bindir = "exe"
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_runtime_dependency 'thinking-sphinx', '~> 3.0'
19
+ spec.add_runtime_dependency 'railties'
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thinking-sphinx-ports
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pat Allan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thinking-sphinx
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - pat@freelancing-gods.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.markdown
93
+ - Gemfile
94
+ - README.markdown
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/thinking-sphinx-ports.rb
99
+ - lib/thinking_sphinx/ports.rb
100
+ - lib/thinking_sphinx/ports/collection.rb
101
+ - lib/thinking_sphinx/ports/key.rb
102
+ - lib/thinking_sphinx/ports/railtie.rb
103
+ - lib/thinking_sphinx/ports/read.rb
104
+ - lib/thinking_sphinx/ports/write.rb
105
+ - thinking-sphinx-ports.gemspec
106
+ homepage: http://github.com/pat/thinking-sphinx-ports
107
+ licenses: []
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Assign unique ports to Thinking Sphinx automatically.
129
+ test_files: []
130
+ has_rdoc: