procstar 1.0.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 +2 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/ChangeLog.rdoc +4 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +54 -0
- data/Rakefile +36 -0
- data/lib/procstar.rb +1 -0
- data/lib/procstar/array_call_chain.rb +19 -0
- data/lib/procstar/class_new.rb +11 -0
- data/lib/procstar/hash_filter.rb +17 -0
- data/lib/procstar/regexp_matcher.rb +11 -0
- data/lib/procstar/version.rb +3 -0
- data/procstar.gemspec +25 -0
- data/spec/array_call_chain_spec.rb +13 -0
- data/spec/class_new_spec.rb +10 -0
- data/spec/hash_filter_spec.rb +14 -0
- data/spec/regexp_matcher_spec.rb +11 -0
- data/spec/spec_helper.rb +18 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a5093dc72b7fc6c5f0382a45a88f0c6ff5322978
|
4
|
+
data.tar.gz: a22c973dc0a5f12ff6601136b12ceaa74aa20fa1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2069b6ec733dabd87b2c7f0e2aa162d83190f1c181378d50debf5ebe97318c2c0606793b151ca9cdc8c00f666a6d5cd43ba93acf729d7775b50a8465901ae5e1
|
7
|
+
data.tar.gz: 4f1b49e8f5df2c4a0fae3bc9554900d4943144227cd42f5710759f619ebcd1cba2be702a79f9f7b90423aae19636294a885b7f3671115865094c04e28f97d9d2
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format documentation
|
data/.travis.yml
ADDED
data/ChangeLog.rdoc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Jan Lelis
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= Procstar {<img src="https://travis-ci.org/janlelis/procstar.png" />}[https://travis-ci.org/janlelis/procstar]
|
2
|
+
|
3
|
+
This gem provides {to_proc}[http://stackoverflow.com/questions/14881125/what-does-to-proc-method-mean] implementations for other classes than just Symbol.
|
4
|
+
|
5
|
+
== Setup
|
6
|
+
|
7
|
+
$ gem install procstar
|
8
|
+
|
9
|
+
Or in your Gemfile:
|
10
|
+
|
11
|
+
gem 'procstar'
|
12
|
+
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
|
16
|
+
=== ArrayCallChain
|
17
|
+
|
18
|
+
Calls the method named by the first argument and passes the other elements as arguments. It is like using `Symbol#to_proc` with more than one argument.
|
19
|
+
|
20
|
+
require 'procstar/array_call_chain'
|
21
|
+
[1,2,3,4].map &[:*, 5] # => [5, 10, 15, 20]
|
22
|
+
# you can also chain them, if the first parameter is an Array
|
23
|
+
[1,2,3,4].map &[[:to_s, 2],[:+, 'b']] # => ["1b", "10b", "11b", "100b"]
|
24
|
+
|
25
|
+
=== ClassNew
|
26
|
+
|
27
|
+
Creates a new instance of the class.
|
28
|
+
|
29
|
+
require 'procstar/class_new'
|
30
|
+
require 'set'
|
31
|
+
[[1,2],[3,5,6,7,3]].map(&Set) # => [Set[1,2], Set[5,6,7,3]]
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
=== HashFilter
|
36
|
+
|
37
|
+
Use a hash to apply procs to specific objects.
|
38
|
+
|
39
|
+
require 'procstar/hash_filter'
|
40
|
+
[1,2,3,4].map(&{ 2 => lambda {|e| e + 1000}, 4 => :to_s }) # => [1, 1002, 3, '4']
|
41
|
+
|
42
|
+
|
43
|
+
=== RegexpMatcher
|
44
|
+
|
45
|
+
Use `&/regex/` to match it against strings.
|
46
|
+
|
47
|
+
require 'procstar/regexp_matcher'
|
48
|
+
%w|just another string array|.map &/[jy]/ # => ["j", nil, nil, "y"]
|
49
|
+
%w|just another string array|.select &/[jy]/ # => ["just", "array"]
|
50
|
+
|
51
|
+
|
52
|
+
== More to_proc ideas? Start forking!
|
53
|
+
|
54
|
+
Copyright (c) 2010-2014 Jan Lelis. MIT License. Originated from the zucker[https://github.com/janlelis/zucker] gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler'
|
7
|
+
rescue LoadError => e
|
8
|
+
warn e.message
|
9
|
+
warn "Run `gem install bundler` to install Bundler."
|
10
|
+
exit -1
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
Bundler.setup(:development)
|
15
|
+
rescue Bundler::BundlerError => e
|
16
|
+
warn e.message
|
17
|
+
warn "Run `bundle install` to install missing gems."
|
18
|
+
exit e.status_code
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake'
|
22
|
+
|
23
|
+
require 'rubygems/tasks'
|
24
|
+
Gem::Tasks.new
|
25
|
+
|
26
|
+
require 'rdoc/task'
|
27
|
+
RDoc::Task.new do |rdoc|
|
28
|
+
rdoc.title = "ruby_version"
|
29
|
+
end
|
30
|
+
task :doc => :rdoc
|
31
|
+
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new
|
34
|
+
|
35
|
+
task :test => :spec
|
36
|
+
task :default => :spec
|
data/lib/procstar.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'procstar/version'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../procstar'
|
2
|
+
|
3
|
+
module Procstar
|
4
|
+
module ArrayCallChain
|
5
|
+
def to_proc
|
6
|
+
lambda{ |obj|
|
7
|
+
if self.first.is_a? Array
|
8
|
+
self.inject(obj){ |result, nested_array|
|
9
|
+
nested_array.to_proc.call result
|
10
|
+
}
|
11
|
+
else
|
12
|
+
obj.send(*self)
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Array.send :include, Procstar::ArrayCallChain
|
data/procstar.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/procstar/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "procstar"
|
7
|
+
gem.version = Procstar::VERSION
|
8
|
+
gem.summary = 'Utilizes to_proc for usage with &.'
|
9
|
+
gem.description = 'Utilizes to_proc for usage with & for other classes than Symbol'
|
10
|
+
gem.license = "MIT"
|
11
|
+
gem.authors = ["Jan Lelis"]
|
12
|
+
gem.email = "mail@janlelis.de"
|
13
|
+
gem.homepage = "https://github.com/janlelis/procstar"
|
14
|
+
|
15
|
+
gem.files = Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_development_dependency 'bundler', '~> 1.0'
|
21
|
+
gem.add_development_dependency 'rake', '~> 10.1'
|
22
|
+
gem.add_development_dependency 'rdoc', '~> 3.0'
|
23
|
+
gem.add_development_dependency 'rspec', '~> 2.4'
|
24
|
+
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'procstar/array_call_chain'
|
2
|
+
|
3
|
+
describe Procstar::ArrayCallChain do
|
4
|
+
describe 'Array#to_proc' do
|
5
|
+
it 'should call the method of the first symbol, using the remaining elements as paramaters' do
|
6
|
+
expect( [1,2,3,4].map(&[:to_s, 2]) ).to eq ["1", "10", "11", "100"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should convert each element to a proc and chain it, if the first parameter is an array" do
|
10
|
+
expect( [1,2,3,4].map( &[[:*,2],[:+,4]]) ).to eq [1,2,3,4].map{|i| i*2 + 4 }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'procstar/hash_filter'
|
3
|
+
|
4
|
+
describe Procstar::HashFilter do
|
5
|
+
describe 'Hash#to_proc' do
|
6
|
+
it 'should run the proc given in the value for a key in the hash' do
|
7
|
+
expect( [1,2,3,4].map(&{
|
8
|
+
4 => :to_s,
|
9
|
+
# 3 => [:to_s, 2] # "11" => if array2proc is used
|
10
|
+
2 => lambda {|e| e + 1000}
|
11
|
+
}) ).to eq [1, 1002, 3, "4"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'procstar/regexp_matcher'
|
3
|
+
|
4
|
+
describe Procstar::RegexpMatcher do
|
5
|
+
describe 'Regexp#to_proc' do
|
6
|
+
it 'should match the regex' do
|
7
|
+
expect( %w|just another string array|.map(&/[jy]/) ).to eq ["j", nil, nil, "y"]
|
8
|
+
expect( %w|just another string array|.select(&/[jy]/) ).to eq ["just", "array"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
def capture_stdout
|
5
|
+
capture = StringIO.new
|
6
|
+
restore, $stdout = $stdout, capture
|
7
|
+
yield
|
8
|
+
$stdout = restore
|
9
|
+
capture.string
|
10
|
+
end
|
11
|
+
|
12
|
+
def capture_stderr
|
13
|
+
capture = StringIO.new
|
14
|
+
restore, $stderr = $stderr, capture
|
15
|
+
yield
|
16
|
+
$stderr = restore
|
17
|
+
capture.string
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: procstar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Lelis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-16 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.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.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: '10.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubygems-tasks
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.2'
|
83
|
+
description: Utilizes to_proc for usage with & for other classes than Symbol
|
84
|
+
email: mail@janlelis.de
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".rspec"
|
91
|
+
- ".travis.yml"
|
92
|
+
- ChangeLog.rdoc
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- lib/procstar.rb
|
99
|
+
- lib/procstar/array_call_chain.rb
|
100
|
+
- lib/procstar/class_new.rb
|
101
|
+
- lib/procstar/hash_filter.rb
|
102
|
+
- lib/procstar/regexp_matcher.rb
|
103
|
+
- lib/procstar/version.rb
|
104
|
+
- pkg/debugging-1.0.0.gem
|
105
|
+
- pkg/debugging-1.0.1.gem
|
106
|
+
- procstar.gemspec
|
107
|
+
- spec/array_call_chain_spec.rb
|
108
|
+
- spec/class_new_spec.rb
|
109
|
+
- spec/hash_filter_spec.rb
|
110
|
+
- spec/regexp_matcher_spec.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
homepage: https://github.com/janlelis/procstar
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.2.1
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Utilizes to_proc for usage with &.
|
136
|
+
test_files:
|
137
|
+
- spec/array_call_chain_spec.rb
|
138
|
+
- spec/class_new_spec.rb
|
139
|
+
- spec/hash_filter_spec.rb
|
140
|
+
- spec/regexp_matcher_spec.rb
|
141
|
+
- spec/spec_helper.rb
|