ataulfo 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +120 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +1 -0
- data/ataulfo.gemspec +23 -0
- data/lib/ataulfo.rb +3 -0
- data/lib/ataulfo/kernel_extension.rb +7 -0
- data/lib/ataulfo/pattern_matching.rb +64 -0
- data/lib/ataulfo/version.rb +3 -0
- data/spec/lib/ataulfo/pattern_matching_spec.rb +149 -0
- data/spec/spec_helper.rb +3 -0
- metadata +35 -24
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8c268635bc6dd13739c0be60f885f02c4a619c2
|
4
|
+
data.tar.gz: 163fc9e5dcb168721be19f05211b1853bca14be7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee6e8b448026e2a3a570010bd31caa9ad3e6e085931930f6b3b4b445948bf6fe241388045c6e2cbcb11b1d1ca5c435f084effb10cc38b38e11b1ea47591d03b5
|
7
|
+
data.tar.gz: 6a3912c3aeb245f740341fccd5d0bd2021b8940e5767d64fa5f96bc5135d162271df07f842f11ad6bf3b9d6be9150a6c6a068b868d277d78e8a7f32ddc74a2be
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-09-28 12:01:20 -0300 using RuboCop version 0.43.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 20
|
12
|
+
|
13
|
+
# Offense count: 7
|
14
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
15
|
+
# URISchemes: http, https
|
16
|
+
Metrics/LineLength:
|
17
|
+
Max: 138
|
18
|
+
|
19
|
+
# Offense count: 4
|
20
|
+
Style/Documentation:
|
21
|
+
Exclude:
|
22
|
+
- 'spec/**/*'
|
23
|
+
- 'test/**/*'
|
24
|
+
- 'lib/ataulfo/kernel_extension.rb'
|
25
|
+
- 'lib/ataulfo/pattern_matching.rb'
|
26
|
+
|
27
|
+
# Offense count: 8
|
28
|
+
# Cop supports --auto-correct.
|
29
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
30
|
+
# SupportedStyles: when_needed, always
|
31
|
+
Style/FrozenStringLiteralComment:
|
32
|
+
Exclude:
|
33
|
+
- 'Gemfile'
|
34
|
+
- 'Guardfile'
|
35
|
+
- 'Rakefile'
|
36
|
+
- 'ataulfo.gemspec'
|
37
|
+
- 'lib/ataulfo.rb'
|
38
|
+
- 'lib/ataulfo/kernel_extension.rb'
|
39
|
+
- 'lib/ataulfo/pattern_matching.rb'
|
40
|
+
- 'lib/ataulfo/version.rb'
|
41
|
+
|
42
|
+
# Offense count: 2
|
43
|
+
Style/MethodMissing:
|
44
|
+
Exclude:
|
45
|
+
- 'lib/ataulfo/pattern_matching.rb'
|
46
|
+
|
47
|
+
# Offense count: 1
|
48
|
+
# Cop supports --auto-correct.
|
49
|
+
Style/MutableConstant:
|
50
|
+
Exclude:
|
51
|
+
- 'lib/ataulfo/version.rb'
|
52
|
+
|
53
|
+
# Offense count: 2
|
54
|
+
# Cop supports --auto-correct.
|
55
|
+
# Configuration parameters: PreferredDelimiters.
|
56
|
+
Style/PercentLiteralDelimiters:
|
57
|
+
Exclude:
|
58
|
+
- 'ataulfo.gemspec'
|
59
|
+
|
60
|
+
# Offense count: 1
|
61
|
+
# Cop supports --auto-correct.
|
62
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
|
63
|
+
# SupportedStyles: slashes, percent_r, mixed
|
64
|
+
Style/RegexpLiteral:
|
65
|
+
Exclude:
|
66
|
+
- 'Guardfile'
|
67
|
+
|
68
|
+
# Offense count: 1
|
69
|
+
# Cop supports --auto-correct.
|
70
|
+
# Configuration parameters: AllowAsExpressionSeparator.
|
71
|
+
Style/Semicolon:
|
72
|
+
Exclude:
|
73
|
+
- 'lib/ataulfo/pattern_matching.rb'
|
74
|
+
|
75
|
+
# Offense count: 1
|
76
|
+
# Cop supports --auto-correct.
|
77
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
78
|
+
# SupportedStyles: space, no_space
|
79
|
+
Style/SpaceBeforeBlockBraces:
|
80
|
+
Exclude:
|
81
|
+
- 'ataulfo.gemspec'
|
82
|
+
|
83
|
+
# Offense count: 4
|
84
|
+
# Cop supports --auto-correct.
|
85
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
86
|
+
# SupportedStyles: space, no_space, compact
|
87
|
+
Style/SpaceInsideHashLiteralBraces:
|
88
|
+
Exclude:
|
89
|
+
- 'Guardfile'
|
90
|
+
- 'lib/ataulfo/pattern_matching.rb'
|
91
|
+
|
92
|
+
# Offense count: 1
|
93
|
+
# Cop supports --auto-correct.
|
94
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
95
|
+
# SupportedStyles: use_perl_names, use_english_names
|
96
|
+
Style/SpecialGlobalVars:
|
97
|
+
Exclude:
|
98
|
+
- 'ataulfo.gemspec'
|
99
|
+
|
100
|
+
# Offense count: 4
|
101
|
+
# Cop supports --auto-correct.
|
102
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
103
|
+
# SupportedStyles: single_quotes, double_quotes
|
104
|
+
Style/StringLiterals:
|
105
|
+
Exclude:
|
106
|
+
- 'Rakefile'
|
107
|
+
- 'ataulfo.gemspec'
|
108
|
+
- 'lib/ataulfo/kernel_extension.rb'
|
109
|
+
- 'lib/ataulfo/version.rb'
|
110
|
+
|
111
|
+
# Offense count: 1
|
112
|
+
Style/StructInheritance:
|
113
|
+
Exclude:
|
114
|
+
- 'lib/ataulfo/pattern_matching.rb'
|
115
|
+
|
116
|
+
# Offense count: 2
|
117
|
+
# Cop supports --auto-correct.
|
118
|
+
Style/UnneededPercentQ:
|
119
|
+
Exclude:
|
120
|
+
- 'ataulfo.gemspec'
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ataulfo
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.1
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
group :tdd, halt_on_fail: true do
|
2
|
+
guard :rspec,
|
3
|
+
cmd: 'bundle exec rspec -f documentation --color',
|
4
|
+
run_all: {cmd: 'bundle exec rspec -f documentation --color'},
|
5
|
+
keep: true,
|
6
|
+
all_on_start: true,
|
7
|
+
all_after_pass: true do
|
8
|
+
|
9
|
+
watch(%r{^spec/.+_spec\.rb$})
|
10
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
11
|
+
watch('lib/mcgee.rb') { 'spec' }
|
12
|
+
end
|
13
|
+
guard :rubocop, cmd: 'bundle exec rubocop', cli: '-fs -c./.rubocop.yml' do
|
14
|
+
watch(%r{.+\.rb$})
|
15
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
16
|
+
end
|
17
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 TODO: Write your name
|
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,77 @@
|
|
1
|
+
# Ataulfo
|
2
|
+
|
3
|
+
A DSL for **pattern matching** over object in Ruby.
|
4
|
+
|
5
|
+
What does it do? It's a conditional clause based on the object interface. It also allows you do make "multi-assignment".
|
6
|
+
|
7
|
+
Example:
|
8
|
+
|
9
|
+
object = Struct.new(:method1, :method2).new
|
10
|
+
object.method1 = 'something'
|
11
|
+
object.method2 = 'something else'
|
12
|
+
|
13
|
+
with object do
|
14
|
+
like method1: m1, method2: m2 do
|
15
|
+
puts m1 # 'something'
|
16
|
+
puts m2 # 'something else'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Another example:
|
21
|
+
|
22
|
+
object = Struct.new(:a_method).new
|
23
|
+
object.a_method = 'something'
|
24
|
+
|
25
|
+
with object do
|
26
|
+
like this_method_does_not_exist: x do
|
27
|
+
fail 'it will not reach here'
|
28
|
+
end
|
29
|
+
like a_method: x do
|
30
|
+
puts x # 'something'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
Add this line to your application's Gemfile:
|
37
|
+
|
38
|
+
gem 'ataulfo'
|
39
|
+
|
40
|
+
And then execute:
|
41
|
+
|
42
|
+
$ bundle
|
43
|
+
|
44
|
+
Or install it yourself as:
|
45
|
+
|
46
|
+
$ gem install ataulfo
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
If you want to play around, clone the project, run the specs and have fun.
|
51
|
+
|
52
|
+
Since this is really tiny and more a "Proof of Concept" than something I would use in production code, I'm not planning
|
53
|
+
to actively work on it. But if you need some help, send me an e-mail: ronie.uliana at gmail. I'll be happy to help you.
|
54
|
+
|
55
|
+
## Licensing
|
56
|
+
|
57
|
+
(MIT License)
|
58
|
+
|
59
|
+
Copyright (c) 2012 Ronie Uliana
|
60
|
+
|
61
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
62
|
+
of this software and associated documentation files (the "Software"), to deal
|
63
|
+
in the Software without restriction, including without limitation the rights
|
64
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
65
|
+
copies of the Software, and to permit persons to whom the Software is
|
66
|
+
furnished to do so, subject to the following conditions:
|
67
|
+
|
68
|
+
The above copyright notice and this permission notice shall be included in
|
69
|
+
all copies or substantial portions of the Software.
|
70
|
+
|
71
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
72
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
73
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
74
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
75
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
76
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
77
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ataulfo.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ataulfo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "ataulfo"
|
8
|
+
gem.version = Ataulfo::VERSION
|
9
|
+
gem.authors = ['Ronie Uliana']
|
10
|
+
gem.email = ['ronie.uliana@gmail.com']
|
11
|
+
gem.description = %q{Pattern Matching for Ruby (objects only)}
|
12
|
+
gem.summary = %q{A DSL for pattern matching over object in Ruby.}
|
13
|
+
gem.homepage = 'https://github.com/ruliana/ataulfo'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
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 = %w[lib]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'guard-rspec'
|
22
|
+
gem.add_development_dependency 'guard-rubocop'
|
23
|
+
end
|
data/lib/ataulfo.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module Ataulfo
|
2
|
+
class PatternMatching
|
3
|
+
class Var < Struct.new(:value);
|
4
|
+
end
|
5
|
+
|
6
|
+
class Body
|
7
|
+
def initialize(vars, other_self)
|
8
|
+
@other_self = other_self
|
9
|
+
vars.each do |k, v|
|
10
|
+
define_singleton_method(k) { v.value }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method_name, *args, &block)
|
15
|
+
@other_self.send method_name, *args, &block
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Matcher
|
20
|
+
def initialize(object, pattern)
|
21
|
+
@object = object
|
22
|
+
@pattern_vars = pattern.select { |_, v| v.is_a? Var }
|
23
|
+
inner_matches = pattern.select { |_, v| v.is_a? Hash }
|
24
|
+
fixed_values = pattern.select { |_, v| !v.is_a?(Var) && !v.is_a?(Hash) }
|
25
|
+
@object_respond_to_methods = pattern.keys.all? { |k| @object.respond_to? k }
|
26
|
+
@object_answers_right_values = fixed_values.all? { |k, v| @object.send(k) == v }
|
27
|
+
|
28
|
+
@matchers = inner_matches.map { |k, v| Matcher.new(object.send(k), v) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def matches?
|
32
|
+
@matchers.all?(&:matches?) if @object_respond_to_methods && @object_answers_right_values
|
33
|
+
end
|
34
|
+
|
35
|
+
def fill_vars
|
36
|
+
@pattern_vars.each { |k, v| v.value = @object.send k }
|
37
|
+
@matchers.each(&:fill_vars)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(object, other_self)
|
42
|
+
@object = object
|
43
|
+
@other_self = other_self
|
44
|
+
@context_vars = { }
|
45
|
+
end
|
46
|
+
|
47
|
+
def like(pattern, &block)
|
48
|
+
matcher = Matcher.new(@object, pattern)
|
49
|
+
return unless matcher.matches?
|
50
|
+
|
51
|
+
matcher.fill_vars
|
52
|
+
|
53
|
+
Body.new(@context_vars, @other_self).instance_eval(&block)
|
54
|
+
@context_vars = { }
|
55
|
+
end
|
56
|
+
|
57
|
+
def method_missing(method_name, *_)
|
58
|
+
# The line below also returns the "Var" to the
|
59
|
+
# pattern. That makes it a collector parameter
|
60
|
+
# already distributed where it belongs to.
|
61
|
+
@context_vars[method_name] = Var.new
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Ataulfo::PatternMatching do
|
5
|
+
it 'matches a single method' do
|
6
|
+
passed_through_match = false
|
7
|
+
|
8
|
+
object = Struct.new(:a_method).new('something')
|
9
|
+
|
10
|
+
with object do
|
11
|
+
like a_method: some_var do
|
12
|
+
expect(some_var).to eq('something')
|
13
|
+
passed_through_match = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
expect(passed_through_match).to be_truthy
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'matches two methods' do
|
21
|
+
passed_through_match = false
|
22
|
+
|
23
|
+
object = Struct.new(:method1, :method2).new('something', 'something else')
|
24
|
+
|
25
|
+
with object do
|
26
|
+
like method2: m2, method1: m1 do
|
27
|
+
expect(m1).to eq('something')
|
28
|
+
expect(m2).to eq('something else')
|
29
|
+
passed_through_match = true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
expect(passed_through_match).to be_truthy
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'two bodies, one execution' do
|
37
|
+
passed_through_match = false
|
38
|
+
|
39
|
+
object = Struct.new(:a_method).new('something')
|
40
|
+
|
41
|
+
with object do
|
42
|
+
like this_does_not_exist: x do
|
43
|
+
raise 'should not match a method that does not exist'
|
44
|
+
end
|
45
|
+
like a_method: x do
|
46
|
+
expect(x).to eq('something')
|
47
|
+
passed_through_match = true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
expect(passed_through_match).to be_truthy
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'matches fixed values' do
|
55
|
+
passed_through_match = false
|
56
|
+
|
57
|
+
object = Struct.new(:a_method).new('something')
|
58
|
+
|
59
|
+
with object do
|
60
|
+
like a_method: 'other_thing' do
|
61
|
+
raise 'should not match a method with wrong value'
|
62
|
+
end
|
63
|
+
like a_method: 'something' do
|
64
|
+
passed_through_match = true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(passed_through_match).to be_truthy
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'matches fixed values in variables' do
|
72
|
+
passed_through_match = false
|
73
|
+
|
74
|
+
object = Struct.new(:a_method).new('something')
|
75
|
+
other_thing = 'other_thing'
|
76
|
+
something = 'something'
|
77
|
+
|
78
|
+
with object do
|
79
|
+
like a_method: other_thing do
|
80
|
+
raise 'should not match a method with wrong value'
|
81
|
+
end
|
82
|
+
like a_method: something do
|
83
|
+
passed_through_match = true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
expect(passed_through_match).to be_truthy
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'matches fixed and var values mixed' do
|
91
|
+
passed_through_match = false
|
92
|
+
|
93
|
+
object = Struct.new(:a_method, :another_method).new('something', 'other value')
|
94
|
+
|
95
|
+
with object do
|
96
|
+
like a_method: 'does not match', another_method: my_var do
|
97
|
+
raise 'should not match a method with wrong value'
|
98
|
+
end
|
99
|
+
like a_method: 'something', another_method: my_var do
|
100
|
+
expect(my_var).to eq('other value')
|
101
|
+
passed_through_match = true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
expect(passed_through_match).to be_truthy
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'matches a simple nested object' do
|
109
|
+
passed_through_match = false
|
110
|
+
|
111
|
+
object = Struct.new(:a_method).new(Struct.new(:inner).new('something'))
|
112
|
+
|
113
|
+
with object do
|
114
|
+
like a_method: { inner: my_var } do
|
115
|
+
expect(my_var).to eq('something')
|
116
|
+
passed_through_match = true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
expect(passed_through_match).to be_truthy
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'matches complex nested expression' do
|
124
|
+
passed_through_match = false
|
125
|
+
|
126
|
+
num = Struct.new(:value)
|
127
|
+
add = Struct.new(:augend, :addend)
|
128
|
+
prod = Struct.new(:multiplicand, :multiplier)
|
129
|
+
|
130
|
+
object = prod[add[num[1], num[2]], add[num[3], num[4]]]
|
131
|
+
|
132
|
+
with object do
|
133
|
+
like multiplicand: { augend: { value: 99 }, addend: { value: x2 } }, multiplier: { augend: { value: x3 }, addend: { value: x4 } } do
|
134
|
+
raise 'should not match a method with wrong value'
|
135
|
+
end
|
136
|
+
like multiplicand: { augend: { value: 1 }, addend: n2 }, multiplier: { augend: { value: x3 }, addend: { value: x4 } } do
|
137
|
+
expect(n2).to eq(num[2])
|
138
|
+
expect(x3).to eq(3)
|
139
|
+
expect(x4).to eq(4)
|
140
|
+
passed_through_match = true
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
expect(passed_through_match).to be_truthy
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'matches hashes'
|
148
|
+
it 'matches arrays'
|
149
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ataulfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ronie Uliana
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-09-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: guard-rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
42
|
+
name: guard-rubocop
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: Pattern Matching for Ruby (objects only)
|
@@ -65,29 +58,47 @@ email:
|
|
65
58
|
executables: []
|
66
59
|
extensions: []
|
67
60
|
extra_rdoc_files: []
|
68
|
-
files:
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- ".rubocop_todo.yml"
|
65
|
+
- ".ruby-gemset"
|
66
|
+
- ".ruby-version"
|
67
|
+
- Gemfile
|
68
|
+
- Guardfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- ataulfo.gemspec
|
73
|
+
- lib/ataulfo.rb
|
74
|
+
- lib/ataulfo/kernel_extension.rb
|
75
|
+
- lib/ataulfo/pattern_matching.rb
|
76
|
+
- lib/ataulfo/version.rb
|
77
|
+
- spec/lib/ataulfo/pattern_matching_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
69
79
|
homepage: https://github.com/ruliana/ataulfo
|
70
80
|
licenses: []
|
81
|
+
metadata: {}
|
71
82
|
post_install_message:
|
72
83
|
rdoc_options: []
|
73
84
|
require_paths:
|
74
85
|
- lib
|
75
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
87
|
requirements:
|
78
|
-
- -
|
88
|
+
- - ">="
|
79
89
|
- !ruby/object:Gem::Version
|
80
90
|
version: '0'
|
81
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
92
|
requirements:
|
84
|
-
- -
|
93
|
+
- - ">="
|
85
94
|
- !ruby/object:Gem::Version
|
86
95
|
version: '0'
|
87
96
|
requirements: []
|
88
97
|
rubyforge_project:
|
89
|
-
rubygems_version:
|
98
|
+
rubygems_version: 2.5.1
|
90
99
|
signing_key:
|
91
|
-
specification_version:
|
100
|
+
specification_version: 4
|
92
101
|
summary: A DSL for pattern matching over object in Ruby.
|
93
|
-
test_files:
|
102
|
+
test_files:
|
103
|
+
- spec/lib/ataulfo/pattern_matching_spec.rb
|
104
|
+
- spec/spec_helper.rb
|