fast_underscore 0.0.3 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/main.yml +44 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +24 -5
- data/CHANGELOG.md +44 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +58 -31
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +16 -25
- data/Steepfile +6 -0
- data/bin/{benchmark → bench} +3 -2
- data/bin/console +1 -1
- data/ext/fast_underscore/fast_underscore.c +133 -182
- data/fast_underscore.gemspec +6 -5
- data/gemfiles/5.1.gemfile +7 -0
- data/gemfiles/5.2.gemfile +7 -0
- data/gemfiles/6.0.gemfile +7 -0
- data/gemfiles/6.1.gemfile +7 -0
- data/lib/fast_underscore.rb +71 -14
- data/lib/fast_underscore/version.rb +1 -1
- data/sig/fast_underscore.rbs +10 -0
- metadata +40 -20
- data/.travis.yml +0 -6
- data/bin/rake +0 -29
- data/bin/rubocop +0 -29
data/fast_underscore.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'fast_underscore/version'
|
6
6
|
|
@@ -24,9 +24,10 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.extensions = ['ext/fast_underscore/extconf.rb']
|
25
25
|
|
26
26
|
spec.add_development_dependency 'benchmark-ips', '~> 2'
|
27
|
-
spec.add_development_dependency 'bundler', '~>
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
28
28
|
spec.add_development_dependency 'minitest', '~> 5'
|
29
|
-
spec.add_development_dependency 'rake', '~>
|
30
|
-
spec.add_development_dependency 'rake-compiler', '~>
|
31
|
-
spec.add_development_dependency 'rubocop', '~>
|
29
|
+
spec.add_development_dependency 'rake', '~> 13'
|
30
|
+
spec.add_development_dependency 'rake-compiler', '~> 1'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 1.12'
|
32
|
+
spec.add_development_dependency 'steep'
|
32
33
|
end
|
data/lib/fast_underscore.rb
CHANGED
@@ -3,29 +3,86 @@
|
|
3
3
|
require 'fast_underscore/version'
|
4
4
|
require 'fast_underscore/fast_underscore'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
module FastUnderscore
|
7
|
+
# Override ActiveSupport::Inflector::underscore to use
|
8
|
+
# FastUnderscore::underscore for ActiveSupport < 5.2.0.
|
9
|
+
module ActiveSupportInflectorOldPatch
|
10
|
+
def self.pattern
|
11
|
+
return @pattern if defined?(@pattern)
|
12
|
+
|
13
|
+
acronym_regex = ActiveSupport::Inflector.inflections.acronym_regex
|
14
|
+
@pattern = /(?:(?<=([A-Za-z\d]))|\b)(#{acronym_regex})(?=\b|[^a-z])/
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
|
17
|
+
def underscore(string)
|
18
|
+
return string unless /[A-Z-]|::/.match?(string)
|
13
19
|
|
14
|
-
response.
|
20
|
+
response = string.dup
|
21
|
+
response.gsub!(ActiveSupportInflectorOldPatch.pattern) do
|
15
22
|
"#{$1 && '_'}#{$2.downcase}"
|
16
23
|
end
|
17
24
|
|
18
25
|
FastUnderscore.underscore(response)
|
19
26
|
end
|
20
|
-
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Override ActiveSupport::Inflector::underscore to use
|
30
|
+
# FastUnderscore::underscore for ActiveSupport >= 5.2.0.
|
31
|
+
module ActiveSupportInflectorPatch
|
32
|
+
def underscore(string)
|
33
|
+
return string unless /[A-Z-]|::/.match?(string)
|
34
|
+
|
35
|
+
response = string.dup
|
36
|
+
acronyms = ActiveSupport::Inflector.inflections.acronyms_underscore_regex
|
37
|
+
|
38
|
+
response.gsub!(acronyms) { "#{$1 && '_'}#{$2.downcase}" }
|
39
|
+
|
40
|
+
FastUnderscore.underscore(response)
|
41
|
+
end
|
42
|
+
end
|
21
43
|
|
22
|
-
|
23
|
-
|
44
|
+
# Hooks into ActiveSupport::Inflector and waits for the #underscore method to
|
45
|
+
# be defined. When it is, it automatically redefines it.
|
46
|
+
module ActiveSupportedDelayedPatch
|
47
|
+
def method_added(method)
|
48
|
+
FastUnderscore.active_support if method == :underscore
|
49
|
+
super
|
50
|
+
end
|
24
51
|
end
|
25
|
-
|
26
|
-
String
|
52
|
+
|
53
|
+
# Override the String#underscore method no matter when it was defined so that
|
54
|
+
# we're sure it's going to call the correct implementation.
|
55
|
+
module ActiveSupportStringPatch
|
27
56
|
def underscore
|
28
|
-
|
57
|
+
ActiveSupport::Inflector.underscore(self)
|
29
58
|
end
|
30
|
-
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Depending on ActiveSupport::VERSION, ::active_support determines the manner
|
62
|
+
# in which acronyms are handled, then it redefines the
|
63
|
+
# ActiveSupport::Inflector::underscore method to use the FastUnderscore
|
64
|
+
# native extension.
|
65
|
+
def self.active_support
|
66
|
+
require 'active_support/version'
|
67
|
+
gem_version = Gem::Version.new(ActiveSupport::VERSION::STRING)
|
68
|
+
|
69
|
+
if gem_version >= Gem::Version.new('5.2.0')
|
70
|
+
ActiveSupport::Inflector.prepend(ActiveSupportInflectorPatch)
|
71
|
+
else
|
72
|
+
ActiveSupport::Inflector.prepend(ActiveSupportInflectorOldPatch)
|
73
|
+
end
|
74
|
+
|
75
|
+
ActiveSupport::Inflector.alias_method(:as_underscore, :underscore)
|
76
|
+
String.prepend(ActiveSupportStringPatch)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
if defined?(ActiveSupport)
|
81
|
+
FastUnderscore.active_support
|
82
|
+
else
|
83
|
+
module ActiveSupport
|
84
|
+
module Inflector
|
85
|
+
prepend(FastUnderscore::ActiveSupportedDelayedPatch)
|
86
|
+
end
|
87
|
+
end
|
31
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_underscore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,42 +58,56 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake-compiler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '1.12'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '1.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: steep
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Provides a C-optimized method for underscoring a string
|
98
112
|
email:
|
99
113
|
- kevin.deisz@gmail.com
|
@@ -102,30 +116,37 @@ extensions:
|
|
102
116
|
- ext/fast_underscore/extconf.rb
|
103
117
|
extra_rdoc_files: []
|
104
118
|
files:
|
119
|
+
- ".github/dependabot.yml"
|
120
|
+
- ".github/workflows/main.yml"
|
105
121
|
- ".gitignore"
|
106
122
|
- ".rubocop.yml"
|
107
|
-
-
|
123
|
+
- CHANGELOG.md
|
124
|
+
- CODE_OF_CONDUCT.md
|
108
125
|
- Gemfile
|
109
126
|
- Gemfile.lock
|
110
|
-
- LICENSE
|
127
|
+
- LICENSE
|
111
128
|
- README.md
|
112
129
|
- Rakefile
|
113
|
-
-
|
130
|
+
- Steepfile
|
131
|
+
- bin/bench
|
114
132
|
- bin/console
|
115
|
-
- bin/rake
|
116
|
-
- bin/rubocop
|
117
133
|
- bin/setup
|
118
134
|
- ext/fast_underscore/extconf.rb
|
119
135
|
- ext/fast_underscore/fast_underscore.c
|
120
136
|
- ext/fast_underscore/fast_underscore.h
|
121
137
|
- fast_underscore.gemspec
|
138
|
+
- gemfiles/5.1.gemfile
|
139
|
+
- gemfiles/5.2.gemfile
|
140
|
+
- gemfiles/6.0.gemfile
|
141
|
+
- gemfiles/6.1.gemfile
|
122
142
|
- lib/fast_underscore.rb
|
123
143
|
- lib/fast_underscore/version.rb
|
144
|
+
- sig/fast_underscore.rbs
|
124
145
|
homepage: https://github.com/kddeisz/fast_underscore
|
125
146
|
licenses:
|
126
147
|
- MIT
|
127
148
|
metadata: {}
|
128
|
-
post_install_message:
|
149
|
+
post_install_message:
|
129
150
|
rdoc_options: []
|
130
151
|
require_paths:
|
131
152
|
- lib
|
@@ -140,9 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
161
|
- !ruby/object:Gem::Version
|
141
162
|
version: '0'
|
142
163
|
requirements: []
|
143
|
-
|
144
|
-
|
145
|
-
signing_key:
|
164
|
+
rubygems_version: 3.2.3
|
165
|
+
signing_key:
|
146
166
|
specification_version: 4
|
147
167
|
summary: Fast String#underscore implementation
|
148
168
|
test_files: []
|
data/.travis.yml
DELETED
data/bin/rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rake' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rake", "rake")
|
data/bin/rubocop
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rubocop' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rubocop", "rubocop")
|