anytick 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a408362c0d9cdefc8a88750e3aacdd35afce73d44afaa864aa2bb6320a640acd
4
+ data.tar.gz: f8462d6b1f2a2f8768fb9db3f023ef42235a16c57cd9a81cad07e9a248b1dc9e
5
+ SHA512:
6
+ metadata.gz: 717a209d1c87d34b93052e11e2f0e348df391e9ffc1854ca41b285d64a7c2bb5cad1beed7f4f023ed91fb1ae3c7a4ad7ccf1446414ebc03af4bc3dfdbd2d0ef4
7
+ data.tar.gz: ef261b360c1621baa6b1907c91ddfaf1b80fbd35f259ae97b91671a2676431db652ab7caa966a76ec06aaca263a5516a8050c57cb04a3a327700bac4106fa4b1
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ /Gemfile.lock
11
+ /README.html
12
+ *~
13
+ .#*
14
+ \#*
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in anytick.gemspec
6
+ gemspec
7
+
8
+ # Local Variables:
9
+ # mode: Ruby
10
+ # indent-tabs-mode: nil
11
+ # End:
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TOKI Yoshinori
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.
@@ -0,0 +1,83 @@
1
+ Anytick
2
+ =======
3
+
4
+ Anytick extends ruby's backtick notation to do more than run a shell
5
+ command. For example, it defines the def method syntax in backtick,
6
+ and makes Ruby 2.7's argument forwarding notation of `(...)' usable
7
+ with Ruby 2.6.
8
+
9
+ Installation
10
+ ------------
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'anytick'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install anytick
25
+
26
+ Usage
27
+ -----
28
+
29
+ ### Using def method rule
30
+
31
+ Example:
32
+
33
+ ```ruby
34
+ require 'anytick'
35
+
36
+ class Foo
37
+ extend Anytick.rule(Anytick::DefineMethod)
38
+
39
+ `def foo(...)
40
+ bar(...)
41
+ end
42
+ `
43
+ end
44
+ ```
45
+
46
+ This example does not cause a syntax error in Ruby 2.6, even though it
47
+ uses the new notation `(...)` of Ruby 2.7.
48
+ If Ruby version is 2.7 or later, this example will be evaluated as is.
49
+ If Ruby version is older than 2.7, this example will be evaluated by
50
+ converting `(...)` to work with older Ruby.
51
+
52
+ ### Using anytick framework
53
+
54
+ Anytick provides a mechanism to extend ruby's backtick notation.
55
+ The def method rule is one example of using this mechanism.
56
+
57
+ If you want to create a new rule, create the rule as a subclass of
58
+ `Anytick::RuleMaker`. Then implement `match(expr)` and
59
+ `execute(namespace, expr, match_result)` methods at the rule.
60
+
61
+ `match(expr)` method determines whether to apply the rule to content
62
+ in backtick notation. `expr` is the content of backtick notation.
63
+ `execute(namespace, expr, match_result)` method is executed when the
64
+ rule is applied. `namespace` is the receiver of backtick notation.
65
+ `expr` is the content of backtick notation. `match_result` is the
66
+ result of `match(expr)` method.
67
+
68
+ A rule is used by `include` or `extend` via `Anytick.rule`.
69
+ Use `include` to extend object scope backtick notation, and use
70
+ `extend` to extend module/class scope backtick notation. It is
71
+ possible to apply more than one rule at once.
72
+
73
+ Contributing
74
+ ------------
75
+
76
+ Bug reports and pull requests are welcome on GitHub at
77
+ <https://github.com/y10k/anytick>.
78
+
79
+ License
80
+ -------
81
+
82
+ The gem is available as open source under the terms of the
83
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/clean'
5
+ require 'rake/testtask'
6
+ require 'rdoc/task'
7
+
8
+ Rake::TestTask.new do |task|
9
+ if ((ENV.key? 'RUBY_DEBUG') && (! ENV['RUBY_DEBUG'].empty?)) then
10
+ task.ruby_opts << '-d'
11
+ end
12
+ end
13
+
14
+ Rake::RDocTask.new do |rd|
15
+ rd.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ rule '.html' => '.md' do |t|
19
+ sh "pandoc --from=markdown --to=html5 --standalone --self-contained --css=$HOME/.pandoc/github.css --output=#{t.name} #{t.source}"
20
+ end
21
+
22
+ desc 'Build README.html from markdown source'
23
+ task :readme => %w[ README.html ]
24
+ CLOBBER.include 'README.html'
25
+
26
+ # Local Variables:
27
+ # mode: Ruby
28
+ # indent-tabs-mode: nil
29
+ # End:
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require_relative 'lib/anytick/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'anytick'
7
+ spec.version = Anytick::VERSION
8
+ spec.authors = ['TOKI Yoshinori']
9
+ spec.email = ['toki@freedom.ne.jp']
10
+
11
+ spec.summary = %q{Anytick extends ruby's backtick notation to do more than run a shell command}
12
+ spec.description = <<-'EOF'
13
+ Anytick extends ruby's backtick notation to do more than run a
14
+ shell command. For example, it defines the def method syntax in
15
+ backtick, and makes Ruby 2.7's argument forwarding notation of
16
+ `(...)' usable with Ruby 2.6.
17
+ EOF
18
+ spec.homepage = 'https://github.com/y10k/anytick'
19
+ spec.license = 'MIT'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler'
31
+ spec.add_development_dependency 'rake'
32
+ spec.add_development_dependency 'test-unit'
33
+ spec.add_development_dependency 'rdoc'
34
+ spec.add_development_dependency 'irb'
35
+ end
36
+
37
+ # Local Variables:
38
+ # mode: Ruby
39
+ # indent-tabs-mode: nil
40
+ # End:
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "anytick"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'anytick/version'
4
+
5
+ module Anytick
6
+ class RuleMaker
7
+ def self.make_rule
8
+ new
9
+ end
10
+
11
+ def make_rule
12
+ self
13
+ end
14
+
15
+ def backtick_caller
16
+ caller_locations(5, 1).first
17
+ end
18
+ end
19
+
20
+ class << self
21
+ def make_backtick_action(rule_list)
22
+ lambda{|expr|
23
+ for rule in rule_list
24
+ if (match_result = (rule.match? expr)) then
25
+ namespace = self
26
+ return rule.execute(namespace, expr, match_result)
27
+ end
28
+ end
29
+ super(expr)
30
+ }
31
+ end
32
+ private :make_backtick_action
33
+ end
34
+
35
+ def self.rule(rule_maker, *other_rule_makers)
36
+ rule_maker_list = [ rule_maker ] + other_rule_makers
37
+ rule_list = rule_maker_list.map(&:make_rule)
38
+ action = make_backtick_action(rule_list)
39
+
40
+ Module.new{
41
+ define_method(:`, action)
42
+ private :`
43
+ }
44
+ end
45
+
46
+ autoload :DefineMethod, 'anytick/defmethod'
47
+ end
48
+
49
+ # Local Variables:
50
+ # mode: Ruby
51
+ # indent-tabs-mode: nil
52
+ # End:
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Anytick
4
+ class DefineMethod < RuleMaker
5
+ def match?(expr)
6
+ (/\A \s* def \s+/x.match? expr) && (/\b end \s* \z/x.match? expr)
7
+ end
8
+
9
+ if ((RUBY_VERSION.split('.').map(&:to_i) <=> [ 2, 7 ]) >= 0) then
10
+ def compat(expr)
11
+ expr
12
+ end
13
+ else
14
+ def compat(expr)
15
+ first_line = expr.lstrip.each_line.first
16
+ if (first_line.include? '(...)') then
17
+ expr.gsub('(...)', '(*__args__, &__block__)')
18
+ else
19
+ expr
20
+ end
21
+ end
22
+ end
23
+ private :compat
24
+
25
+ def execute(namespace, expr, _match_result)
26
+ location = backtick_caller
27
+ if (namespace.respond_to? :module_eval) then
28
+ namespace.module_eval(compat(expr), location.path, location.lineno)
29
+ else
30
+ namespace.instance_eval(compat(expr), location.path, location.lineno)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ # Local Variables:
37
+ # mode: Ruby
38
+ # indent-tabs-mode: nil
39
+ # End:
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Anytick
4
+ VERSION = '0.1.0'
5
+ end
6
+
7
+ # Local Variables:
8
+ # mode: Ruby
9
+ # indent-tabs-mode: nil
10
+ # End:
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anytick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - TOKI Yoshinori
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: irb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |2
84
+ Anytick extends ruby's backtick notation to do more than run a
85
+ shell command. For example, it defines the def method syntax in
86
+ backtick, and makes Ruby 2.7's argument forwarding notation of
87
+ `(...)' usable with Ruby 2.6.
88
+ email:
89
+ - toki@freedom.ne.jp
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - anytick.gemspec
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/anytick.rb
103
+ - lib/anytick/defmethod.rb
104
+ - lib/anytick/version.rb
105
+ homepage: https://github.com/y10k/anytick
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.1.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Anytick extends ruby's backtick notation to do more than run a shell command
128
+ test_files: []