meskyanichi-simple_generators 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +78 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/generators/simple_capistrano_recipe/USAGE +12 -0
- data/generators/simple_capistrano_recipe/simple_capistrano_recipe_generator.rb +48 -0
- data/generators/simple_capistrano_recipe/templates/capistrano_recipe.rb +130 -0
- data/generators/simple_git_template/USAGE +0 -0
- data/generators/simple_git_template/simple_git_template_generator.rb +17 -0
- data/generators/simple_git_template/templates/git_ignore.tpl +8 -0
- data/generators/simple_paperclip_model/USAGE +0 -0
- data/generators/simple_paperclip_model/simple_paperclip_model_generator.rb +55 -0
- data/generators/simple_paperclip_model/templates/paperclip.rb +20 -0
- data/generators/simple_tasks/simple_repository_tasks/USAGE +0 -0
- data/generators/simple_tasks/simple_repository_tasks/simple_repository_tasks_generator.rb +66 -0
- data/generators/simple_tasks/simple_repository_tasks/templates/repository.rake +43 -0
- data/lib/simple_generators.rb +0 -0
- data/simple_generators.gemspec +74 -0
- data/test/simple_generators_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +77 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Michael van Rooijen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
= Simple Generators
|
2
|
+
|
3
|
+
To get you up and running just a little bit faster!
|
4
|
+
|
5
|
+
|
6
|
+
== Simple Capistrano Recipe
|
7
|
+
|
8
|
+
This generator will generate a simple capistrano template. You can supply some arguments to let the generate fill in the deployment recipe for you as well. This generator is currently made specifically for Ruby on Rails with Phusion Passenger and Git Repository. Of course, you can still generate the deployment recipe and alter the sections within it to get it to deploy to your liking!
|
9
|
+
|
10
|
+
==== To generate a dry Capistrano Deployment Recipe, run the following command:
|
11
|
+
script/generate simple_capistrano_recipe
|
12
|
+
|
13
|
+
==== You can also provide arguments to generate an already filled in recipe:
|
14
|
+
script/generate simple_capistrano_recipe domain:example.com user:root deploy_path:/var/rails/example.com
|
15
|
+
repository_type:git repository_url:ssh://root@example.com/var/git/example.git
|
16
|
+
|
17
|
+
After generating the deployment recipe (RAILS_ROOT/config/deploy.rb), you might want to double check if everything is set up correctly before you actually try to deploy.
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
== Simple Git Template
|
23
|
+
|
24
|
+
This is a very small generator that just generates a .gitignore file in the RAILS_ROOT with a couple of predefined ingore lines.
|
25
|
+
==== No arguments can be supplied here:
|
26
|
+
script/generate simple_git_template
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
== Simple Paperclip Model
|
32
|
+
|
33
|
+
Now, I always tend to forget all the settings I usually need for my Paperclip model, hence why I created the gem and added this generators as well.
|
34
|
+
|
35
|
+
==== To generate a Paperclip Model you are required to supply 2 of the 3 arguments:
|
36
|
+
script/generate simple_paperclip_model model:user attachment:avatar [optional: type:image]
|
37
|
+
|
38
|
+
The optional type:image argument will generate example "styles" for Paperclip.
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
== Simple Tasks
|
44
|
+
|
45
|
+
At the moment, there is only one Task Generator available.
|
46
|
+
|
47
|
+
|
48
|
+
=== Simple Repository Tasks
|
49
|
+
|
50
|
+
This generator will generate 3 rake tasks that can help with creating and destroying your applications remote repository using SSH on your own server.
|
51
|
+
|
52
|
+
==== To generates these Repository Rake Tasks, run the following command:
|
53
|
+
script/generate simple_repository_tasks
|
54
|
+
|
55
|
+
If you do it this way, you will manually have to open the rake tasks, located in the lib/tasks/simple_tasks/repository.rake file, and add your server settings in there.
|
56
|
+
|
57
|
+
==== If you wish to, like I do, let the generator insert these settings in for you, execute the following command:
|
58
|
+
script/generate simple_repository_tasks domain:example.com path:/var/git/example.git
|
59
|
+
user:root password:mys3cr3tp4ssw0rd
|
60
|
+
|
61
|
+
==== Now, when you run the following command:
|
62
|
+
rake -T
|
63
|
+
|
64
|
+
You will see a list of all your available rake tasks, including the Repository Rake Tasks and their description.
|
65
|
+
|
66
|
+
These rake tasks allow your to quickly, without manually SSH'ing to your server, create and destroy your git repository for a specific Ruby on Rails application. Additionally, if you haven't already, you can run a simple command (rake simple_tasks:repository:add_to_git) to add your remote repository location (origin) to your local repository.
|
67
|
+
|
68
|
+
==== These are the commands that are currently available for the Simple Repository Tasks:
|
69
|
+
|
70
|
+
rake simple_tasks:repository:add_to_git
|
71
|
+
rake simple_tasks:repository:create
|
72
|
+
rake simple_tasks:repository:destroy
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
== Copyright
|
77
|
+
|
78
|
+
Copyright (c) 2009 Michael van Rooijen. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "simple_generators"
|
8
|
+
gem.summary = "A couple of generators that supply you with some common templates to speed up the development process."
|
9
|
+
gem.description = "A couple of generators that supply you with some common templates to speed up the development process."
|
10
|
+
gem.email = "meskyan@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/meskyanichi/simple_generators"
|
12
|
+
gem.authors = ["Michael van Rooijen"]
|
13
|
+
gem.files.include 'generators/**/*'
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
task :test => :check_dependencies
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
if File.exist?('VERSION')
|
46
|
+
version = File.read('VERSION')
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "simple_generators #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Simple Capistrano Recipe
|
2
|
+
|
3
|
+
|
4
|
+
To generate the default template which you will afterwards manually modify:
|
5
|
+
|
6
|
+
script/generate simple_capistrano_recipe
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
To generate a template dynamically with arguments:
|
11
|
+
|
12
|
+
script/generate simple_capistrano_recipe domain:example.com user:root deploy_path:/var/rails/example.com repository_type:git repository_url:ssh://root@example.com/var/git/example.git
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class SimpleCapistranoRecipeGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
# This method gets initialized when the generator gets run.
|
4
|
+
# It will receive an array of arguments inside @args
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
super
|
7
|
+
extract_args
|
8
|
+
set_defaults
|
9
|
+
system "capify #{RAILS_ROOT}"
|
10
|
+
File.delete("#{RAILS_ROOT}/config/deploy.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
# Processes the file generation/templating
|
14
|
+
# This will automatically be run after the initialize method
|
15
|
+
def manifest
|
16
|
+
record do |m|
|
17
|
+
m.template "capistrano_recipe.rb", "config/deploy.rb"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Creates a new Hash Object containing the user input
|
22
|
+
# The user input will be available through @input and input
|
23
|
+
def extract_args
|
24
|
+
@input = Hash.new
|
25
|
+
@args.each do |arg|
|
26
|
+
if arg.include?(":") then
|
27
|
+
@input[:"#{arg.slice(0, arg.index(":"))}"] = arg.slice((arg.index(":") + 1)..-1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Sets defaults for user input when left blank by the user
|
33
|
+
# for each parameter
|
34
|
+
def set_defaults
|
35
|
+
@input[:domain] ||= "example.com"
|
36
|
+
@input[:user] ||= "root"
|
37
|
+
@input[:deploy_path] ||= "/var/rails/example.com"
|
38
|
+
@input[:repository_type] ||= "git"
|
39
|
+
@input[:repository_url] ||= "ssh://root@example.com/var/git/example.git"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Input Method that's available inside the generated templates
|
43
|
+
# because instance variable are not available, so we access them through methods
|
44
|
+
def input
|
45
|
+
@input
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# Author: Michael van Rooijen
|
2
|
+
# Description:
|
3
|
+
# This recipe is designed to work for people using Phusion Passenger,
|
4
|
+
# Git as your repository.
|
5
|
+
#
|
6
|
+
# The script (initially) does the following:
|
7
|
+
# - It first (after you run cap:deploy setup) will set up the capistrano environment on your remote machine
|
8
|
+
# - After that, it will sync your current database.yml file to the "shared" location on the remote machine
|
9
|
+
# - You are now basically ready to deploy.
|
10
|
+
# - Once you run "cap:deploy" it will start the deployment
|
11
|
+
# - First, it will reach for your remote repository and pull out the files
|
12
|
+
# - The application will be placed in a new revision folder
|
13
|
+
# - The "current" symlink will be updated upon completion of the transfer above
|
14
|
+
# - It will then set up the symlinks from the current application to the "shared"
|
15
|
+
# section for the database.yml, production.sqlite3 and the "assets" directory.
|
16
|
+
# - Once this is done, Capistrano will initiallize the Passenger Instance and your application should be up and running!
|
17
|
+
# - One last task will be performed right after this, and that is that Capistrano will give Rails specific "rights" (www-data:www-data)
|
18
|
+
# to the whole application. This will make sure that nothing that should be writed/modified will kill the application, such as:
|
19
|
+
# stylesheets/javascripts when :cache => true, writing to sqlite3 database, using upload gems such as paperclip.
|
20
|
+
#
|
21
|
+
# So, now your application is up and running. Long Story Short:
|
22
|
+
#
|
23
|
+
# Create a new Rails App. Create a Git Repository. Add your remote repository to it.
|
24
|
+
# Push all your data to the remote repository. Configure this file. Run "cap:deploy setup" to setup the remote machine's environment.
|
25
|
+
# Run "cap:deploy" and your web application should be running in a matter of seconds.
|
26
|
+
#
|
27
|
+
# If you are not using sqlite3 and get a (500)error right off the bat, first place to look is whether your database exists on the remote server
|
28
|
+
# ( I always forget this part ;) )
|
29
|
+
#
|
30
|
+
# This Capistrano Recipe is just a base awaiting to be expanded!
|
31
|
+
# So feel free to do so.
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
# SETTINGS
|
37
|
+
# Application Domain (example.domain.com)
|
38
|
+
# Be sure to fill in the correct domain name for your web application!
|
39
|
+
set :application, "<%= input[:domain] %>"
|
40
|
+
|
41
|
+
# Set server where the application is going to be uploaded to.
|
42
|
+
# Automatically filled in with the application variable.
|
43
|
+
role :web, application
|
44
|
+
role :app, application
|
45
|
+
role :db, application
|
46
|
+
|
47
|
+
# Set the user
|
48
|
+
# :user => Set the user that will attempt to access the remote repository
|
49
|
+
# :deploy_to => Set the deployment location (destination) on the remote server
|
50
|
+
# :use_sudo => Set to false
|
51
|
+
set :user, "<%= input[:user] %>"
|
52
|
+
set :deploy_to, "<%= input[:deploy_path] %>"
|
53
|
+
set :use_sudo, false
|
54
|
+
|
55
|
+
# Git Repository Location
|
56
|
+
# :scm => Specify the source code management tool you want to use (default is git)
|
57
|
+
# :repository => Assign the repository location where the application resides
|
58
|
+
# :branch => Select the branch that capistrano should fetch from (default is master)
|
59
|
+
set :scm, "<%= input[:repository_type] %>"
|
60
|
+
set :repository, "<%= input[:repository_url] %>"
|
61
|
+
set :branch, "master"
|
62
|
+
|
63
|
+
# Required: default_run_options[:pty] - This will allow the user to connect to protected repository after
|
64
|
+
# logging in when the system prompts for the server's root password
|
65
|
+
# default_run_options => (default is true)
|
66
|
+
default_run_options[:pty] = true
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
# TASKS
|
78
|
+
# You can add additional deployment tasks, or alter the ones below.
|
79
|
+
|
80
|
+
namespace :deploy do
|
81
|
+
|
82
|
+
desc "Restart Application with Passenger and make the application writable."
|
83
|
+
task :restart do
|
84
|
+
run "touch #{current_path}/tmp/restart.txt"
|
85
|
+
run "chown -R www-data:www-data #{deploy_to}"
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Setup the shared folder structure."
|
89
|
+
task :setup_shared do
|
90
|
+
run "touch #{shared_path}/log/production.log"
|
91
|
+
run "mkdir #{shared_path}/db #{shared_path}/assets #{shared_path}/config"
|
92
|
+
end
|
93
|
+
|
94
|
+
desc "Syncs the database.yml to the server"
|
95
|
+
task :sync_database_yaml do
|
96
|
+
system "rsync -vr --exclude='.DS_Store' config/database.yml #{user}@#{application}:#{shared_path}/config/"
|
97
|
+
end
|
98
|
+
|
99
|
+
desc "Sets up symbolic links."
|
100
|
+
task :setup_symlinks do
|
101
|
+
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
102
|
+
run "ln -nfs #{shared_path}/db/production.sqlite3 #{release_path}/db/production.sqlite3"
|
103
|
+
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
|
104
|
+
end
|
105
|
+
|
106
|
+
desc "Reset remote rails environment."
|
107
|
+
task :reset_rails_environment do
|
108
|
+
run "rm -rf #{deploy_to}"
|
109
|
+
system "cap deploy:setup"
|
110
|
+
end
|
111
|
+
|
112
|
+
desc "Update the crontab file"
|
113
|
+
task :update_crontab, :roles => :db do
|
114
|
+
run "cd #{release_path} && whenever --update-crontab #{application}"
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
# CALLBACKS
|
124
|
+
# By adding more tasks, you might want to add more callbacks.
|
125
|
+
# Just append more callbacks to the existing ones below.
|
126
|
+
|
127
|
+
after 'deploy:setup', 'deploy:setup_shared'
|
128
|
+
after 'deploy:setup', 'deploy:sync_database_yaml'
|
129
|
+
after 'deploy:update_code', 'deploy:setup_symlinks'
|
130
|
+
#after 'deploy:symlink', 'deploy:update_crontab' (Uncomment if using Javan-Whenever Gem)
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class SimpleGitTemplateGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
# This method gets initialized when the generator gets run.
|
4
|
+
# It will receive an array of arguments inside @args
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
# Processes the file generation/templating
|
10
|
+
# This will automatically be run after the initialize method
|
11
|
+
def manifest
|
12
|
+
record do |m|
|
13
|
+
m.file "git_ignore.tpl", ".gitignore"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
File without changes
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class SimplePaperclipModelGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
# This method gets initialized when the generator gets run.
|
4
|
+
# It will receive an array of arguments inside @args
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
super
|
7
|
+
extract_args
|
8
|
+
set_defaults
|
9
|
+
confirm_input
|
10
|
+
end
|
11
|
+
|
12
|
+
# Processes the file generation/templating
|
13
|
+
# This will automatically be run after the initialize method
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
m.template "paperclip.rb", "app/models/#{@input[:model]}.rb"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Creates a new Hash Object containing the user input
|
21
|
+
# The user input will be available through @input and input
|
22
|
+
def extract_args
|
23
|
+
@input = Hash.new
|
24
|
+
@args.each do |arg|
|
25
|
+
if arg.include?(":") then
|
26
|
+
@input[:"#{arg.slice(0, arg.index(":"))}"] = arg.slice((arg.index(":") + 1)..-1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Input Method that's available inside the generated templates
|
32
|
+
# because instance variable are not available, so we access them through methods
|
33
|
+
def input
|
34
|
+
@input
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sets defaults for user input when left blank by the user
|
38
|
+
# for each parameter
|
39
|
+
def set_defaults
|
40
|
+
@input[:type] ||= "image"
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def confirm_input
|
45
|
+
if @input[:model].nil? or @input[:attachment].nil?
|
46
|
+
raise "
|
47
|
+
A model and attachment must be specified!
|
48
|
+
|
49
|
+
Example:
|
50
|
+
script/generate simple_paperclip_model model:user attachment:avatar
|
51
|
+
"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class <%= input[:model].camelcase.singularize %> < ActiveRecord::Base
|
2
|
+
|
3
|
+
# Add <%= input[:attachment].singularize.underscore %> attribute
|
4
|
+
has_attached_file :<%= input[:attachment].singularize.underscore %>,
|
5
|
+
:url => "/assets/<%= input[:attachment].pluralize %>/:style/:id.:basename.:extension",
|
6
|
+
:path => ":rails_root/public/assets/<%= input[:attachment].pluralize %>/:style/:id.:basename.:extension",
|
7
|
+
:styles => {
|
8
|
+
<% if input[:type].eql?("image") -%>
|
9
|
+
:small => '50x45#',
|
10
|
+
:medium => '150x150',
|
11
|
+
:large => '300x300'
|
12
|
+
<% end -%>
|
13
|
+
}
|
14
|
+
|
15
|
+
# Validation
|
16
|
+
validates_attachment_presence :<%= input[:attachment].singularize.underscore %>, :message => "You are required to select an <%= input[:attachment].singularize %>."
|
17
|
+
validates_attachment_size :<%= input[:attachment].singularize.underscore %>, :less_than => 2.megabytes, :message => "must be less than 500 kilobytes."
|
18
|
+
validates_attachment_content_type :<%= input[:attachment].singularize.underscore %>, :content_type => ['image/jpg', 'image/jpeg','image/gif','image/png','image/pjpeg','image/x-png'], :message => "Must be JPG PNG or GIF."
|
19
|
+
|
20
|
+
end
|
File without changes
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class SimpleRepositoryTasksGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
# This method gets initialized when the generator gets run.
|
4
|
+
# It will receive an array of arguments inside @args
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
super
|
7
|
+
extract_args
|
8
|
+
set_defaults
|
9
|
+
|
10
|
+
unless File.directory?(simple_tasks_path)
|
11
|
+
Dir.mkdir(simple_tasks_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
if File.exist?(simple_repository_path)
|
15
|
+
File.delete(simple_repository_path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Processes the file generation/templating
|
20
|
+
# This will automatically be run after the initialize method
|
21
|
+
def manifest
|
22
|
+
record do |m|
|
23
|
+
m.template "repository.rake", "lib/tasks/simple_tasks/repository.rake"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Creates a new Hash Object containing the user input
|
28
|
+
# The user input will be available through @input and input
|
29
|
+
def extract_args
|
30
|
+
@input = Hash.new
|
31
|
+
@args.each do |arg|
|
32
|
+
if arg.include?(":") then
|
33
|
+
@input[:"#{arg.slice(0, arg.index(":"))}"] = arg.slice((arg.index(":") + 1)..-1)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Sets defaults for user input when left blank by the user
|
39
|
+
# for each parameter
|
40
|
+
def set_defaults
|
41
|
+
@input[:domain] ||= "example.com"
|
42
|
+
@input[:path] ||= "/var/git/example.git"
|
43
|
+
@input[:user] ||= "root"
|
44
|
+
@input[:password] ||= "mys3cr3tp4ssw0rd"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Input Method that's available inside the generated templates
|
48
|
+
# because instance variable are not available, so we access them through methods
|
49
|
+
def input
|
50
|
+
@input
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
# Defines the simple tasks folder path
|
57
|
+
def simple_tasks_path
|
58
|
+
"#{RAILS_ROOT}/lib/tasks/simple_tasks"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Defines the repository rake file path
|
62
|
+
def simple_repository_path
|
63
|
+
"#{RAILS_ROOT}/lib/tasks/simple_tasks/repository.rake"
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
|
3
|
+
namespace :simple_tasks do
|
4
|
+
|
5
|
+
namespace :repository do
|
6
|
+
|
7
|
+
repository_domain = "<%= input[:domain] %>"
|
8
|
+
repository_path = "<%= input[:path] %>"
|
9
|
+
repository_user = "<%= input[:user] %>"
|
10
|
+
repository_password = "<%= input[:password] %>"
|
11
|
+
|
12
|
+
desc "Creates a remote repository for the Rails application."
|
13
|
+
task :create => :filter do
|
14
|
+
puts "Creating remote repository.."
|
15
|
+
Net::SSH.start(repository_domain, repository_user, :password => repository_password) do |ssh|
|
16
|
+
ssh.exec "mkdir -p #{repository_path}; git --bare --git-dir=#{repository_path} init"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Removes a remote repository for the Rails application."
|
21
|
+
task :destroy => :filter do
|
22
|
+
puts "Removing remote repository.."
|
23
|
+
Net::SSH.start(repository_domain, repository_user, :password => repository_password) do |ssh|
|
24
|
+
ssh.exec "rm -rf #{repository_path}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Adds the remote repository as origin to git."
|
29
|
+
task :add_to_git do
|
30
|
+
system "git remote rm origin"
|
31
|
+
system "git remote add origin ssh://#{repository_user}@#{repository_domain}/#{repository_path}"
|
32
|
+
puts "ssh://#{repository_user}@#{repository_domain}/#{repository_path}"
|
33
|
+
puts "was successfully added as remote repository (origin)."
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Filters anything that might cause an error."
|
37
|
+
task :filter do
|
38
|
+
# => no filters added at the moment
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
File without changes
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{simple_generators}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael van Rooijen"]
|
12
|
+
s.date = %q{2009-08-14}
|
13
|
+
s.description = %q{A couple of generators that supply you with some common templates to speed up the development process.}
|
14
|
+
s.email = %q{meskyan@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"generators/simple_capistrano_recipe/USAGE",
|
27
|
+
"generators/simple_capistrano_recipe/USAGE",
|
28
|
+
"generators/simple_capistrano_recipe/simple_capistrano_recipe_generator.rb",
|
29
|
+
"generators/simple_capistrano_recipe/simple_capistrano_recipe_generator.rb",
|
30
|
+
"generators/simple_capistrano_recipe/templates/capistrano_recipe.rb",
|
31
|
+
"generators/simple_capistrano_recipe/templates/capistrano_recipe.rb",
|
32
|
+
"generators/simple_git_template/USAGE",
|
33
|
+
"generators/simple_git_template/USAGE",
|
34
|
+
"generators/simple_git_template/simple_git_template_generator.rb",
|
35
|
+
"generators/simple_git_template/simple_git_template_generator.rb",
|
36
|
+
"generators/simple_git_template/templates/git_ignore.tpl",
|
37
|
+
"generators/simple_git_template/templates/git_ignore.tpl",
|
38
|
+
"generators/simple_paperclip_model/USAGE",
|
39
|
+
"generators/simple_paperclip_model/USAGE",
|
40
|
+
"generators/simple_paperclip_model/simple_paperclip_model_generator.rb",
|
41
|
+
"generators/simple_paperclip_model/simple_paperclip_model_generator.rb",
|
42
|
+
"generators/simple_paperclip_model/templates/paperclip.rb",
|
43
|
+
"generators/simple_paperclip_model/templates/paperclip.rb",
|
44
|
+
"generators/simple_tasks/simple_repository_tasks/USAGE",
|
45
|
+
"generators/simple_tasks/simple_repository_tasks/USAGE",
|
46
|
+
"generators/simple_tasks/simple_repository_tasks/simple_repository_tasks_generator.rb",
|
47
|
+
"generators/simple_tasks/simple_repository_tasks/simple_repository_tasks_generator.rb",
|
48
|
+
"generators/simple_tasks/simple_repository_tasks/templates/repository.rake",
|
49
|
+
"generators/simple_tasks/simple_repository_tasks/templates/repository.rake",
|
50
|
+
"lib/simple_generators.rb",
|
51
|
+
"simple_generators.gemspec",
|
52
|
+
"test/simple_generators_test.rb",
|
53
|
+
"test/test_helper.rb"
|
54
|
+
]
|
55
|
+
s.homepage = %q{http://github.com/meskyanichi/simple_generators}
|
56
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
57
|
+
s.require_paths = ["lib"]
|
58
|
+
s.rubygems_version = %q{1.3.5}
|
59
|
+
s.summary = %q{A couple of generators that supply you with some common templates to speed up the development process.}
|
60
|
+
s.test_files = [
|
61
|
+
"test/simple_generators_test.rb",
|
62
|
+
"test/test_helper.rb"
|
63
|
+
]
|
64
|
+
|
65
|
+
if s.respond_to? :specification_version then
|
66
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
|
+
s.specification_version = 3
|
68
|
+
|
69
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
70
|
+
else
|
71
|
+
end
|
72
|
+
else
|
73
|
+
end
|
74
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meskyanichi-simple_generators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael van Rooijen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-14 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A couple of generators that supply you with some common templates to speed up the development process.
|
17
|
+
email: meskyan@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- generators/simple_capistrano_recipe/USAGE
|
33
|
+
- generators/simple_capistrano_recipe/simple_capistrano_recipe_generator.rb
|
34
|
+
- generators/simple_capistrano_recipe/templates/capistrano_recipe.rb
|
35
|
+
- generators/simple_git_template/USAGE
|
36
|
+
- generators/simple_git_template/simple_git_template_generator.rb
|
37
|
+
- generators/simple_git_template/templates/git_ignore.tpl
|
38
|
+
- generators/simple_paperclip_model/USAGE
|
39
|
+
- generators/simple_paperclip_model/simple_paperclip_model_generator.rb
|
40
|
+
- generators/simple_paperclip_model/templates/paperclip.rb
|
41
|
+
- generators/simple_tasks/simple_repository_tasks/USAGE
|
42
|
+
- generators/simple_tasks/simple_repository_tasks/simple_repository_tasks_generator.rb
|
43
|
+
- generators/simple_tasks/simple_repository_tasks/templates/repository.rake
|
44
|
+
- lib/simple_generators.rb
|
45
|
+
- simple_generators.gemspec
|
46
|
+
- test/simple_generators_test.rb
|
47
|
+
- test/test_helper.rb
|
48
|
+
has_rdoc: false
|
49
|
+
homepage: http://github.com/meskyanichi/simple_generators
|
50
|
+
licenses:
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: A couple of generators that supply you with some common templates to speed up the development process.
|
75
|
+
test_files:
|
76
|
+
- test/simple_generators_test.rb
|
77
|
+
- test/test_helper.rb
|