zenturio_batteries 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +8 -0
- data/lib/assets/.gitkeep +0 -0
- data/lib/assets/configs/unicorn.erb +33 -0
- data/lib/assets/configs/unicorn_nginx.erb +28 -0
- data/lib/tasks/.gitkeep +0 -0
- data/lib/tasks/configs.rake +20 -0
- data/lib/zenturio_batteries/base/generator.rb +59 -0
- data/lib/zenturio_batteries/configs.rb +29 -0
- data/lib/zenturio_batteries/version.rb +3 -0
- data/lib/zenturio_batteries.rb +20 -0
- data/spec/base_generator_spec.rb +27 -0
- data/spec/configs_spec.rb +33 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/zenturio_batteries_spec.rb +14 -0
- data/zenturio_batteries.gemspec +23 -0
- metadata +74 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
zenturio_batteries (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rspec (2.11.0)
|
11
|
+
rspec-core (~> 2.11.0)
|
12
|
+
rspec-expectations (~> 2.11.0)
|
13
|
+
rspec-mocks (~> 2.11.0)
|
14
|
+
rspec-core (2.11.1)
|
15
|
+
rspec-expectations (2.11.3)
|
16
|
+
diff-lcs (~> 1.1.3)
|
17
|
+
rspec-mocks (2.11.3)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
rspec
|
24
|
+
zenturio_batteries!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Andreas Sotnik <andreas.sotnik@gmail.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# ZenturioBatteries
|
2
|
+
|
3
|
+
This gem generates common parts of Ruby On Rails applications. Parts like: production configuration for several web servers, common models with migrations, some widgets, etc
|
4
|
+
|
5
|
+
Gem consist of several "batteries":
|
6
|
+
|
7
|
+
1. Production Configurations for several web servers
|
8
|
+
2. ???
|
9
|
+
|
10
|
+
Each "battery" - is a common usable part for application. Parts would be generated as part of application.
|
11
|
+
|
12
|
+
This approach has advantages (compare to usual including gem):
|
13
|
+
|
14
|
+
1. Only necessary part would be generated => reduced number of imported classes.
|
15
|
+
2. Every generated component - independent part and could be customized for every specific project.
|
16
|
+
3. No need to update parts of old application => so less compatibility dependency. But it's also a disadvantage.
|
17
|
+
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this lines to your application's Gemfile:
|
22
|
+
|
23
|
+
group :development do
|
24
|
+
gem 'zenturio_batteries'
|
25
|
+
end
|
26
|
+
|
27
|
+
Then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install zenturio_batteries
|
34
|
+
|
35
|
+
Add to Rakefile:
|
36
|
+
|
37
|
+
require "zenturio_batteries"
|
38
|
+
ZenturioBatteries.load_tasks
|
39
|
+
|
40
|
+
That's all. You ready for generating parts.
|
41
|
+
|
42
|
+
For example (generating production configuration files):
|
43
|
+
|
44
|
+
$ rake batteries:config
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
TODO: Write usage instructions here
|
49
|
+
|
data/Rakefile
ADDED
data/lib/assets/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#bundle exec unicorn_rails -c config/unicorn.rb -E production
|
2
|
+
|
3
|
+
base_path = '<%= proj_dir %>'
|
4
|
+
|
5
|
+
rails_env = ENV['RAILS_ENV'] || 'production'
|
6
|
+
|
7
|
+
worker_processes (rails_env == 'production' ? 7 : 2)
|
8
|
+
|
9
|
+
preload_app true
|
10
|
+
|
11
|
+
timeout 30
|
12
|
+
|
13
|
+
listen base_path+'/tmp/sockets/unicorn.sock', :backlog => 2048
|
14
|
+
|
15
|
+
before_fork do |server, worker|
|
16
|
+
|
17
|
+
defined?(ActiveRecord::Base) and
|
18
|
+
ActiveRecord::Base.connection.disconnect!
|
19
|
+
|
20
|
+
old_pid = base_path + '/tmp/pids/unicorn.pid.oldbin'
|
21
|
+
if File.exists?(old_pid) && server.pid != old_pid
|
22
|
+
begin
|
23
|
+
Process.kill("QUIT", File.read(old_pid).to_i)
|
24
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
25
|
+
# someone else did our job for us
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
after_fork do |server, worker|
|
32
|
+
ActiveRecord::Base.establish_connection
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
upstream app_server {
|
2
|
+
server unix:<%= proj_dir %>/tmp/sockets/unicorn.sock fail_timeout=0;
|
3
|
+
}
|
4
|
+
|
5
|
+
server {
|
6
|
+
root <%= proj_dir %>/public;
|
7
|
+
|
8
|
+
server_name domain.name;
|
9
|
+
|
10
|
+
try_files $uri @app;
|
11
|
+
|
12
|
+
keepalive_timeout 5;
|
13
|
+
|
14
|
+
location @app {
|
15
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
16
|
+
proxy_set_header Host $http_host;
|
17
|
+
proxy_redirect off;
|
18
|
+
proxy_pass http://app_server;
|
19
|
+
}
|
20
|
+
|
21
|
+
error_page 500 502 503 504 /500.html;
|
22
|
+
location = /500.html {
|
23
|
+
root <%= proj_dir %>/public;
|
24
|
+
}
|
25
|
+
|
26
|
+
}
|
27
|
+
|
28
|
+
|
data/lib/tasks/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'zenturio_batteries'
|
2
|
+
|
3
|
+
namespace :batteries do
|
4
|
+
|
5
|
+
namespace :configs do
|
6
|
+
gen = ZenturioBatteries::Configs.new
|
7
|
+
options = gen.available_options
|
8
|
+
|
9
|
+
options.each do |opt|
|
10
|
+
desc opt[:label]
|
11
|
+
task opt[:handler], :hard_mode? do |t, args|
|
12
|
+
puts ''
|
13
|
+
hard_mode = (args[:hard_mode?] == 'true')
|
14
|
+
gen.execute! opt[:handler], hard_mode
|
15
|
+
puts ''
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ZenturioBatteries::Base
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
# Basic module for generation application parts
|
5
|
+
module Generator
|
6
|
+
|
7
|
+
# Get the list of available options for current generator
|
8
|
+
def available_options
|
9
|
+
[]
|
10
|
+
end
|
11
|
+
|
12
|
+
# Execute option for given handler.
|
13
|
+
# If there is no such handler - raise Exception
|
14
|
+
def execute! handler, hard_mode = false
|
15
|
+
raise Exception.new('No such handler') unless self.methods.include?(handler)
|
16
|
+
|
17
|
+
method = self.method(handler)
|
18
|
+
config_list = method.call
|
19
|
+
|
20
|
+
process_config! config_list, hard_mode
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
# Copy necessary files to destination folders.
|
26
|
+
# Information about files - in config_list parameter
|
27
|
+
#
|
28
|
+
# config_list - is a Array and each element is a Hash.
|
29
|
+
# each element has 2 keys - :source and :destination
|
30
|
+
def process_config! config_list, hard_mode
|
31
|
+
config_list.each do |finfo|
|
32
|
+
source = finfo[:source]
|
33
|
+
dest = finfo[:destination]
|
34
|
+
|
35
|
+
# Setting bindings for templates
|
36
|
+
proj_dir = Dir.pwd
|
37
|
+
|
38
|
+
# Rendering templates
|
39
|
+
renderer = ERB.new File.new(ZenturioBatteries.base_dir+'/assets'+source).read
|
40
|
+
res = renderer.result binding
|
41
|
+
|
42
|
+
# Saving templates to destination
|
43
|
+
dest_file = proj_dir+dest
|
44
|
+
|
45
|
+
if File.exists?(dest_file) && !hard_mode
|
46
|
+
puts dest_file+' already exists and generation will be skipped.'
|
47
|
+
else
|
48
|
+
File.open(dest_file, "w+") do |f|
|
49
|
+
f.write(res)
|
50
|
+
end
|
51
|
+
puts dest_file+' was generated.'
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "zenturio_batteries/base/generator"
|
2
|
+
|
3
|
+
=begin
|
4
|
+
Class for generating production configuration files for several web servers
|
5
|
+
|
6
|
+
Supported options:
|
7
|
+
1. Nginx + Unicorn
|
8
|
+
2. %todo%
|
9
|
+
=end
|
10
|
+
class ZenturioBatteries::Configs
|
11
|
+
include ZenturioBatteries::Base::Generator
|
12
|
+
|
13
|
+
def available_options
|
14
|
+
[
|
15
|
+
{:label=>'Generate production config for: Nginx + Unicorn', :handler => :unicorn}
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
# Handler for `Nginx + Unicorn` option
|
22
|
+
def unicorn
|
23
|
+
[
|
24
|
+
{:source => '/configs/unicorn.erb', :destination=>'/unicorn.rb'},
|
25
|
+
{:source => '/configs/unicorn_nginx.erb', :destination=>'/nginx.conf'},
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "zenturio_batteries/version"
|
2
|
+
require "zenturio_batteries/base/generator"
|
3
|
+
require "zenturio_batteries/configs"
|
4
|
+
|
5
|
+
=begin
|
6
|
+
Base module for Zenturio Batteries
|
7
|
+
=end
|
8
|
+
module ZenturioBatteries
|
9
|
+
|
10
|
+
# return base dir with assets and tasks directory inside
|
11
|
+
def self.base_dir
|
12
|
+
File.dirname(__FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Loads rake tasks
|
16
|
+
def self.load_tasks
|
17
|
+
Dir.glob(base_dir+'/tasks/*.rake').each { |f| load f }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
=begin
|
4
|
+
Mock class for testing some generator methods
|
5
|
+
=end
|
6
|
+
class MockGenerator
|
7
|
+
include ZenturioBatteries::Base::Generator
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ZenturioBatteries::Base::Generator do
|
11
|
+
|
12
|
+
it 'has method that should return list of available options' do
|
13
|
+
gen = MockGenerator.new
|
14
|
+
gen.methods.include?(:available_options).should eq(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has method that should execute option by its handler' do
|
18
|
+
gen = MockGenerator.new
|
19
|
+
gen.methods.include?(:execute!).should eq(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can\'t call wrong hanlder' do
|
23
|
+
gen = MockGenerator.new
|
24
|
+
lambda { gen.execute!(:wrong_handler) }.should raise_exception
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZenturioBatteries::Configs do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@curdir = Dir.pwd
|
7
|
+
Dir.mkdir @curdir+'/tmp' unless Dir.exists? @curdir+'/tmp'
|
8
|
+
Dir.chdir @curdir+'/tmp'
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Dir.chdir @curdir
|
13
|
+
Dir[@curdir+'/tmp/*'].each {|f| File.delete(f) }
|
14
|
+
Dir.unlink @curdir+'/tmp'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has at least one option' do
|
18
|
+
gen = ZenturioBatteries::Configs.new
|
19
|
+
options = gen.available_options
|
20
|
+
|
21
|
+
options.class.should eq(Array)
|
22
|
+
options.empty?.should eq(false)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'can generate nginx|unicorn configuration' do
|
26
|
+
gen = ZenturioBatteries::Configs.new
|
27
|
+
gen.execute! :unicorn
|
28
|
+
|
29
|
+
File.exists?(Dir.pwd+'/unicorn.rb').should eq(true)
|
30
|
+
File.exists?(Dir.pwd+'/nginx.conf').should eq(true)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZenturioBatteries do
|
4
|
+
|
5
|
+
it 'has correct base directory' do
|
6
|
+
dir = ZenturioBatteries.base_dir
|
7
|
+
|
8
|
+
dir.empty?.should eq(false)
|
9
|
+
Dir.exists?(dir).should eq(true)
|
10
|
+
Dir.exists?(dir+'/assets').should eq(true)
|
11
|
+
Dir.exists?(dir+'/tasks').should eq(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zenturio_batteries/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "zenturio_batteries"
|
8
|
+
gem.version = ZenturioBatteries::VERSION
|
9
|
+
|
10
|
+
gem.authors = ["Andreas Sotnik"]
|
11
|
+
gem.email = ["andreas.sotnik@gmail.com"]
|
12
|
+
|
13
|
+
gem.description = "This gem generates common parts of Ruby On Rails applications. Parts like: production configuration for several web servers, common models with migrations, some widgets, etc"
|
14
|
+
gem.summary = "Gem for generating common parts of RoR Application: production configuration, models, additional components, etc"
|
15
|
+
gem.homepage = "http://zenturio.me/pages/zenturio-batteries"
|
16
|
+
|
17
|
+
gem.license = 'MIT'
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($/)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zenturio_batteries
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andreas Sotnik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'This gem generates common parts of Ruby On Rails applications. Parts
|
15
|
+
like: production configuration for several web servers, common models with migrations,
|
16
|
+
some widgets, etc'
|
17
|
+
email:
|
18
|
+
- andreas.sotnik@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- .rspec
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- LICENSE.txt
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- lib/assets/.gitkeep
|
31
|
+
- lib/assets/configs/unicorn.erb
|
32
|
+
- lib/assets/configs/unicorn_nginx.erb
|
33
|
+
- lib/tasks/.gitkeep
|
34
|
+
- lib/tasks/configs.rake
|
35
|
+
- lib/zenturio_batteries.rb
|
36
|
+
- lib/zenturio_batteries/base/generator.rb
|
37
|
+
- lib/zenturio_batteries/configs.rb
|
38
|
+
- lib/zenturio_batteries/version.rb
|
39
|
+
- spec/base_generator_spec.rb
|
40
|
+
- spec/configs_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
- spec/zenturio_batteries_spec.rb
|
43
|
+
- zenturio_batteries.gemspec
|
44
|
+
homepage: http://zenturio.me/pages/zenturio-batteries
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: ! 'Gem for generating common parts of RoR Application: production configuration,
|
69
|
+
models, additional components, etc'
|
70
|
+
test_files:
|
71
|
+
- spec/base_generator_spec.rb
|
72
|
+
- spec/configs_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- spec/zenturio_batteries_spec.rb
|