claiss 1.0.8 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/claiss.rb +73 -75
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ef3d4170f9601194f42c8a03c6089aad440bda98a91ebce1b3a8d84a3ae21bd
|
4
|
+
data.tar.gz: 5386b3b64754fb15f7db09e85c0f6bfd53aa46ad9299ef905b7ad61ca7265d8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 788da6b6055fda32c443db38ce8cb4fa88057e4ca2f50560814b938adb02bec9b913fb068f1b7ae2afa09e6a8f9607cd52ca4bd91a308422e02ca728c9ce95b0
|
7
|
+
data.tar.gz: eee327c7ba60ba69ca65ed6672b7ebc886ede89a49cf1085c9bf75d9537b0364abd0401e507a8d33bfec7e8d552ec1d05511014bc71d19b87f7fa344b0697db3
|
data/lib/claiss.rb
CHANGED
@@ -8,90 +8,88 @@ require 'json'
|
|
8
8
|
module Claiss
|
9
9
|
extend Dry::CLI::Registry
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
class Version < Dry::CLI::Command
|
12
|
+
desc "Print version"
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
class Refactor < Dry::CLI::Command
|
22
|
-
desc "Refactors terms and files on directories"
|
23
|
-
argument :path, type: :string, required: true, desc: "Relative path directory"
|
24
|
-
argument :json_file, type: :string, desc: "Provide a Ruby hash file"
|
25
|
-
|
26
|
-
def call(path:, json_file: nil, **)
|
27
|
-
dict = {}
|
28
|
-
search = ""
|
29
|
-
replace = ""
|
30
|
-
input = "y"
|
31
|
-
temp_dir = "/refactored-#{Time.now.to_i.to_s}"
|
32
|
-
origin_path = File.expand_path(path)
|
33
|
-
destination_path = File.expand_path("."+ temp_dir)
|
34
|
-
|
35
|
-
|
36
|
-
if !json_file.nil?
|
37
|
-
jfile = File.read(json_file)
|
38
|
-
dict = JSON.parse(jfile)
|
39
|
-
else
|
40
|
-
while input.downcase == "y" do
|
41
|
-
puts "Term to search: "
|
42
|
-
search = STDIN.gets.chomp
|
43
|
-
puts "Term to replace: "
|
44
|
-
replace = STDIN.gets.chomp
|
45
|
-
|
46
|
-
dict[search] = replace
|
47
|
-
puts "\nAdd another? Type Y \nto Start Refactoring press Enter"
|
48
|
-
input = STDIN.gets.chomp!
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
dict = {origin_path => destination_path}.merge(dict)
|
53
|
-
dict[origin_path] = destination_path
|
54
|
-
source = File.expand_path(origin_path + "/**/{*,.*}", __FILE__)
|
55
|
-
Dir.glob(source).reject{ |f| File.directory?(f)}.each do |file_name|
|
56
|
-
destination = file_name
|
57
|
-
text = File.read(file_name) if !File.directory?(file_name)
|
14
|
+
def call(*)
|
15
|
+
spec = Gem::Specification::load("claiss.gemspec")
|
16
|
+
puts "#{spec.description}"
|
17
|
+
puts "Version: #{spec.version}"
|
18
|
+
end
|
19
|
+
end
|
58
20
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
21
|
+
class Refactor < Dry::CLI::Command
|
22
|
+
desc "Refactors terms and files on directories"
|
23
|
+
argument :path, type: :string, required: true, desc: "Relative path directory"
|
24
|
+
argument :json_file, type: :string, desc: "Provide a Ruby hash file"
|
25
|
+
|
26
|
+
def call(path:, json_file: nil, **)
|
27
|
+
dict = {}
|
28
|
+
search = ""
|
29
|
+
replace = ""
|
30
|
+
input = "y"
|
31
|
+
temp_dir = "/refactored-#{Time.now.to_i.to_s}"
|
32
|
+
origin_path = File.expand_path(path)
|
33
|
+
destination_path = File.expand_path("."+ temp_dir)
|
65
34
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
35
|
+
if !json_file.nil?
|
36
|
+
jfile = File.read(json_file)
|
37
|
+
dict = JSON.parse(jfile)
|
38
|
+
else
|
39
|
+
while input.downcase == "y" do
|
40
|
+
puts "Term to search: "
|
41
|
+
search = STDIN.gets.chomp
|
42
|
+
puts "Term to replace: "
|
43
|
+
replace = STDIN.gets.chomp
|
70
44
|
|
71
|
-
|
45
|
+
dict[search] = replace
|
46
|
+
puts "\nAdd another? Type Y \nto Start Refactoring press Enter"
|
47
|
+
input = STDIN.gets.chomp!
|
72
48
|
end
|
73
49
|
end
|
74
50
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
rails = `chmod 755 #{path+'/bin/rails'}`
|
88
|
-
rake = `chmod 755 #{path+'/bin/rake'}`
|
89
|
-
spring = `chmod 755 #{path+'/bin/spring'}`
|
51
|
+
dict = {origin_path => destination_path}.merge(dict)
|
52
|
+
dict[origin_path] = destination_path
|
53
|
+
source = File.join(origin_path, "**", "{*,.*}")
|
54
|
+
Dir.glob(source, File::FNM_DOTMATCH).each do |file_name|
|
55
|
+
next if File.directory?(file_name)
|
56
|
+
|
57
|
+
destination = file_name
|
58
|
+
text = File.read(file_name)
|
59
|
+
|
60
|
+
dict.each do |p, i|
|
61
|
+
destination.gsub!(p, i)
|
62
|
+
text.gsub!(p, i)
|
90
63
|
end
|
64
|
+
|
65
|
+
FileUtils.mkdir_p(File.dirname(destination))
|
66
|
+
File.write(destination, text)
|
67
|
+
puts "File: #{destination}, OK"
|
91
68
|
end
|
92
69
|
|
70
|
+
puts "done! your project is in the #{temp_dir} folder"
|
71
|
+
end
|
72
|
+
end
|
93
73
|
|
94
|
-
|
95
|
-
|
96
|
-
|
74
|
+
class FixRubyPermissions < Dry::CLI::Command
|
75
|
+
argument :path, required: true, desc: "The path of your ruby project"
|
76
|
+
|
77
|
+
def call(path: nil, **)
|
78
|
+
if path.nil?
|
79
|
+
path = File.basename(Dir.getwd)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Run shell scripts to set permissions.
|
83
|
+
directories = `chmod 755 $(find #{path} -type d)`
|
84
|
+
files = `chmod 644 $(find #{path} -type f)`
|
85
|
+
bundle = `chmod 755 #{path+'/bin/bundle'}`
|
86
|
+
rails = `chmod 755 #{path+'/bin/rails'}`
|
87
|
+
rake = `chmod 755 #{path+'/bin/rake'}`
|
88
|
+
spring = `chmod 755 #{path+'/bin/spring'}`
|
89
|
+
end
|
97
90
|
end
|
91
|
+
|
92
|
+
register "version", Version, aliases: ["v", "-v", "--version"]
|
93
|
+
register "refactor", Refactor
|
94
|
+
register "fix_ruby_permissions", FixRubyPermissions
|
95
|
+
end
|