Module: RuremaFresh
- Defined in:
- lib/rurema_fresh.rb,
lib/rurema_fresh/option.rb,
lib/rurema_fresh/version.rb,
lib/rurema_fresh/constants.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.1"
- DEFAULT_SUPPORT_VERSION =
Rubyリファレンスマニュアルがサポートしている最古バージョンのつもり。
'2.4.0'
- HELP_URLS =
{ "GitHub" => "https://github.com/universato/rurema_fresh", "ruby-jp(ruremaチャンネル)" => "https://ruby-jp.github.io/", }
Class Method Summary collapse
- .options ⇒ Object
- .remove_old_versions(file_text, support_version = DEFAULT_SUPPORT_VERSION) ⇒ Object (also: versions)
- .replace_if(text, support_version) ⇒ Object
Class Method Details
.options ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rurema_fresh/option.rb', line 4 def self. = {} opt = OptionParser.new opt.version = RuremaFresh::VERSION opt. = "Usage: rurema_fresh versions ./rurema_file [--ruby=#{DEFAULT_SUPPORT_VERSION}]" opt.summary_width = 14 opt.summary_indent = ' ' * 4 opt.on('-r:', '--ruby', 'Ruby support version。サポートしたいRubyバージョン。'){ |version| [:ruby] = version } opt.on_tail('-h', '--help', 'show this help') { puts opt.help and exit } begin opt.parse!(ARGV) rescue OptionParser::InvalidOption => e puts e.inspect puts "RuremaFresh: サポートしてないオプションが入力されました" end end |
.remove_old_versions(file_text, support_version = DEFAULT_SUPPORT_VERSION) ⇒ Object Also known as: versions
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 |
# File 'lib/rurema_fresh.rb', line 10 def self.remove_old_versions(file_text, support_version = DEFAULT_SUPPORT_VERSION) support_version = add_minor(support_version) blocks = [] delete_mode = false file_text = self.replace_if(file_text, support_version) texts = file_text.lines texts.each_with_index do |text, line_no| if text.start_with?('#@since ', '#@until ') blocks << text.dup version = text.split[1] if version <= support_version delete_mode = true if text.start_with?('#@until ') text.clear end elsif text.start_with?('#@else') next if blocks[-1].start_with?('#@if') directive, version = blocks.pop.split if version <= support_version text.clear delete_mode = (directive == '#@since') end directive_swap(directive) blocks << [directive, version].join(' ') elsif text.start_with?('#@end') directive, version = blocks.pop.split if (directive == '#@since' || directive == '#@until') && version <= support_version text.clear delete_mode = false elsif (directive == '#@samplecode' || directive == '#@if') && delete_mode text.clear end if (directive, version = blocks.last&.split) if directive == '#@until' && version <= support_version delete_mode = true end end elsif text.start_with?('#@samplecode', '#@if') blocks << text.dup text.clear if delete_mode else text.clear if delete_mode end end texts.join end |
.replace_if(text, support_version) ⇒ Object
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 |
# File 'lib/rurema_fresh.rb', line 64 def self.replace_if(text, support_version) text.gsub(/^(\#@if\s*\(\s*version\s*([<>!=]=?)\s*["'](.+)["']\s*\))/){ zentai = $1 op = $2 version = $3 if op.include?('<') if op.include?('=') "\#@until #{self.ruby_advance(version)}" else "\#@until #{version}" end elsif op.include?('>') if op.include?('=') "\#@since #{version}" else "\#@since #{self.ruby_advance(version)}" end elsif op == "==" if version < support_version "\#@until #{self.ruby_advance(version)}" else zentai.sub('#@if(', '#@if (') end elsif op == "!=" if version < support_version "\#@since #{version}" else zentai.sub('#@if(', '#@if (') end else msg = "#{__FILE__}: #{__LINE__}行目:" msg += "本来、ここは実行されないはずです。異常終了します。" raise RuremaFresh::Error.new(msg) end }.gsub(/^(\#@if\s*\(\s*["'](.+)["']\s*(<=?)\s*version\s+and\s+version\s*(<=?)\s*["'](.+)["']\s*\))/){ zentai = $1 version1 = $2 _op = $3 op = $4 version2 = $5 if version1 < support_version if op.include?('=') "\#@until #{self.ruby_advance(version2)}" else "\#@until #{version2}" end else zentai.sub('#@if(', '#@if (') end } end |