Thin_Upstreams 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ coverage
7
+ rdoc
8
+ .yardoc
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in Bob.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+
2
+ Thin\_Upstreams
3
+ ================
4
+
5
+ A Ruby gem to generate .conf files with upstreams
6
+ to include in your nginx.conf. It uses your Thin
7
+ configuration files.
8
+
9
+ Installation
10
+ ------------
11
+
12
+ gem 'Thin_Upstreams'
13
+
14
+ Notes
15
+ -----
16
+
17
+ File upstreams.conf is created in current working directory.
18
+ You can't specify file output name.
19
+
20
+ Usage: In Ruby
21
+ ------
22
+
23
+ Accepts optional file globs:
24
+
25
+ require "Thin_Upstreams"
26
+
27
+ Dir.chdir("/apps") {
28
+ Thin_Upstreams()
29
+ Thin_Upstreams "*/configs/my.thin.yml", "./**/config.yml"
30
+ }
31
+
32
+ File /app/upstreams.conf is created/overwritten. You
33
+
34
+ Usage: Bash/Shell
35
+ ------
36
+
37
+ File glob arguments are optional:
38
+
39
+ cd /apps
40
+ Thin_Upstreams
41
+ Thin_Upstreams "*/configs/my.thin.yml", "./**/config.yml"
42
+
43
+ File /app/upstreams.conf is created/overwritten.
44
+
45
+ Run Tests
46
+ ---------
47
+
48
+ git clone git@github.com:da99/Thin_Upstreams.git
49
+ cd Thin_Upstreams
50
+ bundle update
51
+ bundle exec bacon spec/main.rb
52
+
53
+ "I hate writing."
54
+ -----------------------------
55
+
56
+ If you know of existing software that makes the above redundant,
57
+ please tell me. The last thing I want to do is maintain code.
58
+
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "Thin_Upstreams/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "Thin_Upstreams"
8
+ s.version = Thin_Upstreams::VERSION
9
+ s.authors = ["da99"]
10
+ s.email = ["i-hate-spam-45671204@mailinator.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{ Create upstreams conf file for Nginx. }
13
+ s.description = %q{
14
+ A Ruby gem to generate .conf files with upstreams
15
+ to include in your nginx.conf. It uses your
16
+ Thin config files: ./*/thin.yml, ./*/config/thin.yml
17
+ }
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_development_dependency 'Exit_Zero'
25
+ s.add_development_dependency 'bacon'
26
+ s.add_development_dependency 'rake'
27
+ s.add_development_dependency 'Bacon_Colored'
28
+ s.add_development_dependency 'pry'
29
+ s.add_development_dependency 'thin'
30
+
31
+ # Specify any dependencies here; for example:
32
+ # s.add_runtime_dependency 'rest-client'
33
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- ruby -*-
3
+ #
4
+
5
+
6
+ require "Thin_Upstreams"
7
+
8
+ Thin_Upstreams(*ARGV)
@@ -0,0 +1,40 @@
1
+ require 'Thin_Upstreams/version'
2
+ require "yaml"
3
+
4
+ def Thin_Upstreams glob = "./*/config/thin.yml"
5
+
6
+ str = %~\n~
7
+ arr = Dir.glob(glob).each { |file|
8
+ o = YAML::load File.read(file)
9
+ app_name = begin
10
+ pwd = File.join( File.expand_path("."), "/" )
11
+ path = File.expand_path(file)
12
+ path.sub(pwd, '').split("/").first
13
+ end
14
+
15
+ ports = Thin_Upstreams.port_to_array(o["port"], o["servers"])
16
+ str << %~
17
+ upstream #{app_name} {
18
+ #{ ports.map { |i| "server 127.0.0.1:#{i}" }.join("\n") }
19
+ }
20
+ ~
21
+ }
22
+
23
+ File.write "upstreams.conf", str
24
+ end
25
+
26
+ class Thin_Upstreams
27
+
28
+ module Class_Methods
29
+
30
+ def port_to_array raw_port, raw_num
31
+ port = Integer(raw_port)
32
+ q = Integer(raw_num)
33
+ (0...q).to_a.map { |i| port + i }
34
+ end
35
+
36
+ end # === module Class_Methods
37
+
38
+ extend Class_Methods
39
+
40
+ end # === class Thin_Upstreams
@@ -0,0 +1,3 @@
1
+ class Thin_Upstreams
2
+ VERSION = "0.1.0"
3
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.print e.message, "\n"
7
+ $stderr.print "Run `bundle install` to install missing gems\n"
8
+ exit e.status_code
9
+ end
10
+ require 'bacon'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+
15
+ Bacon.summary_on_exit
data/spec/main.rb ADDED
@@ -0,0 +1,56 @@
1
+
2
+ require File.expand_path('spec/helper')
3
+ require 'Thin_Upstreams'
4
+ require 'Bacon_Colored'
5
+ require 'pry'
6
+ require 'Exit_Zero'
7
+
8
+ DIR = "/tmp/Thin_Upstreams"
9
+
10
+ def reset_dir
11
+ Exit_Zero "rm -rf #{DIR}"
12
+
13
+ Exit_Zero "mkdir -p #{DIR}/Hi/config"
14
+ Exit_Zero "mkdir -p #{DIR}/Hi/custom"
15
+
16
+ Exit_Zero "mkdir -p #{DIR}/Hello/config"
17
+ Exit_Zero "mkdir -p #{DIR}/Hello/custom"
18
+
19
+ chdir {
20
+ Exit_Zero "cd Hi/config && bundle exec thin config -C thin.yml --port 3010 --servers 2"
21
+ Exit_Zero "cd Hello/config && bundle exec thin config -C thin.yml --port 4010 --servers 3"
22
+
23
+ Exit_Zero "cd Hi/custom && bundle exec thin config -C my.yml --port 6010 --servers 4"
24
+ Exit_Zero "cd Hello/custom && bundle exec thin config -C my.yml --port 7010 --servers 5"
25
+ }
26
+ end
27
+
28
+ def reset_file
29
+ chdir {
30
+ file = "upstreams.conf"
31
+ Exit_Zero "rm #{file}" if File.exists?(file)
32
+ }
33
+ end
34
+
35
+ def chdir
36
+ Dir.chdir(DIR) {
37
+ yield
38
+ }
39
+ end
40
+
41
+ shared "file_maker" do
42
+
43
+ before {
44
+ reset_file
45
+ }
46
+
47
+ end
48
+
49
+ # ======== Include the tests.
50
+ if ARGV.size > 1 && ARGV[1, ARGV.size - 1].detect { |a| File.exists?(a) }
51
+ # Do nothing. Bacon grabs the file.
52
+ else
53
+ Dir.glob('spec/tests/*.rb').each { |file|
54
+ require File.expand_path(file.sub('.rb', '')) if File.file?(file)
55
+ }
56
+ end
data/spec/tests/bin.rb ADDED
@@ -0,0 +1,34 @@
1
+
2
+ bins = Dir.glob("bin/*")
3
+
4
+ describe "permissions of bin/" do
5
+ bins.each { |file|
6
+ it "should chmod 755 for: #{file}" do
7
+ `stat -c %a #{file}`.strip
8
+ .should.be == "755"
9
+ end
10
+ }
11
+ end # === permissions of bin/
12
+
13
+ describe "Thin_Upstreams (bin executable)" do
14
+
15
+ behaves_like "file_maker"
16
+
17
+ it "creates upstreams.conf file" do
18
+ target = "upstream Hi"
19
+ chdir {
20
+ Exit_Zero "Thin_Upstreams"
21
+ File.read("upstreams.conf")[target].should == target
22
+ }
23
+ end
24
+
25
+ it "accepts a file glob" do
26
+ target = ":601"
27
+ chdir {
28
+ Exit_Zero "Thin_Upstreams \"*/custom/*.yml\""
29
+ File.read("upstreams.conf")[target].should == target
30
+ }
31
+ end
32
+
33
+ end # === Thin_Upstreams (bin executable)
34
+
@@ -0,0 +1,34 @@
1
+
2
+ describe "Thin_Upstreams" do
3
+
4
+ behaves_like "file_maker"
5
+
6
+ it "creates upstreams.conf file" do
7
+ chdir {
8
+ Thin_Upstreams()
9
+ File.file?("upstreams.conf").should == true
10
+ }
11
+ end
12
+
13
+ it "generates content based on: */config/thin.yml" do
14
+ target = "upstream Hi"
15
+ chdir {
16
+ Thin_Upstreams()
17
+ File.read("upstreams.conf")[target].should == target
18
+ %w{ 3010 3011 4010 4011 4012 }.each { |port|
19
+ File.read("upstreams.conf")[":#{port}"].should == ":#{port}"
20
+ }
21
+ }
22
+ end
23
+
24
+ it "allows custom file globs" do
25
+ chdir {
26
+ Thin_Upstreams "*/custom/my.yml"
27
+ %w{ 6010 6011 6012 7010 7011 7012 }.each { |port|
28
+ File.read("upstreams.conf")[":#{port}"].should == ":#{port}"
29
+ }
30
+ }
31
+ end
32
+
33
+ end # === Thin_Upstreams
34
+
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Thin_Upstreams
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - da99
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: Exit_Zero
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bacon
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: Bacon_Colored
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: thin
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: ! "\n A Ruby gem to generate .conf files with upstreams\n to include
111
+ in your nginx.conf. It uses your\n Thin config files: ./*/thin.yml, ./*/config/thin.yml\n
112
+ \ "
113
+ email:
114
+ - i-hate-spam-45671204@mailinator.com
115
+ executables:
116
+ - Thin_Upstreams
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .gitignore
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - Thin_Upstreams.gemspec
125
+ - bin/Thin_Upstreams
126
+ - lib/Thin_Upstreams.rb
127
+ - lib/Thin_Upstreams/version.rb
128
+ - spec/helper.rb
129
+ - spec/main.rb
130
+ - spec/tests/bin.rb
131
+ - spec/tests/create.rb
132
+ homepage: ''
133
+ licenses: []
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 1.8.19
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: Create upstreams conf file for Nginx.
156
+ test_files: []