rurema_fresh 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +164 -0
- data/Rakefile +12 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/exe/rurema_fresh +60 -0
- data/lib/rurema_fresh.rb +184 -0
- data/lib/rurema_fresh/constants.rb +9 -0
- data/lib/rurema_fresh/option.rb +26 -0
- data/lib/rurema_fresh/version.rb +5 -0
- data/rurema_fresh.gemspec +38 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6a6140a8c89ccc7bbf377b530bf644dfa9206711fc45889e7942a92b99aa5b6
|
4
|
+
data.tar.gz: '0940fb48eeb2330a45a2275d4586a79f0097e38eb1f2884f9866ec24802a45f0'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbb6a6f1a086f1688542f3c9784145187fa287b9f3fdacb57d355977684ce688814a0b87f3a4b9f30ed510b7806c86f02017ac9d3858245eeeb6afff958e86e1
|
7
|
+
data.tar.gz: 0d44803fdeafe2a9bbf867ecbe3f27379a2e068ddfc5d2288b28359a5bac159cde64a5e9c097338be9b7909594ff01bf4f62400ed57c70ceb34793169f33f924
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at @uniersato. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 universato
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
# RuremaFresh
|
2
|
+
|
3
|
+
RuremaFreshは、るりまの愛称で知られるRubyリファレンスマニュアルのrd形式の文書の整形・サポートを目的としたgemです。
|
4
|
+
|
5
|
+
なお、現在は、「古い条件分岐の削除、可能なら`if`を`since`や`until`に置き換える、メソッド・コマンド」のみを提供しています。
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
主なインストール方法を紹介します。
|
10
|
+
|
11
|
+
- gemの`bundler`を用いてインストールする方法
|
12
|
+
1. `Gemfile`に`gem 'rurema_fresh', :github => 'universato/rurema_fresh'`と書きます。
|
13
|
+
2. コマンド`bundle install`で、Gemfile(& Gemfile.lock)に従って、インストール。
|
14
|
+
<!-- - コマンド`gem install rurema_fresh`を打ち、インストール。 -->
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
### コマンドでファイルを破壊的に変更する方法
|
19
|
+
|
20
|
+
Command `rurema_fresh versions` destructively modifies the file.
|
21
|
+
|
22
|
+
コマンドを使って、ファイルを書き換えます。
|
23
|
+
念のためGitでコミットを打つなど戻せる状態でコマンドを実行してください。
|
24
|
+
|
25
|
+
`gem`コマンドではなく、`bundler`の`bundle`コマンドでGemfileで指定しインストールしている場合は、
|
26
|
+
`bundler`を通してコマンドを打てるように、
|
27
|
+
`bundle exec rurema_fresh versions`コマンドを打って下さい。
|
28
|
+
|
29
|
+
また、`versions`と複数形になっていることに注意してください。
|
30
|
+
複数の古いバージョン分岐を削除し、サポート対象範囲の複数のバージョンのものが残る可能性があるため、複数形にしています。
|
31
|
+
|
32
|
+
```sh
|
33
|
+
$ cat sample.rd
|
34
|
+
#@samplecode
|
35
|
+
#@since 2.4.0
|
36
|
+
puts "Hello, World!"
|
37
|
+
#@else
|
38
|
+
puts "Goodbye, World!"
|
39
|
+
#@end
|
40
|
+
#@end
|
41
|
+
#@until 2.3.0
|
42
|
+
#@samplecode
|
43
|
+
puts "old"
|
44
|
+
#@end
|
45
|
+
#@end
|
46
|
+
|
47
|
+
$ rurema_fresh versions sample.rb --ruby=2.4.0
|
48
|
+
sample.rd
|
49
|
+
上記のファイルについて、Ruby2.4.0より古い条件分岐がありました
|
50
|
+
9行、削除しました。
|
51
|
+
|
52
|
+
$ cat sample.rd
|
53
|
+
#@samplecode
|
54
|
+
puts "Hello, World!"
|
55
|
+
#@end
|
56
|
+
```
|
57
|
+
|
58
|
+
### コード上で、文字列から古い条件分岐を削除した文字列を生成して返す方法
|
59
|
+
|
60
|
+
コード上で文字列の条件分岐を削除するときは、以下のように使います。
|
61
|
+
```ruby
|
62
|
+
require 'rurema_fresh'
|
63
|
+
|
64
|
+
src = <<-'TEXT'
|
65
|
+
#@samplecode
|
66
|
+
#@since 1.9.0
|
67
|
+
# 0番目の文字を返す
|
68
|
+
p "abc"[0] #=> "a"
|
69
|
+
#@else
|
70
|
+
# 0番目の文字コードを返す
|
71
|
+
p "abc"[0] #=> 97
|
72
|
+
#@end
|
73
|
+
#@end
|
74
|
+
TEXT
|
75
|
+
|
76
|
+
puts RuremaFresh.remove_old_versions(src, '2.4.0')
|
77
|
+
# alias RuremaFresh.versions
|
78
|
+
```
|
79
|
+
↓
|
80
|
+
```rb
|
81
|
+
#@samplecode
|
82
|
+
# 0番目の文字を返す
|
83
|
+
p "abc"[0] #=> "a"
|
84
|
+
#@end
|
85
|
+
```
|
86
|
+
引数の文字列を破壊的に変更することはなく、新しい文字列を生成して返します。
|
87
|
+
|
88
|
+
### versionsサブコマンドによるif文の対応
|
89
|
+
|
90
|
+
#### 対応済み
|
91
|
+
- `#@if( version >= "2.0.0")`は、`#@since 2.0.0`に置き換えた上で、古ければ削除します。
|
92
|
+
- `#@if( version < "2.0.0")`は、`#@until 2.0.0`に置き換えた上で、古ければ削除します。
|
93
|
+
- `#@if( version > "1.8.7")`は、`#@since 1.9.0`とバージョンを上げ置き換えた上で、古ければ削除します。
|
94
|
+
- `#@if( version <= "2.7.0")`は、`#@until 3.0.0`とバージョンを上げ置き換えた上で、古ければ削除します。
|
95
|
+
- `#@if( version == 1.0.0)`は、条件分岐が古ければ削除し、そうでなければif文のままです。
|
96
|
+
- `#@if( version != 1.0.0)`は、条件分岐が古ければ削除し、そうでなければif文のままです。
|
97
|
+
- `#@if ( "1.0.0" < version and version <= "1.5.0" )`で、1つ目の条件分岐が古ければ、2つ目の式だけを`#@until`に置き換え、さらに古ければ削除します。1つめの条件分岐がサポート対象範囲の場合、if文のままです。
|
98
|
+
|
99
|
+
なお `#@if(`のように、`#@if`と`(`の間にスペースがないif文は、間にスペースを入れます。
|
100
|
+
|
101
|
+
#### 未対応
|
102
|
+
|
103
|
+
- `#@if ( "1.0.0" < version)`のように、具体的なバージョンが左のもの。
|
104
|
+
- `#@if ( version > "1.0.0" and version <= "3.0.0")`のような、両式のversionが中央に来てないもの。
|
105
|
+
|
106
|
+
これらの式が来たときは、スルーします。
|
107
|
+
|
108
|
+
### 注意点
|
109
|
+
|
110
|
+
`#@since`は「以上」の指定ですが、`#@until`は「未満」の指定です。
|
111
|
+
|
112
|
+
#### since の例
|
113
|
+
|
114
|
+
`sample_since.rd`
|
115
|
+
```sh
|
116
|
+
#@since 3.0.0
|
117
|
+
3.0.0以上の環境で出力される。
|
118
|
+
#@end
|
119
|
+
```
|
120
|
+
|
121
|
+
`rurema_fresh versions sample_since.rd --ruby=3.0.0`
|
122
|
+
|
123
|
+
このコマンドはサポートの最低バージョンとして`3.0.0`を指定しており、
|
124
|
+
条件分岐が不要になり、中身の文章「3.0.0以上の環境で出力される。」だけが出力されます。
|
125
|
+
|
126
|
+
#### until の例
|
127
|
+
|
128
|
+
`sample_until.rd`
|
129
|
+
```sh
|
130
|
+
#@until 3.0.0
|
131
|
+
3.0.0未満の環境で出力される。
|
132
|
+
#@end
|
133
|
+
```
|
134
|
+
|
135
|
+
`rurema_fresh versions sample_until.rd --ruby=3.0.0`
|
136
|
+
|
137
|
+
このコマンドはサポートの最低バージョンとして`3.0.0`を指定しており、
|
138
|
+
条件分岐が不要になり、中身の文章は`3.0.0`未満でのみ必要とされ、
|
139
|
+
`3.0.0`以上では必要なくなり、条件分岐のブロックとともに中身も消えます。
|
140
|
+
|
141
|
+
## Development
|
142
|
+
|
143
|
+
<!-- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
144
|
+
|
145
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). -->
|
146
|
+
|
147
|
+
### 全体のテスト
|
148
|
+
|
149
|
+
当rurema_freshのディレクトリに移動した上で、
|
150
|
+
`rake test`ないし`rake`で、全体のテストを実行します。
|
151
|
+
|
152
|
+
もしくは、`ruby ./test/rurema_fresh_test`で実行できます。
|
153
|
+
|
154
|
+
### 個別のテスト
|
155
|
+
|
156
|
+
Ruby標準の`minitest`を用いテストを書いており、個別のテストメソッドを実行するには、
|
157
|
+
当rurema_freshのディレクトリに移動した上で、
|
158
|
+
`ruby ./test/rurema_fresh_test --name=test_remove_old_since1`
|
159
|
+
とテストしたいメソッド名を`name`オプションで指定することで実行できます。
|
160
|
+
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
改善に繋がるかもしれないと思えば、自由にPull RequestやIssueを送ってください。
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "rurema_fresh"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require "irb"
|
11
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/rurema_fresh
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/rurema_fresh.rb'
|
4
|
+
|
5
|
+
# サブコマンドで条件分岐
|
6
|
+
case ARGV[0]
|
7
|
+
when "versions"
|
8
|
+
# rurema_fresh versions ./refm/api/src/_builtin/Array --ruby=2.4.0
|
9
|
+
# puts "rurema_freshコマンドを実行するよ"
|
10
|
+
ARGV.shift # => "version"
|
11
|
+
options = RuremaFresh.options
|
12
|
+
support_version = options[:ruby] || RuremaFresh::DEFAULT_SUPPORT_VERSION
|
13
|
+
|
14
|
+
if file_path = ARGV.shift
|
15
|
+
begin
|
16
|
+
buffer = IO.read(file_path)
|
17
|
+
rescue Errno::ENOENT
|
18
|
+
puts file_path
|
19
|
+
puts "このコマンド引数のファイルを探しましたが見つからなかったので、終了します。"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
|
23
|
+
new_buffer = RuremaFresh.remove_old_versions(buffer, support_version)
|
24
|
+
IO.write(file_path, new_buffer)
|
25
|
+
|
26
|
+
if new_buffer.size == buffer.size
|
27
|
+
puts file_path
|
28
|
+
puts "上記のファイルについて、Ruby#{support_version}より古い条件分岐はありませんでした。"
|
29
|
+
else
|
30
|
+
puts file_path
|
31
|
+
puts "上記のファイルについて、Ruby#{support_version}より古い条件分岐があり、"
|
32
|
+
puts "#{buffer.lines.size - new_buffer.lines.size}行、削除しました。"
|
33
|
+
end
|
34
|
+
else
|
35
|
+
puts "rurema_fresh versions の後ろにファイル名を入れてコマンドを打ってください"
|
36
|
+
puts "なお、デフォルトの最低サポートバージョンは、#{RuremaFresh::DEFAULT_SUPPORT_VERSION}です。"
|
37
|
+
puts "これより古い分岐となるものは、削除されます。"
|
38
|
+
puts "サポートしたいバージョンを変更したい場合は、--ruby=2.0.0 のように変更してください。"
|
39
|
+
puts "指定されたバージョンより古い分岐は、削除されます。"
|
40
|
+
end
|
41
|
+
else
|
42
|
+
if ARGV.empty?
|
43
|
+
puts "rurema_fresh は、versions サブコマンドを持ちます。"
|
44
|
+
puts "次のように使えます。"
|
45
|
+
puts "rurema_fresh versions ./refm/api/src/_builtin/Array --ruby=2.4.0"
|
46
|
+
puts "疑問点があったら、ruby-jpのruremaチャンネルやGitHubで聞いてください"
|
47
|
+
pp RuremaFresh::HELP_URLS
|
48
|
+
else
|
49
|
+
begin
|
50
|
+
options = RuremaFresh.options
|
51
|
+
if options == {} && ARGV[0]
|
52
|
+
puts "#{ARGV[0]} <- There is no such a subcommand in rurema_fresh
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
rescue OptionParser::MissingArgument => e
|
56
|
+
puts e.inspect
|
57
|
+
puts "サポートしてないオプションが入力されてました"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/rurema_fresh.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./rurema_fresh/constants.rb"
|
4
|
+
require_relative "./rurema_fresh/option.rb"
|
5
|
+
require_relative "./rurema_fresh/version.rb"
|
6
|
+
|
7
|
+
module RuremaFresh
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
def self.remove_old_versions(file_text, support_version = DEFAULT_SUPPORT_VERSION)
|
11
|
+
support_version = add_minor(support_version)
|
12
|
+
|
13
|
+
blocks = []
|
14
|
+
delete_mode = false
|
15
|
+
|
16
|
+
file_text = file_text.gsub(/^(\#@if\s*\(\s*version\s*([<>!=]=?)\s*["'](.+)["']\s*\))/){
|
17
|
+
zentai = $1
|
18
|
+
op = $2
|
19
|
+
version = $3
|
20
|
+
if op.include?('<')
|
21
|
+
if op.include?('=')
|
22
|
+
"\#@until #{self.ruby_advance(version)}"
|
23
|
+
else
|
24
|
+
"\#@until #{version}"
|
25
|
+
end
|
26
|
+
elsif op.include?('>')
|
27
|
+
if op.include?('=')
|
28
|
+
"\#@since #{version}"
|
29
|
+
else
|
30
|
+
"\#@since #{self.ruby_advance(version)}"
|
31
|
+
end
|
32
|
+
elsif op == "=="
|
33
|
+
if version < support_version
|
34
|
+
"\#@until #{self.ruby_advance(version)}"
|
35
|
+
else
|
36
|
+
zentai.sub('#@if(', '#@if (')
|
37
|
+
end
|
38
|
+
elsif op == "!="
|
39
|
+
if version < support_version
|
40
|
+
"\#@since #{version}"
|
41
|
+
else
|
42
|
+
zentai.sub('#@if(', '#@if (')
|
43
|
+
end
|
44
|
+
else
|
45
|
+
puts "RuremaFresh #{__FILE__}: #{__LINE__}行目:"
|
46
|
+
puts "本来、ここは実行されないはずです。異常終了します。"
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
}.gsub(/^(\#@if\s*\(\s*["'](.+)["']\s*(<=?)\s*version\s+and\s+version\s*(<=?)\s*["'](.+)["']\s*\))/){
|
50
|
+
|
51
|
+
zentai = $1
|
52
|
+
version1 = $2
|
53
|
+
_op = $3
|
54
|
+
op = $4
|
55
|
+
version2 = $5
|
56
|
+
|
57
|
+
if version1 < support_version
|
58
|
+
if op.include?('=')
|
59
|
+
"\#@until #{self.ruby_advance(version2)}"
|
60
|
+
else
|
61
|
+
"\#@until #{version2}"
|
62
|
+
end
|
63
|
+
else
|
64
|
+
zentai.sub('#@if(', '#@if (')
|
65
|
+
end
|
66
|
+
}
|
67
|
+
|
68
|
+
texts = file_text.lines
|
69
|
+
texts.each_with_index do |text, line_no|
|
70
|
+
if text.start_with?('#@since ', '#@until ')
|
71
|
+
blocks << text.dup
|
72
|
+
version = text.split[1]
|
73
|
+
if version <= support_version
|
74
|
+
delete_mode = true if text.start_with?('#@until ')
|
75
|
+
text.clear
|
76
|
+
end
|
77
|
+
elsif text.start_with?('#@else')
|
78
|
+
next if blocks[-1].start_with?('#@if')
|
79
|
+
directive, version = blocks.pop.split
|
80
|
+
if version <= support_version
|
81
|
+
text.clear
|
82
|
+
delete_mode = (directive == '#@since')
|
83
|
+
end
|
84
|
+
directive_swap(directive)
|
85
|
+
blocks << [directive, version].join(' ')
|
86
|
+
elsif text.start_with?('#@end')
|
87
|
+
directive, version = blocks.pop.split
|
88
|
+
if (directive == '#@since' || directive == '#@until') && version <= support_version
|
89
|
+
text.clear
|
90
|
+
delete_mode = false
|
91
|
+
elsif (directive == '#@samplecode' || directive == '#@if') && delete_mode
|
92
|
+
text.clear
|
93
|
+
end
|
94
|
+
|
95
|
+
if (directive, version = blocks.last&.split)
|
96
|
+
if directive == '#@until' && version <= support_version
|
97
|
+
delete_mode = true
|
98
|
+
end
|
99
|
+
end
|
100
|
+
elsif text.start_with?('#@samplecode', '#@if')
|
101
|
+
blocks << text.dup
|
102
|
+
text.clear if delete_mode
|
103
|
+
else
|
104
|
+
text.clear if delete_mode
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
texts.join
|
109
|
+
end
|
110
|
+
class << self
|
111
|
+
alias versions remove_old_versions
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
# module RuremaFresh
|
116
|
+
# directive = '#@since 2.4.0'
|
117
|
+
# RuremaFresh.directive_swap(directive)
|
118
|
+
# p directive # => '#@until 2.4.0'
|
119
|
+
# RuremaFresh.directive_swap(directive)
|
120
|
+
# p directive # => '#@since 2.4.0'
|
121
|
+
# end
|
122
|
+
def self.directive_swap(directive)
|
123
|
+
raise ArgumentError.new('引数は、#@since or #@until のみです') unless directive == '#@since' || directive == '#@until'
|
124
|
+
directive.sub!('#@since', '#@_____')
|
125
|
+
directive.sub!('#@until', '#@since')
|
126
|
+
directive.sub!('#@_____', '#@until')
|
127
|
+
end
|
128
|
+
|
129
|
+
# module RuremaFresh
|
130
|
+
# self.add_minor(0) # => "0.0.0"
|
131
|
+
# self.add_minor(2) # => "2.0.0"
|
132
|
+
# self.add_minor("2") # => "2.0.0"
|
133
|
+
# self.add_minor(2.4) # => "2.4.0"
|
134
|
+
# self.add_minor("2.4") # => "2.4.0"
|
135
|
+
# end
|
136
|
+
def self.add_minor(version)
|
137
|
+
version = version.to_s
|
138
|
+
if Gem::Version.correct?(version)
|
139
|
+
case version.count(".")
|
140
|
+
when 0
|
141
|
+
version + ".0.0"
|
142
|
+
when 1
|
143
|
+
version + ".0"
|
144
|
+
else
|
145
|
+
version
|
146
|
+
end
|
147
|
+
else
|
148
|
+
puts "RuremaFresh: #{__FILE__}:#{__LINE__}行目でエラーが生じました。"
|
149
|
+
puts "#{version}: 不正なバージョン入力です。終了します。"
|
150
|
+
exit
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# module RuremaFresh
|
155
|
+
# self.advance("1.8.7") # => "1.9.0"
|
156
|
+
# self.advance("1.9.1") # => "2.0.0"
|
157
|
+
# self.advance("2.0.0") # => "2.1.0"
|
158
|
+
# self.advance("2.4.0") # => "2.5.0"
|
159
|
+
# self.advance("2.7.0") # => "3.0.0"
|
160
|
+
# end
|
161
|
+
def self.ruby_advance(version)
|
162
|
+
version = Gem::Version.new(version).bump.version
|
163
|
+
self.add_minor(version).gsub("2.8.0", "3.0.0")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
# For debug
|
169
|
+
if $0 == __FILE__
|
170
|
+
# puts "#{__FILE__}が直接実行されました。"
|
171
|
+
# text = DATA.readlines.join
|
172
|
+
# puts RuremaFresh.remove_old_versions(text, "2.4.0")
|
173
|
+
end
|
174
|
+
|
175
|
+
__END__
|
176
|
+
#@samplecode
|
177
|
+
#@since 1.9.0
|
178
|
+
# 0番目の文字を返す
|
179
|
+
p "abc"[0] #=> "a"
|
180
|
+
#@else
|
181
|
+
# 0番目の文字コードを返す
|
182
|
+
p "abc"[0] #=> 97
|
183
|
+
#@end
|
184
|
+
#@end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module RuremaFresh
|
4
|
+
def self.options
|
5
|
+
options = {}
|
6
|
+
|
7
|
+
opt = OptionParser.new
|
8
|
+
opt.version = RuremaFresh::VERSION
|
9
|
+
opt.banner = "Usage: rurema_fresh versions ./rurema_file [--ruby=#{DEFAULT_SUPPORT_VERSION}]"
|
10
|
+
opt.summary_width = 14
|
11
|
+
opt.summary_indent = ' ' * 4
|
12
|
+
opt.on('-r:', '--ruby', 'Ruby support version。サポートしたいRubyバージョン。'){ |version|
|
13
|
+
options[:ruby] = version
|
14
|
+
}
|
15
|
+
opt.on_tail('-h', '--help', 'show this help') { puts opt.help and exit }
|
16
|
+
|
17
|
+
begin
|
18
|
+
opt.parse!(ARGV)
|
19
|
+
rescue OptionParser::InvalidOption => e
|
20
|
+
puts e.inspect
|
21
|
+
puts "RuremaFresh: サポートしてないオプションが入力されました"
|
22
|
+
end
|
23
|
+
|
24
|
+
options
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/rurema_fresh/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rurema_fresh"
|
7
|
+
spec.version = RuremaFresh::VERSION
|
8
|
+
spec.authors = ["universato"]
|
9
|
+
spec.email = ["universato@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "るりまの since & until の古い分岐を削除します"
|
12
|
+
spec.description = "ifの分岐には対応したいけど、対応は未定です。"
|
13
|
+
spec.homepage = "https://github.com/universato/rurema_fresh"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/universato/rurema_fresh"
|
21
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
spec.add_dependency "rake", "~> 13.0"
|
34
|
+
spec.add_dependency "minitest", "~> 5.0"
|
35
|
+
|
36
|
+
# For more information and examples about making a new gem, checkout our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rurema_fresh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- universato
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
description: ifの分岐には対応したいけど、対応は未定です。
|
42
|
+
email:
|
43
|
+
- universato@gmail.com
|
44
|
+
executables:
|
45
|
+
- rurema_fresh
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- exe/rurema_fresh
|
58
|
+
- lib/rurema_fresh.rb
|
59
|
+
- lib/rurema_fresh/constants.rb
|
60
|
+
- lib/rurema_fresh/option.rb
|
61
|
+
- lib/rurema_fresh/version.rb
|
62
|
+
- rurema_fresh.gemspec
|
63
|
+
homepage: https://github.com/universato/rurema_fresh
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata:
|
67
|
+
homepage_uri: https://github.com/universato/rurema_fresh
|
68
|
+
source_code_uri: https://github.com/universato/rurema_fresh
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.4.0
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.2.11
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: るりまの since & until の古い分岐を削除します
|
88
|
+
test_files: []
|