-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkimono.rb
189 lines (146 loc) · 6.17 KB
/
kimono.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# Takes a list of ENV vars, records their value,
# sets them to null, runs the block, then ensures
# the ENV vars are restored at the end.
def suppress_env_vars(*vars, &block)
cache = {}
vars.each do |var|
cache[var] = ENV[var]
end
begin
vars.each do |var|
ENV[var] = nil
end
yield block
ensure
cache.each_pair do |key, value|
ENV[key] = value
end
end
end
# >----------------------------[ Initial Setup ]------------------------------<
initializer 'generators.rb', <<-RUBY
Rails.application.config.generators do |g|
end
RUBY
@recipes = ["devise", "bushido", "tane", "test_tools"]
def recipes; @recipes end
def recipe?(name); @recipes.include?(name) end
def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
def say_wizard(text); say_custom(@current_recipe || 'wizard', text) end
def ask_wizard(question)
ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
end
def yes_wizard?(question)
answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
case answer.downcase
when "yes", "y"
true
when "no", "n"
false
else
yes_wizard?(question)
end
end
def no_wizard?(question); !yes_wizard?(question) end
def multiple_choice(question, choices)
say_custom('question', question)
values = {}
choices.each_with_index do |choice,i|
values[(i + 1).to_s] = choice[1]
say_custom (i + 1).to_s + ')', choice[0]
end
answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
values[answer]
end
@current_recipe = nil
@configs = {}
@after_blocks = []
def after_bundler(&block); @after_blocks << [@current_recipe, block]; end
@after_everything_blocks = []
def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end
@before_configs = {}
def before_config(&block); @before_configs[@current_recipe] = block; end
# >----------------------[ Devise and devise_bushido_authenticatable ]----------------------<
@current_recipe = "devise"
@before_configs["devise"].call if @before_configs["devise"]
say_recipe "Devise"
@configs[@current_recipe] = config
gem "devise"
gem "devise_bushido_authenticatable", :git =>"https://github.com/Bushido/devise_cas_authenticatable.git"
after_bundler do
generate("devise:install")
generate("devise", "User")
Dir["db/migrate/*devise_create_*"].each do |file|
# Replace database_authenticatable with bushido_authenticatable in the migration
gsub_file file, "database_authenticatable :null => false", "bushido_authenticatable"
# Replace the following lines to create fields for extra attributes
gsub_file file, "t.recoverable", "t.string :email"
inject_into_file file, "t.string :first_name\n", :before => "t.timestamps\n"
inject_into_file file, " \n ", :before => "t.timestamps\n"
inject_into_file file, " t.string :last_name\n", :after => "t.string :first_name\n"
inject_into_file file, " t.string :locale\n", :after => "t.string :last_name\n"
inject_into_file file, " t.string :timezone\n", :after => "t.string :locale\n"
# Replace add_index for reset_password_token with ido_id
gsub_file file, "reset_password_token", "ido_id"
end
user_model_file = "app/models/user.rb"
inject_into_class user_model_file, "User" do
<<-EOF
def bushido_extra_attributes(extra_attributes)
self.first_name = extra_attributes["first_name"].to_s
self.last_name = extra_attributes["last_name"].to_s
self.email = extra_attributes["email"]
self.locale = extra_attributes["locale"]
self.timezone = extra_attributes["timezone"]
end
EOF
end
gsub_file user_model_file, ":recoverable, :rememberable, :trackable, :validatable", ""
gsub_file user_model_file, ":database_authenticatable, :registerable,", ":bushido_authenticatable"
gsub_file user_model_file,
"attr_accessible :email, :password, :password_confirmation, :remember_me",
"attr_accessible :email, :ido_id, :first_name, :last_name"
suppress_env_vars("BUNDLE_BIN_PATH", "BUNDLE_GEMFILE", "RUBYOPT") do
run("bundle exec rake db:migrate")
end
end
# >-------------------------------[ Bushido ]---------------------------------<
@current_recipe = "bushido"
@before_configs["bushido"].call if @before_configs["bushido"]
say_recipe "Bushido"
@configs[@current_recipe] = config
gem "bushido", :git=>"https://github.com/Bushido/bushidogem.git"
after_bundler do
generate("bushido:mail_routes")
generate("bushido:hooks")
generate("bushido:routes")
end
# >----------------------------------[ Tane ]----------------------------------<
@current_recipe = "tane"
@before_configs["tane"].call if @before_configs["tane"]
say_recipe "Tane"
gem "tane", :group => "development", :git => "https://github.com/Bushido/tane.git"
run "rm ./public/index.html"
get 'https://raw.github.com/Bushido/kimono/master/index.html', "public/index.html"
# >-------------------------------[ Test Tools ]-------------------------------<
@current_recipe = "test_tools"
@before_configs["test_tools"].call if @before_configs["test_tools"]
say_recipe "Test tools"
gem "rspec-rails", :group => "development"
gem "factory_girl_rails", :group => "development"
gem "awesome_print", :group => "development"
# >-----------------------------[ Run Bundler ]-------------------------------<
@current_recipe = nil
say_wizard "Running Bundler install. This will take a while."
say_wizard "Running from : #{Dir.pwd}"
suppress_env_vars("BUNDLE_BIN_PATH", "BUNDLE_GEMFILE", "RUBYOPT") do
run 'bundle install --quiet'
end
say_wizard "Running after Bundler callbacks."
suppress_env_vars("BUNDLE_BIN_PATH", "BUNDLE_GEMFILE", "RUBYOPT") do
@after_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}
end
@current_recipe = nil
say_wizard "Running after everything callbacks."
@after_everything_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}