anytick 0.1.0 → 0.2.0

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: a408362c0d9cdefc8a88750e3aacdd35afce73d44afaa864aa2bb6320a640acd
4
- data.tar.gz: f8462d6b1f2a2f8768fb9db3f023ef42235a16c57cd9a81cad07e9a248b1dc9e
3
+ metadata.gz: ddcdbc6e54c941064e4867b9ab8c2141be3bbb0a3cbc3b9ad21fea3782fe2723
4
+ data.tar.gz: 2e27749216a2ad6b6f02df7f78f7518783b89c6d1ca2733c07ea7b4c2dcbd1aa
5
5
  SHA512:
6
- metadata.gz: 717a209d1c87d34b93052e11e2f0e348df391e9ffc1854ca41b285d64a7c2bb5cad1beed7f4f023ed91fb1ae3c7a4ad7ccf1446414ebc03af4bc3dfdbd2d0ef4
7
- data.tar.gz: ef261b360c1621baa6b1907c91ddfaf1b80fbd35f259ae97b91671a2676431db652ab7caa966a76ec06aaca263a5516a8050c57cb04a3a327700bac4106fa4b1
6
+ metadata.gz: f0036faacefaec3e58fad39a096d1ade763cb9331d80e1c9ebd6cbf79fde178cfe7dd15eb957643fc6041016a9445f3b3c5ffbae64c89d44492a39d1bb69588f
7
+ data.tar.gz: 84f31f6942d0fcb888238de4f5c821423a5bd5c89a89c5fe1356992b6768350856a7e4a40e48ce428c842d35b3592f74df0e3980c2bd0a9c94e421ab457a8db5
data/.gitignore CHANGED
@@ -9,6 +9,7 @@
9
9
  /vendor/
10
10
  /Gemfile.lock
11
11
  /README.html
12
+ /CHANGELOG.html
12
13
  *~
13
14
  .#*
14
15
  \#*
@@ -0,0 +1,14 @@
1
+ Change Log
2
+ ==========
3
+
4
+ 0.2.0
5
+ -----
6
+ Released on 2020-02-10.
7
+
8
+ ### Added
9
+ - Add trailing arguments forwarding on define method rule.
10
+ [#1](https://github.com/y10k/anytick/issues/1)
11
+
12
+ 0.1.0
13
+ -----
14
+ Released on 2019-12-28.
data/README.md CHANGED
@@ -3,7 +3,7 @@ Anytick
3
3
 
4
4
  Anytick extends ruby's backtick notation to do more than run a shell
5
5
  command. For example, it defines the def method syntax in backtick,
6
- and makes Ruby 2.7's argument forwarding notation of `(...)' usable
6
+ and makes Ruby 2.7's arguments forwarding notation of `(...)` usable
7
7
  with Ruby 2.6.
8
8
 
9
9
  Installation
data/Rakefile CHANGED
@@ -23,6 +23,10 @@ desc 'Build README.html from markdown source'
23
23
  task :readme => %w[ README.html ]
24
24
  CLOBBER.include 'README.html'
25
25
 
26
+ desc 'Build CHANGELOG.html from markdown source'
27
+ task :changelog => %w[ CHANGELOG.html ]
28
+ CLOBBER.include 'CHANGELOG.html'
29
+
26
30
  # Local Variables:
27
31
  # mode: Ruby
28
32
  # indent-tabs-mode: nil
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = <<-'EOF'
13
13
  Anytick extends ruby's backtick notation to do more than run a
14
14
  shell command. For example, it defines the def method syntax in
15
- backtick, and makes Ruby 2.7's argument forwarding notation of
15
+ backtick, and makes Ruby 2.7's arguments forwarding notation of
16
16
  `(...)' usable with Ruby 2.6.
17
17
  EOF
18
18
  spec.homepage = 'https://github.com/y10k/anytick'
@@ -44,6 +44,10 @@ module Anytick
44
44
  end
45
45
 
46
46
  autoload :DefineMethod, 'anytick/defmethod'
47
+
48
+ def self.DefineMethod(**kw_args)
49
+ DefineMethod.new(**kw_args)
50
+ end
47
51
  end
48
52
 
49
53
  # Local Variables:
@@ -2,32 +2,49 @@
2
2
 
3
3
  module Anytick
4
4
  class DefineMethod < RuleMaker
5
+ def initialize(trailing_arguments_forwarding: true)
6
+ @trailing_arguments_forwarding = trailing_arguments_forwarding
7
+ @trailing_arguments_forwarding_mark = (@trailing_arguments_forwarding.is_a? String) ? @trailing_arguments_forwarding : '[...]'
8
+ end
9
+
5
10
  def match?(expr)
6
11
  (/\A \s* def \s+/x.match? expr) && (/\b end \s* \z/x.match? expr)
7
12
  end
8
13
 
14
+ def first_line(expr)
15
+ expr.lstrip.each_line.first
16
+ end
17
+ private :first_line
18
+
9
19
  if ((RUBY_VERSION.split('.').map(&:to_i) <=> [ 2, 7 ]) >= 0) then
10
- def compat(expr)
11
- expr
20
+ def arg_fwd(expr)
21
+ first_line = first_line(expr)
22
+ if (@trailing_arguments_forwarding && (first_line.include? @trailing_arguments_forwarding_mark)) then
23
+ expr.gsub(@trailing_arguments_forwarding_mark, '*__args__, **__kw_args__, &__block__')
24
+ else
25
+ expr
26
+ end
12
27
  end
13
28
  else
14
- def compat(expr)
15
- first_line = expr.lstrip.each_line.first
16
- if (first_line.include? '(...)') then
29
+ def arg_fwd(expr)
30
+ first_line = first_line(expr)
31
+ if (@trailing_arguments_forwarding && (first_line.include? @trailing_arguments_forwarding_mark)) then
32
+ expr.gsub(@trailing_arguments_forwarding_mark, '*__args__, &__block__')
33
+ elsif (first_line.include? '(...)') then
17
34
  expr.gsub('(...)', '(*__args__, &__block__)')
18
35
  else
19
36
  expr
20
37
  end
21
38
  end
22
39
  end
23
- private :compat
40
+ private :arg_fwd
24
41
 
25
42
  def execute(namespace, expr, _match_result)
26
43
  location = backtick_caller
27
44
  if (namespace.respond_to? :module_eval) then
28
- namespace.module_eval(compat(expr), location.path, location.lineno)
45
+ namespace.module_eval(arg_fwd(expr), location.path, location.lineno)
29
46
  else
30
- namespace.instance_eval(compat(expr), location.path, location.lineno)
47
+ namespace.instance_eval(arg_fwd(expr), location.path, location.lineno)
31
48
  end
32
49
  end
33
50
  end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Anytick
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
 
7
7
  # Local Variables:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anytick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TOKI Yoshinori
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-28 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,7 +83,7 @@ dependencies:
83
83
  description: |2
84
84
  Anytick extends ruby's backtick notation to do more than run a
85
85
  shell command. For example, it defines the def method syntax in
86
- backtick, and makes Ruby 2.7's argument forwarding notation of
86
+ backtick, and makes Ruby 2.7's arguments forwarding notation of
87
87
  `(...)' usable with Ruby 2.6.
88
88
  email:
89
89
  - toki@freedom.ne.jp
@@ -92,6 +92,7 @@ extensions: []
92
92
  extra_rdoc_files: []
93
93
  files:
94
94
  - ".gitignore"
95
+ - CHANGELOG.md
95
96
  - Gemfile
96
97
  - LICENSE.txt
97
98
  - README.md