match_map 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +50 -0
- data/.travis.yml +1 -4
- data/Gemfile +1 -27
- data/README.md +3 -3
- data/Rakefile +20 -24
- data/bench/bench.rb +4 -0
- data/lib/match_map/version.rb +3 -0
- data/lib/match_map.rb +9 -10
- data/match_map.gemspec +30 -0
- data/test/helper.rb +2 -10
- metadata +51 -31
- data/lib/match_map/match_map_18.rb +0 -15
- data/lib/match_map/match_map_19.rb +0 -12
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YmVlYjdjYTQwNTczZjA2ODcyYjIxN2E2MjNhNjc3Y2UyNWI1MTRkNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YWM5OGNlMmU4OWRmNTg0N2FhNWY3OTQ4Mzg1OWU1ZDY1ZWY2NzIyYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmM3NTM1N2MyYzE5YTdkMjQ0ZDViNTE3OTcwYzM0YjAyMDRiZmJjYTdlYjM4
|
10
|
+
MTQ2NTE2ODU3ZTMwMzI1Y2UxZWQzNTQzNThmN2U4NGI5NjYwMmMxNGQ2NjA4
|
11
|
+
Y2M1ODgyNTAzNTk3Y2Y1NDMyODc5MmRhNWMwZDk3YzkzNjE2NGY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTRkNDM2MGYyMzY5ZTc1MzM4M2ZjYmFlMTY0MmJlOTQ4NDRlMGY4OGZiYTY4
|
14
|
+
ZDI4NjAwZWIxYTIyMGE5Nzk4YTM5MDlmZTIyZGQ0MDgyOWY0YTMwYTM2ODNm
|
15
|
+
YmYyOTgxZmQ2MmEwODQzZWJjMDlhZDg2NmQyNzgzMjZkMjNlODQ=
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
#.DS_Store
|
31
|
+
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
|
36
|
+
# For emacs:
|
37
|
+
#*~
|
38
|
+
#\#*
|
39
|
+
#.\#*
|
40
|
+
|
41
|
+
# For vim:
|
42
|
+
#*.swp
|
43
|
+
|
44
|
+
# For redcar:
|
45
|
+
#.redcar
|
46
|
+
|
47
|
+
# For rubinius:
|
48
|
+
#*.rbc
|
49
|
+
|
50
|
+
Gemfile.lock
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,29 +1,3 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
2
|
+
gemspec
|
5
3
|
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
|
9
|
-
if RUBY_VERSION =~ /^1.8/
|
10
|
-
gem 'hashery'
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
group :documentation do
|
15
|
-
gem "yard", "~> 0.6.0"
|
16
|
-
end
|
17
|
-
|
18
|
-
group :development do
|
19
|
-
gem "minitest", ">= 0"
|
20
|
-
gem "bundler", "~> 1"
|
21
|
-
gem "jeweler", "~> 1.6.4"
|
22
|
-
end
|
23
|
-
|
24
|
-
# Don't require 'turn' to format tests, but use it if you have it
|
25
|
-
# begin
|
26
|
-
# require 'turn'
|
27
|
-
# gem 'turn', '>=0.9.3'
|
28
|
-
# rescue LoadError
|
29
|
-
# end
|
data/README.md
CHANGED
@@ -11,9 +11,9 @@ mm[/a/] = 'apat'
|
|
11
11
|
mm[/b/] = ['bpat1', 'bpat2']
|
12
12
|
mm[/.+b$/] = 'bpat3'
|
13
13
|
|
14
|
-
mm['a']
|
15
|
-
mm['aa']
|
16
|
-
mm['b']
|
14
|
+
mm['a'] #=> ['a_string', 'apat'] # order is the same as the key order
|
15
|
+
mm['aa'] #=> ['apat']
|
16
|
+
mm['b'] #=> ['bpat1', 'bpat2']
|
17
17
|
mm['cob'] #=> ['bpat1', 'bpat2', 'bpat3'] # flattened one level!!!
|
18
18
|
mm['cab'] #=> ['apat', 'bpat1', 'bpat2', 'bpat3']
|
19
19
|
mm['c'] #=> [] # no match
|
data/Rakefile
CHANGED
@@ -1,44 +1,40 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
begin
|
3
|
+
require 'bundler'
|
4
|
+
rescue LoadError => e
|
5
|
+
warn e.message
|
6
|
+
warn "Run `gem install bundler` to install Bundler."
|
7
|
+
exit -1
|
8
|
+
end
|
2
9
|
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
10
|
begin
|
6
|
-
Bundler.setup(:
|
11
|
+
Bundler.setup(:development)
|
7
12
|
rescue Bundler::BundlerError => e
|
8
|
-
|
9
|
-
|
13
|
+
warn e.message
|
14
|
+
warn "Run `bundle install` to install missing gems."
|
10
15
|
exit e.status_code
|
11
16
|
end
|
17
|
+
|
12
18
|
require 'rake'
|
13
19
|
|
14
|
-
require
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = "A multimap that allows keys to match regex patterns"
|
21
|
-
gem.description = %Q{MatchMap is a map representing key=>value pairs but where
|
22
|
-
(a) a query argument can match more than one key, and (b) the argument is compraed to the key
|
23
|
-
such that you can use regex patterns as keys}
|
24
|
-
gem.email = "bill@dueber.com"
|
25
|
-
gem.authors = ["Bill Dueber"]
|
26
|
-
# dependencies defined in Gemfile
|
27
|
-
end
|
28
|
-
Jeweler::RubygemsDotOrgTasks.new
|
20
|
+
require "bundler/gem_tasks"
|
21
|
+
|
22
|
+
require 'yard'
|
23
|
+
YARD::Rake::YardocTask.new
|
24
|
+
task :doc => :yard
|
29
25
|
|
30
26
|
require 'rake/testtask'
|
31
|
-
Rake::TestTask.new
|
32
|
-
test.libs << '
|
27
|
+
Rake::TestTask.new do |test|
|
28
|
+
test.libs << 'test'
|
33
29
|
test.pattern = 'test/**/test_*.rb'
|
34
30
|
test.verbose = true
|
35
31
|
end
|
36
32
|
|
33
|
+
task :default => [:test]
|
34
|
+
|
37
35
|
desc "Run a quick benchmark"
|
38
36
|
task :bench do
|
39
37
|
$: << 'lib'
|
40
38
|
load 'bench/bench.rb'
|
41
39
|
end
|
42
40
|
|
43
|
-
task :default => :test
|
44
|
-
|
data/bench/bench.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'benchmark'
|
2
2
|
require 'match_map'
|
3
|
+
require 'pry'
|
4
|
+
require 'pry-nav'
|
3
5
|
|
4
6
|
h5 = {
|
5
7
|
'a' => 'A',
|
@@ -20,6 +22,8 @@ end
|
|
20
22
|
# @mm2[/a/] = 'AAA'
|
21
23
|
|
22
24
|
iters = 100_000
|
25
|
+
binding.pry
|
26
|
+
|
23
27
|
puts "Testing #{iters} accesses"
|
24
28
|
|
25
29
|
method = (defined? JRUBY_VERSION) ? :bmbm : :bm
|
data/lib/match_map.rb
CHANGED
@@ -6,26 +6,25 @@ class MatchMap
|
|
6
6
|
|
7
7
|
attr_accessor :default
|
8
8
|
attr_reader :echo
|
9
|
-
|
10
|
-
if RUBY_VERSION =~ /^1\.9/
|
11
|
-
require 'match_map/match_map_19'
|
12
|
-
include MatchMapIncludes::OnePointNine
|
13
|
-
else
|
14
|
-
require 'match_map/match_map_18'
|
15
|
-
include MatchMapIncludes::OnePointEight
|
16
|
-
end
|
17
9
|
|
18
|
-
def initialize
|
10
|
+
def initialize(h = {}, &blk)
|
19
11
|
@default = nil # default miss value is nil
|
20
12
|
@attrs = {}
|
13
|
+
|
21
14
|
# Set up the appripriate @map and define which inner_get to use
|
22
|
-
|
15
|
+
# initially, the non-optimized version
|
16
|
+
@map = {}
|
17
|
+
define_singleton_method :inner_get, method(:normal_inner_get)
|
23
18
|
|
24
19
|
# Initialize with the given hash
|
25
20
|
h.each_pair do |k, v|
|
26
21
|
self[k] = v
|
27
22
|
end
|
28
23
|
|
24
|
+
if block_given?
|
25
|
+
blk.call(self)
|
26
|
+
end
|
27
|
+
|
29
28
|
end
|
30
29
|
|
31
30
|
def delete key
|
data/match_map.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'match_map/version'
|
5
|
+
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "match_map"
|
9
|
+
gem.version = MatchMap::VERSION
|
10
|
+
gem.summary = "A multimap that allows keys to match regex patterns"
|
11
|
+
gem.description = "MatchMap is a map representing key=>value pairs but where \n (a) a query argument can match more than one key, and (b) the argument is compraed to the key\n such that you can use regex patterns as keys"
|
12
|
+
gem.license = "MIT"
|
13
|
+
gem.authors = ["Bill Dueber"]
|
14
|
+
gem.email = "bill@dueber.com"
|
15
|
+
gem.homepage = "http://github.com/billdueber/match_map"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ['lib']
|
21
|
+
|
22
|
+
|
23
|
+
gem.add_development_dependency 'bundler', '~> 1.0'
|
24
|
+
gem.add_development_dependency 'minitest'
|
25
|
+
gem.add_development_dependency 'rake'
|
26
|
+
gem.add_development_dependency 'yard'
|
27
|
+
|
28
|
+
|
29
|
+
end
|
30
|
+
|
data/test/helper.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'bundler'
|
3
2
|
begin
|
4
3
|
Bundler.setup(:default, :development)
|
@@ -7,16 +6,9 @@ rescue Bundler::BundlerError => e
|
|
7
6
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
7
|
exit e.status_code
|
9
8
|
end
|
9
|
+
require 'minitest'
|
10
10
|
require 'minitest/spec'
|
11
11
|
require 'minitest/benchmark'
|
12
|
-
# if RUBY_VERSION =~ /^1.9/
|
13
|
-
# begin
|
14
|
-
# require 'turn/autorun'
|
15
|
-
# # f = ENV['format'] || 'progress'
|
16
|
-
# # Turn.config.format = f.to_sym if f
|
17
|
-
# rescue LoadError
|
18
|
-
# end
|
19
|
-
# end
|
20
12
|
|
21
13
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
22
14
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -25,4 +17,4 @@ require 'match_map'
|
|
25
17
|
class MiniTest::Unit::TestCase
|
26
18
|
end
|
27
19
|
|
28
|
-
MiniTest
|
20
|
+
MiniTest.autorun
|
metadata
CHANGED
@@ -1,60 +1,81 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: match_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bill Dueber
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-10-11 00:00:00.000000000 Z
|
13
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'
|
14
27
|
- !ruby/object:Gem::Dependency
|
15
28
|
name: minitest
|
16
|
-
requirement:
|
17
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
18
30
|
requirements:
|
19
31
|
- - ! '>='
|
20
32
|
- !ruby/object:Gem::Version
|
21
33
|
version: '0'
|
22
34
|
type: :development
|
23
35
|
prerelease: false
|
24
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
25
41
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
28
|
-
none: false
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
29
44
|
requirements:
|
30
|
-
- -
|
45
|
+
- - ! '>='
|
31
46
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
47
|
+
version: '0'
|
33
48
|
type: :development
|
34
49
|
prerelease: false
|
35
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
36
55
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
39
|
-
none: false
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
40
58
|
requirements:
|
41
|
-
- -
|
59
|
+
- - ! '>='
|
42
60
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
61
|
+
version: '0'
|
44
62
|
type: :development
|
45
63
|
prerelease: false
|
46
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
47
69
|
description: ! "MatchMap is a map representing key=>value pairs but where \n (a)
|
48
70
|
a query argument can match more than one key, and (b) the argument is compraed to
|
49
71
|
the key\n such that you can use regex patterns as keys"
|
50
72
|
email: bill@dueber.com
|
51
73
|
executables: []
|
52
74
|
extensions: []
|
53
|
-
extra_rdoc_files:
|
54
|
-
- LICENSE.txt
|
55
|
-
- README.md
|
75
|
+
extra_rdoc_files: []
|
56
76
|
files:
|
57
77
|
- .document
|
78
|
+
- .gitignore
|
58
79
|
- .travis.yml
|
59
80
|
- CHANGES
|
60
81
|
- Gemfile
|
@@ -64,36 +85,35 @@ files:
|
|
64
85
|
- VERSION
|
65
86
|
- bench/bench.rb
|
66
87
|
- lib/match_map.rb
|
67
|
-
- lib/match_map/
|
68
|
-
-
|
88
|
+
- lib/match_map/version.rb
|
89
|
+
- match_map.gemspec
|
69
90
|
- test/helper.rb
|
70
91
|
- test/test_match_map.rb
|
71
92
|
homepage: http://github.com/billdueber/match_map
|
72
93
|
licenses:
|
73
94
|
- MIT
|
95
|
+
metadata: {}
|
74
96
|
post_install_message:
|
75
97
|
rdoc_options: []
|
76
98
|
require_paths:
|
77
99
|
- lib
|
78
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
101
|
requirements:
|
81
102
|
- - ! '>='
|
82
103
|
- !ruby/object:Gem::Version
|
83
104
|
version: '0'
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
hash: 2828716471477841812
|
87
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
106
|
requirements:
|
90
107
|
- - ! '>='
|
91
108
|
- !ruby/object:Gem::Version
|
92
109
|
version: '0'
|
93
110
|
requirements: []
|
94
111
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 2.1.5
|
96
113
|
signing_key:
|
97
|
-
specification_version:
|
114
|
+
specification_version: 4
|
98
115
|
summary: A multimap that allows keys to match regex patterns
|
99
|
-
test_files:
|
116
|
+
test_files:
|
117
|
+
- test/helper.rb
|
118
|
+
- test/test_match_map.rb
|
119
|
+
has_rdoc:
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# In ruby 1.8x, the Hashes are not ordered, so we fall back on
|
2
|
-
# the hashery ordered_hash
|
3
|
-
|
4
|
-
require 'hashery/ordered_hash'
|
5
|
-
|
6
|
-
module MatchMapIncludes
|
7
|
-
module OnePointEight
|
8
|
-
# 1.8 setup
|
9
|
-
def setup h
|
10
|
-
singleton_class = class << self; self; end
|
11
|
-
singleton_class.send(:define_method, :inner_get, method(:normal_inner_get))
|
12
|
-
@map = OrderedHash.new
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|