bently 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +8 -0
- data/README.md +0 -0
- data/bently.gemspec +16 -0
- data/bin/bently +12 -0
- data/lib/bently/cli.rb +27 -0
- data/lib/bently/core_ext/string.rb +40 -0
- data/lib/bently/globals.rb +3 -0
- data/lib/bently/recipe/devise.rb +18 -0
- data/lib/bently/recipe/gitignore.rb +18 -0
- data/lib/bently/recipe/haml-rails.rb +16 -0
- data/lib/bently/recipe/resque.rb +6 -0
- data/lib/bently/recipe/rspec-rails.rb +18 -0
- data/lib/bently/recipe/twitter-bootstrap-rails.rb +17 -0
- data/lib/bently/recipe/welcome-index.rb +18 -0
- data/lib/bently/recipe.rb +133 -0
- data/lib/bently.rb +7 -0
- metadata +76 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
File without changes
|
data/bently.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'bently'
|
3
|
+
s.version = '0.0.0'
|
4
|
+
s.date = '2012-09-15'
|
5
|
+
s.summary = "Bently executes (bakes) predefined formulas (recipes)"
|
6
|
+
s.description = "Bently executes (bakes) predefined formulas (recipes) for trivial stuff you do a lot"
|
7
|
+
s.authors = ["Benjamin Sullivan"]
|
8
|
+
s.email = 'bsullivan2@gmail.com'
|
9
|
+
s.homepage = 'http://github.com/bonsaiben/bently'
|
10
|
+
|
11
|
+
s.add_dependency "thor", ">= 0.14.6"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
end
|
data/bin/bently
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'bently'
|
7
|
+
#begin
|
8
|
+
Bently::CLI.start
|
9
|
+
#rescue
|
10
|
+
# puts "Unexpected error. Quitting..."
|
11
|
+
# exit(1)
|
12
|
+
#end
|
data/lib/bently/cli.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Bently
|
2
|
+
|
3
|
+
class CLI < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
desc 'list', 'list recipes'
|
7
|
+
def list
|
8
|
+
Recipe.list.each {|f| puts f }
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'read [RECIPE]', 'display a recipe'
|
12
|
+
def read recipe_name
|
13
|
+
bake recipe_name, true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'bake [RECIPE]', 'execute a recipe'
|
17
|
+
def bake(recipe_name, read_only=false)
|
18
|
+
if Recipe.list.include?(recipe_name)
|
19
|
+
recipe = Recipe.from_name(recipe_name).new(:read_only => read_only)
|
20
|
+
recipe.bake
|
21
|
+
else
|
22
|
+
puts "Recipe not found."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# some methods borrowed from ActiveSupport
|
2
|
+
# https://github.com/rails/rails/tree/master/activesupport
|
3
|
+
# MIT License (http://www.opensource.org/licenses/MIT)
|
4
|
+
|
5
|
+
class String
|
6
|
+
|
7
|
+
def camelize
|
8
|
+
string = self
|
9
|
+
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
10
|
+
string = string.gsub(/\-/,'_')
|
11
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
|
12
|
+
end
|
13
|
+
|
14
|
+
def constantize
|
15
|
+
names = self.split('::')
|
16
|
+
names.shift if names.empty? || names.first.empty?
|
17
|
+
|
18
|
+
names.inject(Object) do |constant, name|
|
19
|
+
if constant == Object
|
20
|
+
constant.const_get(name)
|
21
|
+
else
|
22
|
+
candidate = constant.const_get(name)
|
23
|
+
next candidate if constant.const_defined?(name, false)
|
24
|
+
next candidate unless Object.const_defined?(name)
|
25
|
+
|
26
|
+
# Go down the ancestors to check it it's owned
|
27
|
+
# directly before we reach Object or the end of ancestors.
|
28
|
+
constant = constant.ancestors.inject do |const, ancestor|
|
29
|
+
break const if ancestor == Object
|
30
|
+
break ancestor if ancestor.const_defined?(name, false)
|
31
|
+
const
|
32
|
+
end
|
33
|
+
|
34
|
+
# owner is in Object, so raise
|
35
|
+
constant.const_get(name, false)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Bently
|
2
|
+
|
3
|
+
class Devise < Recipe
|
4
|
+
GEMFILE_DEF = "gem 'devise'"
|
5
|
+
RAILS_GENERATOR = "rails g devise:install"
|
6
|
+
MODEL_GENERATOR = "rails g devise"
|
7
|
+
ASK_MODEL_GENERATOR = "Model name:"
|
8
|
+
|
9
|
+
def bake
|
10
|
+
add_gem(GEMFILE_DEF) || return
|
11
|
+
bundle_install
|
12
|
+
command RAILS_GENERATOR
|
13
|
+
ask_command("#{MODEL_GENERATOR} MODEL", ASK_MODEL_GENERATOR){|a| "#{MODEL_GENERATOR} #{a}" }
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Bently
|
2
|
+
|
3
|
+
class RspecRails < Recipe
|
4
|
+
GEMFILE_DEF = %{group :test, :development do
|
5
|
+
gem "rspec-rails", "~> 2.0"
|
6
|
+
end
|
7
|
+
}
|
8
|
+
RAILS_GENERATOR = "rails g rspec:install"
|
9
|
+
|
10
|
+
def bake
|
11
|
+
add_gem(GEMFILE_DEF)
|
12
|
+
bundle_install
|
13
|
+
command RAILS_GENERATOR
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Bently
|
2
|
+
|
3
|
+
class TwitterBootstrapRails < Recipe
|
4
|
+
|
5
|
+
GEMFILE_DEF = "gem \"twitter-bootstrap-rails\", :group => :assets"
|
6
|
+
RAILS_GENERATOR = "rails g bootstrap:install"
|
7
|
+
|
8
|
+
def bake
|
9
|
+
add_gem(GEMFILE_DEF) || return
|
10
|
+
bundle_install
|
11
|
+
command RAILS_GENERATOR
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Bently
|
2
|
+
|
3
|
+
class WelcomeIndex < Recipe
|
4
|
+
|
5
|
+
RAILS_GENERATE = 'bundle exec rails g controller welcome index'
|
6
|
+
ROUTES_FILE = 'config/routes.rb'
|
7
|
+
GSUB_SEARCH = /#\s*(root :to => 'welcome#index')/
|
8
|
+
GSUB_REPLACE = '\1'
|
9
|
+
|
10
|
+
def bake
|
11
|
+
command RAILS_GENERATE
|
12
|
+
gsub_file ROUTES_FILE, GSUB_SEARCH, GSUB_REPLACE
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Bently
|
2
|
+
|
3
|
+
class Recipe
|
4
|
+
|
5
|
+
BUNDLE_INSTALL = "bundle install"
|
6
|
+
RECIPE_DIR = "#{BENTLY_REPOSITORY}/lib/bently/recipe/*.rb"
|
7
|
+
|
8
|
+
# list all recipes
|
9
|
+
def self.list
|
10
|
+
Dir[RECIPE_DIR].map{ |f| File.basename f, '.rb' }.sort
|
11
|
+
end
|
12
|
+
|
13
|
+
# get recipe class from name
|
14
|
+
def self.from_name name
|
15
|
+
"Bently::#{name.camelize}".constantize
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def initialize options={}
|
21
|
+
@read_only = options[:read_only]
|
22
|
+
end
|
23
|
+
|
24
|
+
# bake a recipe
|
25
|
+
def bake
|
26
|
+
puts_step "Done!"
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
# instance to CLI
|
32
|
+
# for access to Thor helper methods
|
33
|
+
def cli; @cli ||= CLI.new end
|
34
|
+
|
35
|
+
# add a gem to the Gemfile
|
36
|
+
def add_gem gem_def
|
37
|
+
unless @read_only
|
38
|
+
if confirm_step "Add to Gemfile"
|
39
|
+
begin
|
40
|
+
cli.append_to_file 'Gemfile', gem_def
|
41
|
+
rescue
|
42
|
+
puts "Gemfile was not found. Aborting.."
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
puts_quote_step "Add to Gemfile", gem_def
|
48
|
+
end
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
# run bundle install
|
53
|
+
def bundle_install
|
54
|
+
command BUNDLE_INSTALL
|
55
|
+
end
|
56
|
+
|
57
|
+
# execute a command
|
58
|
+
def command cmd
|
59
|
+
unless @read_only
|
60
|
+
puts `#{cmd}` if confirm_step cmd
|
61
|
+
else
|
62
|
+
puts_step cmd
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# executes a command with user input
|
67
|
+
def ask_command cmd, prompt
|
68
|
+
unless @read_only
|
69
|
+
if confirm_step cmd
|
70
|
+
resp = cli.ask prompt
|
71
|
+
puts `#{yield resp}`
|
72
|
+
end
|
73
|
+
else
|
74
|
+
puts_step cmd
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# creates a file
|
79
|
+
def create_file destination, data
|
80
|
+
unless @read_only
|
81
|
+
cli.create_file destination, data if confirm_step "Touch #{destination}"
|
82
|
+
else
|
83
|
+
puts_quote_step "Touch #{destination}", data
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# gsubs a file
|
88
|
+
def gsub_file file, search, replace
|
89
|
+
unless @read_only
|
90
|
+
if confirm_step "Edit #{file}"
|
91
|
+
cli.gsub_file file, search, replace
|
92
|
+
end
|
93
|
+
else
|
94
|
+
puts_step "Edit #{file}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# outputs a step with a blockquote
|
99
|
+
def puts_quote_step text, quote
|
100
|
+
puts_step "#{text}"
|
101
|
+
puts
|
102
|
+
puts "#{quote}"
|
103
|
+
puts
|
104
|
+
end
|
105
|
+
|
106
|
+
# outputs a step for confirmation
|
107
|
+
def confirm_step text
|
108
|
+
cli.yes? "#{magenta('==>')} #{bold(text)}?"
|
109
|
+
end
|
110
|
+
|
111
|
+
# outputs a step
|
112
|
+
def puts_step text
|
113
|
+
puts "#{magenta('==>')} #{bold(text)}"
|
114
|
+
end
|
115
|
+
|
116
|
+
# colorizes text
|
117
|
+
def colorize(text, color_code)
|
118
|
+
"#{color_code}#{text}\033[0m"
|
119
|
+
end
|
120
|
+
|
121
|
+
def red(text); colorize(text, "\033[31m"); end
|
122
|
+
def green(text); colorize(text, "\033[32m"); end
|
123
|
+
def magenta(text); colorize(text, "\033[35m"); end
|
124
|
+
def light_green(text); colorize(text, "\033[32m"); end
|
125
|
+
def bold(text); "\033[1m#{text}\033[22m"; end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# load recipes
|
131
|
+
Dir["#{Bently::BENTLY_REPOSITORY}/lib/bently/recipe/*.rb"].map{ |f| File.basename f, '.rb' }.each do |f|
|
132
|
+
require 'bently/recipe/' + f
|
133
|
+
end
|
data/lib/bently.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bently
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benjamin Sullivan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &2151891060 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.14.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2151891060
|
25
|
+
description: Bently executes (bakes) predefined formulas (recipes) for trivial stuff
|
26
|
+
you do a lot
|
27
|
+
email: bsullivan2@gmail.com
|
28
|
+
executables:
|
29
|
+
- bently
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- README.md
|
37
|
+
- bently.gemspec
|
38
|
+
- bin/bently
|
39
|
+
- lib/bently.rb
|
40
|
+
- lib/bently/cli.rb
|
41
|
+
- lib/bently/core_ext/string.rb
|
42
|
+
- lib/bently/globals.rb
|
43
|
+
- lib/bently/recipe.rb
|
44
|
+
- lib/bently/recipe/devise.rb
|
45
|
+
- lib/bently/recipe/gitignore.rb
|
46
|
+
- lib/bently/recipe/haml-rails.rb
|
47
|
+
- lib/bently/recipe/resque.rb
|
48
|
+
- lib/bently/recipe/rspec-rails.rb
|
49
|
+
- lib/bently/recipe/twitter-bootstrap-rails.rb
|
50
|
+
- lib/bently/recipe/welcome-index.rb
|
51
|
+
homepage: http://github.com/bonsaiben/bently
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.17
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Bently executes (bakes) predefined formulas (recipes)
|
75
|
+
test_files: []
|
76
|
+
has_rdoc:
|