xproc 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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +70 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/xproc/version.rb +3 -0
- data/lib/xproc.rb +63 -0
- data/xproc.gemspec +24 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 434ab7c5b11f8d94276e194138704d60e63d6b0d
|
4
|
+
data.tar.gz: 1f2f980bb3a7ef58102e1601fb8b5e43516e4b02
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 176324f14e2c870a66688c5fb022089b1a40115494533ad68c0138d5399b012b5ecdf32da7ff5e3a36cc3b9e57e6dd0ab9f30b959c731aba9df63e781b3ab960
|
7
|
+
data.tar.gz: 7cf5002daf9f35d170862507f3bd827018d2edffaad3ec23d42374c270c40c0c8d5d62a061d685005128ab6bc75a315da92ab86d279c9ed7e56abdc9a996994f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Jonas Nicklas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# XProc
|
2
|
+
|
3
|
+
XProc is a refinement for Ruby which allows you to write simple blocks using a
|
4
|
+
convenient shorthand syntax, inspired by Scala, Crystal and Elixir.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'xproc'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Since it's a refinement, you have to explicitly include it wherever you want to
|
17
|
+
use it. Use it like this:
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
using XProc
|
21
|
+
|
22
|
+
["foo", "bar", "quox"].map(&x.gsub("oo", "aa")).select(&x.length <= 3)
|
23
|
+
# => ["faa", "bar"]
|
24
|
+
```
|
25
|
+
|
26
|
+
You can also use positional arguments like this:
|
27
|
+
|
28
|
+
``` ruby
|
29
|
+
[1,2,3,4,5].reduce(&x1 * x2)
|
30
|
+
# => 120
|
31
|
+
```
|
32
|
+
|
33
|
+
And chain stuff
|
34
|
+
|
35
|
+
``` ruby
|
36
|
+
[1,2,3,4,5].map(&x * 2 + 1)
|
37
|
+
# => [3, 5, 7, 9, 11]
|
38
|
+
|
39
|
+
[123, 456].map(&x.to_s.reverse)
|
40
|
+
# => ["321", "654"]
|
41
|
+
```
|
42
|
+
|
43
|
+
It does this by recording all method calls on `x` and replaying them when the
|
44
|
+
proc is called.
|
45
|
+
|
46
|
+
## Limitations
|
47
|
+
|
48
|
+
The `x` or `x1`... **must** be the first expression after the `&` sign. This does not
|
49
|
+
work:
|
50
|
+
|
51
|
+
``` ruby
|
52
|
+
[1,2,3,4,5].reduce(&foo(x))
|
53
|
+
```
|
54
|
+
|
55
|
+
Any `x` passed as an argument must be a direct argument to another `x`. This does not
|
56
|
+
work:
|
57
|
+
|
58
|
+
``` ruby
|
59
|
+
[1,2,3,4,5].reduce([], &x1 + [x2])
|
60
|
+
[1,2,3,4,5].reduce([], &x1 + foo(x2))
|
61
|
+
[1,2,3,4,5].reduce([], &x1 + Foo.new(x2))
|
62
|
+
```
|
63
|
+
|
64
|
+
## Is it any good?
|
65
|
+
|
66
|
+
[No](https://news.ycombinator.com/item?id=3067434).
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
[MIT](License.txt)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "xproc"
|
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
|
data/bin/setup
ADDED
data/lib/xproc.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "xproc/version"
|
2
|
+
|
3
|
+
module XProc
|
4
|
+
class Proc < BasicObject
|
5
|
+
attr_reader :index
|
6
|
+
|
7
|
+
def initialize(index, invocations = [])
|
8
|
+
@index = index
|
9
|
+
@invocations = invocations
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_proc
|
13
|
+
invocations = @invocations
|
14
|
+
index = @index
|
15
|
+
::Kernel.lambda do |*proc_args|
|
16
|
+
invocations.reduce(proc_args[index]) do |val, (name, args, block)|
|
17
|
+
args = args.map do |arg|
|
18
|
+
if arg.is_a?(::XProc::Proc)
|
19
|
+
proc_args[arg.index]
|
20
|
+
else
|
21
|
+
arg
|
22
|
+
end
|
23
|
+
end
|
24
|
+
val.send(name, *args, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def respond_to_missing?(*)
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def method_missing(name, *args, &block)
|
34
|
+
::XProc::Proc.new(@index, @invocations + [[name, args, block]])
|
35
|
+
end
|
36
|
+
|
37
|
+
undef :==
|
38
|
+
undef :!=
|
39
|
+
undef :!
|
40
|
+
end
|
41
|
+
|
42
|
+
refine Object do
|
43
|
+
def x
|
44
|
+
::XProc::Proc.new(0)
|
45
|
+
end
|
46
|
+
|
47
|
+
def x1
|
48
|
+
::XProc::Proc.new(0)
|
49
|
+
end
|
50
|
+
|
51
|
+
def x2
|
52
|
+
::XProc::Proc.new(1)
|
53
|
+
end
|
54
|
+
|
55
|
+
def x3
|
56
|
+
::XProc::Proc.new(2)
|
57
|
+
end
|
58
|
+
|
59
|
+
def x4
|
60
|
+
::XProc::Proc.new(3)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/xproc.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'xproc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "xproc"
|
8
|
+
spec.version = XProc::VERSION
|
9
|
+
spec.authors = ["Jonas Nicklas and Kim Burgestrand"]
|
10
|
+
spec.email = ["dev+jonas+kim@elabs.se"]
|
11
|
+
|
12
|
+
spec.summary = "Awesome short procs for Ruby"
|
13
|
+
spec.homepage = "https://github.com/jnicklas/xproc"
|
14
|
+
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xproc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Nicklas and Kim Burgestrand
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-22 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: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- dev+jonas+kim@elabs.se
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- lib/xproc.rb
|
58
|
+
- lib/xproc/version.rb
|
59
|
+
- xproc.gemspec
|
60
|
+
homepage: https://github.com/jnicklas/xproc
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.6
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Awesome short procs for Ruby
|
84
|
+
test_files: []
|