shelike-pipe 0.1.2 → 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
  SHA1:
3
- metadata.gz: 9778b064d51f8fdf973fd885fd7cfae965a9d1d2
4
- data.tar.gz: f868a1b19014014c4f4d7b2d94f95e1f441882cf
3
+ metadata.gz: f4e8c45e3d99dd5b8cd128146152d02d720f433d
4
+ data.tar.gz: f099c4bddc1ed5de560264b56a321f77ca73293f
5
5
  SHA512:
6
- metadata.gz: 688dc1eed2a799734f6e6f20cee108108e23ea8ae86252931d3bab10c1fb9021fcf6ca7ec5b1190bc002dbc79b935116a1fb2e28e3d18b5d571cf5d495b58a9f
7
- data.tar.gz: b4961fa96afb28ec4c32b41cf8d32ae2ecd9042c3242d44027f9d5b8d252cc313f6e6326d72a1c9c7fa940d466a592b554d38f34e444ba314e57adcbbcbd817d
6
+ metadata.gz: 2c7fb17a1a93dfc6816a6acc4c6ae6b4b523010f7adebc6fceaa5c769aedc4034c54907c23aa4d4766d5ab533ef7e5f7eefdabed577cd1f6f8b4fbad1fc56980
7
+ data.tar.gz: ac73626068a893068c8cce48ae15d3b3e6356b4c89482ba3e17d3808dc47003e93b5f3d4153d1f042b7c8ff129fb7d550214277ea3eeb6b853fd4ef6b36878f0
@@ -6,4 +6,7 @@ rvm:
6
6
  - ruby-head
7
7
  matrix:
8
8
  allow_failures:
9
- - rvm: ruby-head
9
+ - rvm: ruby-head
10
+ addons:
11
+ code_climate:
12
+ repo_token: 2e1b103fe257c1bc49d71b4065cfbb010f708831a2cf0e89a35710eb487f25cd
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Shelike::Pipe
2
2
 
3
3
  [![Build Status](https://travis-ci.org/k-motoyan/shelike-pipe.svg?branch=master)](https://travis-ci.org/k-motoyan/shelike-pipe)
4
+ [![Code Climate](https://codeclimate.com/github/k-motoyan/shelike-pipe/badges/gpa.svg)](https://codeclimate.com/github/k-motoyan/shelike-pipe)
5
+ [![Test Coverage](https://codeclimate.com/github/k-motoyan/shelike-pipe/badges/coverage.svg)](https://codeclimate.com/github/k-motoyan/shelike-pipe/coverage)
4
6
 
5
7
  Shelike::Pipe offer an operator to behave like the pipe operator of the shell.
6
8
 
@@ -39,9 +41,16 @@ require 'json'
39
41
  # When an argument is necessary, define it with sequence.
40
42
  (%w(a b c) | :size | [:*, 3]).call # => 9
41
43
 
42
- # Can return nil when carry out processing by silence method when an exception occurs on the way.
43
- ('{ a: 1 }' | JSON.method(:parse)).call # => JSON::ParserError
44
- ('{ a: 1 }' | JSON.method(:parse)).silence # => nil
44
+ # Carry out the function that was connected to there by using `^` and catchable an exception.
45
+ '{ a: 1 }' | JSON.method(:parse) ^ ->(e) { exception! }
46
+
47
+ # When an exception occurs, the `^` returns `nil`, and the case except it returns the practice result of the function to there.
48
+ '{ a: 1 }' | JSON.method(:parse) ^ ->(e) { exception! } # => nil
49
+ '{ "a": 1 }' | JSON.method(:parse) ^ ->(e) { exception! } # => { "a" => 1 }
50
+
51
+ # When they use `|` and `^` for `nil`, results always become `nil`.
52
+ (nil | to_i).call # => nil
53
+ -> { nil } ^ :upcase # => nil
45
54
  ```
46
55
 
47
56
  ## Development
@@ -51,9 +51,20 @@ module Shelike
51
51
  end
52
52
  end
53
53
 
54
- def silence
55
- call
56
- rescue => _
54
+ def ^(proc)
55
+ call.tap { |r| raise Shelike::Pipe::Error::ResultNilError if r.nil? }
56
+ rescue => e
57
+ proc.call(e)
58
+ nil
59
+ end
60
+ end
61
+
62
+ refine NilClass do
63
+ def |(_)
64
+ nil
65
+ end
66
+
67
+ def ^(_)
57
68
  nil
58
69
  end
59
70
  end
@@ -0,0 +1,11 @@
1
+ module Shelike
2
+ module Pipe
3
+ module Error
4
+ class ResultNilError < StandardError
5
+ def initialize
6
+ super 'Result was nil.'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Shelike
2
2
  module Pipe
3
- VERSION = '0.1.2'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -18,4 +18,5 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_development_dependency 'rake', '~> 10.0'
20
20
  spec.add_development_dependency 'rspec', '~> 3.4'
21
+ spec.add_development_dependency 'codeclimate-test-reporter'
21
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelike-pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k-motoyan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
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'
41
55
  description:
42
56
  email:
43
57
  - k.motoyan888@gmail.com
@@ -53,6 +67,7 @@ files:
53
67
  - Rakefile
54
68
  - bin/setup
55
69
  - lib/shelike/pipe.rb
70
+ - lib/shelike/pipe/error.rb
56
71
  - lib/shelike/pipe/version.rb
57
72
  - shelike-pipe.gemspec
58
73
  homepage: https://github.com/k-motoyan/shelike-pipe