shelike-pipe 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d1f23b969367accae1138bd242c3cfbee723e61
4
+ data.tar.gz: ca4aeaa44b8bfb5f6de8fcc4425fcac36ee81c01
5
+ SHA512:
6
+ metadata.gz: f24426bb7cf3e5a2f5ccce218c19532bcd2233cda184633b0ada52a0624aac573704d5b95ff57641c2d42ceffdaf72add632ac793e3518e897ac45702970dfbe
7
+ data.tar.gz: f56a9683c2d075058318afb048a16baa09e2174eaae659f726141d7ec6978f5a28caeecd498d85cd016bd2b8cab1ee57e1e158e895cae9dffc3458e3e76421f1
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+ /*.iml/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shelike-pipe.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 k-motoyan
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,60 @@
1
+ # Shelike::Pipe
2
+
3
+ Shelike::Pipe offer an operator to behave like the pipe operator of the shell.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'shelike-pipe'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install shelike-pipe
20
+
21
+ ## Usage
22
+
23
+ ```rb
24
+ require 'shelike/pipe'
25
+
26
+ using Shelike::Pipe
27
+
28
+ # Can let an object of the left side of a go board apply to the symbol of the right side.
29
+ ('foo' | :upcase).call # => 'FOO'
30
+
31
+ # Can apply it for the Method and Proc
32
+ require 'json'
33
+
34
+ ('{ "a": 1 }' | JSON.method(:parse)).call # => { "a" => 1 }
35
+ ('{ "a": 1 }' | ->(json) { JSON.parse(json) }).call # => { "a" => 1 }
36
+
37
+ # When an argument is necessary, define it with sequence.
38
+ (%w(a b c) | :size | [:*, 3]).call # => 9
39
+
40
+ # Can return nil when carry out processing by silence method when an exception occurs on the way.
41
+ ('{ a: 1 }' | JSON.method(:parse)).call # => JSON::ParserError
42
+ ('{ a: 1 }' | JSON.method(:parse)).silence # => nil
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies.
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (git checkout -b my-new-feature)
53
+ 3. Commit your changes (git commit -am 'Added some feature')
54
+ 4. Push to the branch (git push origin my-new-feature)
55
+ 5. Create new Pull Request
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
60
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task :default => :spec
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install --path=.bundle
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,63 @@
1
+ # require 'shelike/pipe/version'
2
+
3
+ module Shelike
4
+ module Pipe
5
+ def self.build_proc(proc, apply_proc, *args)
6
+ case proc
7
+ when Symbol, Method then -> { proc.to_proc.call(apply_proc.call, *args) }
8
+ when Proc then -> { proc.call(apply_proc.call, *args) }
9
+ else raise ArgumentError
10
+ end
11
+ end
12
+
13
+ refine Object do
14
+ def |(arg)
15
+ if arg.is_a? Array
16
+ proc_or_method = arg.shift
17
+ Shelike::Pipe.build_proc proc_or_method, -> { self }, *arg
18
+ else
19
+ Shelike::Pipe.build_proc arg, -> { self }
20
+ end
21
+ end
22
+ end
23
+
24
+ refine Array do
25
+ def |(arg)
26
+ if arg.is_a? Array
27
+ proc_or_method = arg.shift
28
+ Shelike::Pipe.build_proc proc_or_method, -> { self }, *arg
29
+ else
30
+ Shelike::Pipe.build_proc arg, -> { self }
31
+ end
32
+ end
33
+ end
34
+
35
+ refine Fixnum do
36
+ def |(arg)
37
+ if arg.is_a? Array
38
+ proc_or_method = arg.shift
39
+ Shelike::Pipe.build_proc proc_or_method, -> { self }, *arg
40
+ else
41
+ Shelike::Pipe.build_proc arg, -> { self }
42
+ end
43
+ end
44
+ end
45
+
46
+ refine Proc do
47
+ def |(arg)
48
+ if arg.is_a? Array
49
+ proc_or_method = arg.shift
50
+ Shelike::Pipe.build_proc proc_or_method, -> { call }, *arg
51
+ else
52
+ Shelike::Pipe.build_proc arg, -> { call }
53
+ end
54
+ end
55
+
56
+ def silence
57
+ call
58
+ rescue => _
59
+ nil
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ module Shelike
2
+ module Pipe
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shelike/pipe/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'shelike-pipe'
8
+ spec.version = Shelike::Pipe::VERSION
9
+ spec.authors = ['k-motoyan']
10
+ spec.email = ['k.motoyan888@gmail.com']
11
+
12
+ spec.summary = 'Shelike::Pipe offer an operator to behave like the pipe operator of the shell.'
13
+ spec.homepage = 'https://github.com/k-motoyan/shelike-pipe'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.11'
20
+ spec.add_development_dependency 'rake', '~> 10.0'
21
+ spec.add_development_dependency 'rspec'
22
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shelike-pipe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - k-motoyan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-03 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ description:
56
+ email:
57
+ - k.motoyan888@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/setup
69
+ - lib/shelike/pipe.rb
70
+ - lib/shelike/pipe/version.rb
71
+ - shelike-pipe.gemspec
72
+ homepage: https://github.com/k-motoyan/shelike-pipe
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Shelike::Pipe offer an operator to behave like the pipe operator of the shell.
96
+ test_files: []