put_rake 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02d551c439ad35a2c7f1b8dfe78f00807fc5c9f1b91c34d2c2eabae564462f9c
4
- data.tar.gz: 1d5d568ec4b4706ca950106d741a46e4ec45207bc8a4641569a9084fb223dad3
3
+ metadata.gz: e87dafe1567a8e779eaf345ae28990cb0aa5f9c3d466dcac150c0a6facbbed93
4
+ data.tar.gz: c8ef7121c564292ae99c78e1177e161a0b941230458de938cad3e0cfef8b3bad
5
5
  SHA512:
6
- metadata.gz: 57af2bb5e732c78a9fdc4f5cb4359ce0f6eda3e63f04bb9fac2956e6f0b4cff4e5db82b86f40b002ae17a9dd9d29edf1d21e25cd475d21b5d79d25b935f35acf
7
- data.tar.gz: ee7c7210625ce993438230dc85ab3c969490035feb36ff0721f006bc311613c5296cc5fc669b736c79a61648da987fdbe84de43fdecd56325fa962afa0880d6d
6
+ metadata.gz: 759ac7b416eca7097f74942ef8b858596fdcf5ac71d9c39ca81f61395cdb23ac7d27e24f132002a41bd65f2ddeed678dd186d657b62bb3e01ed2d2c0dadf09b2
7
+ data.tar.gz: 742693e9f23e19e83df8c74be1b790404ed5ae140f6ff965664b19614e31d518f5c34c88e9dcf56f84784fbde262a23366b3677535b090118df33d741a7db6d7
data/README.org CHANGED
@@ -27,6 +27,7 @@ put_rake commands:
27
27
  put_rake for [EXT] # put Rakefile for [EXT]
28
28
  put_rake help [COMMAND] # Describe available commands or one specific command
29
29
  put_rake list # list available Rakefiles
30
+ put_rake migrate # rename legacy Rakefile_* templates to *.rake
30
31
  put_rake path # show Rakefile template path
31
32
  put_rake version # show version
32
33
  #+end_src
@@ -44,6 +45,18 @@ by the following command:
44
45
  put_rake add /Users/hoge/bin/Rakefiles
45
46
  #+end_src
46
47
 
48
+ New templates should use the =NAME.rake= naming convention. The legacy
49
+ =Rakefile_NAME= convention remains available for backward compatibility.
50
+ Legacy templates in the default and additional template paths can be renamed
51
+ with:
52
+ #+begin_src bash
53
+ put_rake migrate --dry-run
54
+ put_rake migrate
55
+ #+end_src
56
+
57
+ If =NAME.rake= already exists, the corresponding =Rakefile_NAME= is skipped
58
+ without being overwritten.
59
+
47
60
  Happy Ruby.
48
61
 
49
62
  ** Development
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PutRake
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.11"
5
5
  end
data/lib/put_rake.rb CHANGED
@@ -24,11 +24,7 @@ module PutRake
24
24
 
25
25
  desc "path", "show Rakefile template path"
26
26
  def path
27
- tmp = ENV["PUT_RAKE_PATH"] || ""
28
- additional_path = tmp.split(":")
29
- @gem_template_dirs = [
30
- File.join(File.dirname(__FILE__), "templates"), additional_path,
31
- ].flatten
27
+ @gem_template_dirs = template_dirs
32
28
  puts "* Rakefile template paths\n #{@gem_template_dirs.join("\n ")}"
33
29
  end
34
30
 
@@ -53,11 +49,11 @@ on ~/.config/fish/fishconfig.fish."
53
49
  :aliases => "-a", :desc => "add to the Rakefile"
54
50
 
55
51
  def for(*args)
56
- file = "Rakefile_#{args[0]}"
52
+ files = ["#{args[0]}.rake", "Rakefile_#{args[0]}"]
57
53
  list()
58
- @file_path = @rake_file_path.collect do |path|
59
- path if File.basename(path) == file
60
- end.compact!
54
+ @file_path = @rake_file_path.select do |path|
55
+ files.include?(File.basename(path))
56
+ end
61
57
  if @file_path.size != 1 #check multiple name
62
58
  comment = <<~"HEREDOC"
63
59
  Multiple file name #{args}: edit source Rakefile name first.\n
@@ -82,6 +78,37 @@ HEREDOC
82
78
  system comm
83
79
  end
84
80
 
81
+ desc "migrate", "rename legacy Rakefile_* templates to *.rake"
82
+ method_option :dry_run, :type => :boolean, :default => false,
83
+ :aliases => "-n", :desc => "show changes without renaming"
84
+
85
+ def migrate
86
+ puts options[:dry_run] ? "* Template migration (dry run)" : "* Template migration"
87
+
88
+ template_dirs.each do |template_dir|
89
+ puts "** #{template_dir}"
90
+ unless Dir.exist?(template_dir)
91
+ puts " skipped: directory does not exist"
92
+ next
93
+ end
94
+
95
+ Dir.glob(File.join(template_dir, "Rakefile_*")).sort.each do |source|
96
+ next unless File.file?(source)
97
+ next if source.end_with?("~")
98
+
99
+ key = legacy_template_key(source)
100
+ destination = File.join(template_dir, "#{key}.rake")
101
+
102
+ if File.exist?(destination)
103
+ puts " skipped: #{File.basename(source)} -> #{File.basename(destination)} (destination exists)"
104
+ else
105
+ puts " #{File.basename(source)} -> #{File.basename(destination)}"
106
+ FileUtils.mv(source, destination) unless options[:dry_run]
107
+ end
108
+ end
109
+ end
110
+ end
111
+
85
112
  desc "list", "list available Rakefiles"
86
113
 
87
114
  def list
@@ -94,9 +121,12 @@ HEREDOC
94
121
  files = File.join(gem_template_dir, "*")
95
122
  Dir.glob(files).each do |file|
96
123
  next if file[-1] == "~"
97
- next unless File.basename(file) =~ /^Rakefile/
124
+ next unless File.file?(file)
125
+
126
+ key = template_key(file)
127
+ next unless key
128
+
98
129
  @rake_file_path << file
99
- key = file.match(/Rakefile_(.*)/)[1]
100
130
  res = command_line "rake -T -f #{file}"
101
131
  command = res.stdout.split("\n").collect do |line|
102
132
  line.include?(key) ? line : nil
@@ -109,5 +139,24 @@ HEREDOC
109
139
  end
110
140
  end
111
141
  end
142
+
143
+ no_commands do
144
+ def template_dirs
145
+ additional_paths = (ENV["PUT_RAKE_PATH"] || "").split(":").reject(&:empty?)
146
+ [File.join(File.dirname(__FILE__), "templates"), *additional_paths].uniq
147
+ end
148
+
149
+ def legacy_template_key(file)
150
+ File.basename(file).delete_prefix("Rakefile_")
151
+ end
152
+
153
+ def template_key(file)
154
+ basename = File.basename(file)
155
+ return legacy_template_key(file) if basename.start_with?("Rakefile_")
156
+ return File.basename(file, ".rake") if File.extname(file) == ".rake"
157
+
158
+ nil
159
+ end
160
+ end
112
161
  end
113
162
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: put_rake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shigeto R. Nishiani