-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevise2thor.rb
101 lines (66 loc) · 1.55 KB
/
devise2thor.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
#!/usr/bin/env ruby
# usage: ruby ../bashrail/thor/t2.rb gsub1 a
#
# eg:
# cd /var/raila
# ruby ../bashrail/thor/t2.rb gem1 anyparameter
# this will operate on files in raila
# bashrail/ must be beside raila/
require "thor"
class Rail308 < Thor
include Thor::Actions
desc "add to a file", "gsub file"
def gsub1(name)
path1 = 'config/initializers/devise.rb'
#
# change password_length..
#
gsub_file path1 , /config.password_length = 6..128/ do
<<-'RUBY'
config.password_length = 1..128
RUBY
end
#
# change email regex check...
#
gsub_file path1 , 'config.email_regexp = /\A[^@\s]+@[^@\s]+\z/' do
<<-'RUBY'
# config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
config.email_regexp = /./
RUBY
end
puts File.dirname(__FILE__)
puts "gsub1"
end
desc "add to a file", "gsub stylesheet file"
def gsub2(name)
#
# add devise bootstrap views.....
#
path2 = 'app/assets/stylesheets/application.scss'
gsub_file path2 , '= require_self' do
<<-'RUBY'
= require_self
*= require devise_bootstrap_views
RUBY
end
end
desc "add logout link to home page..." , "edit file(s)"
def gsub3(name)
#
# add logout link...
#
prepend_file 'app/views/home/index.html.erb', <<-'RUBY'
<% if user_signed_in? %>
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
<% else %>
<%= link_to('Login', new_user_session_path) %>
<%end %>
RUBY
end
def self.source_root
File.dirname(__FILE__)
end
#class end
end
Rail308.start(ARGV)