matchete 0.4.0 → 0.5.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: 5fa9bd76ac56c8cef81d38dc29c909785266d343
4
- data.tar.gz: 229e287190233cdf977ba70a82a38843ffe7f27b
3
+ metadata.gz: 7eaec51f73bf9688fef271c8675a363a75b4d497
4
+ data.tar.gz: 14a06ff2857110511aa837f0c817683972869df7
5
5
  SHA512:
6
- metadata.gz: db82efc590b09b6475c2e110760d7bc3e4d83051c335127df92b2ceabe71c0710f1b0327da5c86712e5cc24458fc020449ab9ae17ada1bd6a2aea779dbd99b43
7
- data.tar.gz: 49cee2493d6e2b4e738a6205e412d6f446b33c5440554a38e685c3669d2a37ad87b6f522860d636015cdcedff2271d56fccb71ce9c692281fa2411fcf4f9095a
6
+ metadata.gz: 1dd3b6b2d2ed7dcf481d5a6c7f504bd815f865016e53d6cd9200fcdfb7eba106af673b6bb74f29e3621cf0baf382e8a6a4caf35d77548b6bc81f1ebef228ba09
7
+ data.tar.gz: 8e620e41f5260fb4be81ce600caa977a73f550667f86afeb18664025dcc2433aeecaef5344ce53d3f435a1d21364e80e198752891f54903e46c57c25c9dc18d5
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/README.md CHANGED
@@ -21,7 +21,8 @@ Features
21
21
  * `on full_match('#count', '#combine')` matches if all of the tests return true for an arg
22
22
  * `on exact(Integer)` matches special values, used as shortcuts in other cases:
23
23
  classes, strings starting with '#', etc
24
- # `default` matches when no match has been found in `on` branches
24
+ * `on having('#count' => 2)` matches objects with properties with certain values
25
+ * `default` matches when no match has been found in `on` branches
25
26
 
26
27
 
27
28
 
@@ -166,6 +167,12 @@ p converter.convert(free: 2) #[:rofl, 2]
166
167
  p converter.convert(2.2) #[:z, 2.2]
167
168
 
168
169
  ```
170
+
171
+ version
172
+ -------
173
+ 0.5.0
174
+
175
+
169
176
  cbb
170
177
  -----
171
178
  ![](https://global3.memecdn.com/kawaii-danny-trejo_o_2031011.jpg)
data/lib/matchete.rb CHANGED
@@ -33,7 +33,7 @@ module Matchete
33
33
  end
34
34
 
35
35
  # Matches something like sum types:
36
- # either(Integer, Array)
36
+ # either(Integer, Array)
37
37
  # matches both [2] and 2
38
38
  def either(*guards)
39
39
  -> arg { guards.any? { |g| match_guard(g, arg) } }
@@ -46,6 +46,14 @@ module Matchete
46
46
  -> arg { arg == value }
47
47
  end
48
48
 
49
+ # Matches property results
50
+ # e.g. having('#to_s': '[]') will match []
51
+ def having(**properties)
52
+ -> arg do
53
+ properties.all? { |prop, result| arg.respond_to?(prop[1..-1]) && arg.send(prop[1..-1]) == result }
54
+ end
55
+ end
56
+
49
57
  # Matches each guard
50
58
  # full_match(Integer, '#value')
51
59
  # matches only instances of Integer which respond to '#value'
data/matchete.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'matchete'
6
- s.version = '0.4.0'
6
+ s.version = '0.5.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Alexander Ivanov"]
9
9
  s.email = ["alehander42@gmail.com"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matchete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Ivanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-05 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -31,9 +31,9 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".gitignore"
34
35
  - ".travis.yml"
35
36
  - Gemfile
36
- - Gemfile.lock
37
37
  - LICENSE
38
38
  - README.md
39
39
  - Rakefile
@@ -66,4 +66,6 @@ rubygems_version: 2.4.6
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: Method overloading for Ruby based on pattern matching
69
- test_files: []
69
+ test_files:
70
+ - spec/matchete_spec.rb
71
+ - spec/spec_helper.rb
data/Gemfile.lock DELETED
@@ -1,78 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- addressable (2.3.8)
5
- builder (3.2.2)
6
- codeclimate-test-reporter (0.4.7)
7
- simplecov (>= 0.7.1, < 1.0.0)
8
- descendants_tracker (0.0.4)
9
- thread_safe (~> 0.3, >= 0.3.1)
10
- diff-lcs (1.2.5)
11
- docile (1.1.5)
12
- faraday (0.9.1)
13
- multipart-post (>= 1.2, < 3)
14
- git (1.2.9.1)
15
- github_api (0.12.3)
16
- addressable (~> 2.3)
17
- descendants_tracker (~> 0.0.4)
18
- faraday (~> 0.8, < 0.10)
19
- hashie (>= 3.3)
20
- multi_json (>= 1.7.5, < 2.0)
21
- nokogiri (~> 1.6.3)
22
- oauth2
23
- hashie (3.4.2)
24
- highline (1.7.2)
25
- jeweler (2.0.1)
26
- builder
27
- bundler (>= 1.0)
28
- git (>= 1.2.5)
29
- github_api
30
- highline (>= 1.6.15)
31
- nokogiri (>= 1.5.10)
32
- rake
33
- rdoc
34
- json (1.8.3)
35
- jwt (1.5.0)
36
- mini_portile (0.6.2)
37
- multi_json (1.11.0)
38
- multi_xml (0.5.5)
39
- multipart-post (2.0.0)
40
- nokogiri (1.6.6.2)
41
- mini_portile (~> 0.6.0)
42
- oauth2 (1.0.0)
43
- faraday (>= 0.8, < 0.10)
44
- jwt (~> 1.0)
45
- multi_json (~> 1.3)
46
- multi_xml (~> 0.5)
47
- rack (~> 1.2)
48
- rack (1.6.1)
49
- rake (10.4.2)
50
- rdoc (4.2.0)
51
- rspec (3.2.0)
52
- rspec-core (~> 3.2.0)
53
- rspec-expectations (~> 3.2.0)
54
- rspec-mocks (~> 3.2.0)
55
- rspec-core (3.2.3)
56
- rspec-support (~> 3.2.0)
57
- rspec-expectations (3.2.1)
58
- diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.2.0)
60
- rspec-mocks (3.2.1)
61
- diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.2.0)
63
- rspec-support (3.2.2)
64
- simplecov (0.10.0)
65
- docile (~> 1.1.0)
66
- json (~> 1.8)
67
- simplecov-html (~> 0.10.0)
68
- simplecov-html (0.10.0)
69
- thread_safe (0.3.5)
70
-
71
- PLATFORMS
72
- ruby
73
-
74
- DEPENDENCIES
75
- bundler
76
- codeclimate-test-reporter
77
- jeweler
78
- rspec