fast_underscore 0.3.1 → 0.3.2
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 +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/main.yml +44 -0
- data/.rubocop.yml +21 -5
- data/CHANGELOG.md +44 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +58 -36
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +15 -36
- data/Steepfile +6 -0
- data/bin/{benchmark → bench} +1 -0
- data/bin/console +1 -0
- data/ext/fast_underscore/fast_underscore.c +132 -191
- data/fast_underscore.gemspec +5 -4
- data/gemfiles/5.1.gemfile +1 -1
- data/gemfiles/5.2.gemfile +1 -1
- data/gemfiles/6.0.gemfile +7 -0
- data/gemfiles/6.1.gemfile +7 -0
- data/lib/fast_underscore.rb +66 -23
- data/lib/fast_underscore/version.rb +1 -1
- data/sig/fast_underscore.rbs +10 -0
- metadata +36 -20
- data/.travis.yml +0 -9
- data/bin/rake +0 -29
- data/bin/rubocop +0 -29
- data/lib/fast_underscore/acronym_regex.rb +0 -28
- data/lib/fast_underscore/acronym_underscore_regex.rb +0 -23
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', '~>
|
29
|
+
spec.add_development_dependency 'rake', '~> 13'
|
30
30
|
spec.add_development_dependency 'rake-compiler', '~> 1'
|
31
|
-
spec.add_development_dependency 'rubocop', '~>
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 1.12'
|
32
|
+
spec.add_development_dependency 'steep'
|
32
33
|
end
|
data/gemfiles/5.1.gemfile
CHANGED
data/gemfiles/5.2.gemfile
CHANGED
data/lib/fast_underscore.rb
CHANGED
@@ -4,42 +4,85 @@ require 'fast_underscore/version'
|
|
4
4
|
require 'fast_underscore/fast_underscore'
|
5
5
|
|
6
6
|
module FastUnderscore
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
16
|
+
|
17
|
+
def underscore(string)
|
18
|
+
return string unless /[A-Z-]|::/.match?(string)
|
19
|
+
|
20
|
+
response = string.dup
|
21
|
+
response.gsub!(ActiveSupportInflectorOldPatch.pattern) do
|
22
|
+
"#{$1 && '_'}#{$2.downcase}"
|
23
|
+
end
|
24
|
+
|
25
|
+
FastUnderscore.underscore(response)
|
26
|
+
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
|
43
|
+
|
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
|
51
|
+
end
|
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
|
56
|
+
def underscore
|
57
|
+
ActiveSupport::Inflector.underscore(self)
|
58
|
+
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
|
13
66
|
require 'active_support/version'
|
14
67
|
gem_version = Gem::Version.new(ActiveSupport::VERSION::STRING)
|
15
68
|
|
16
69
|
if gem_version >= Gem::Version.new('5.2.0')
|
17
|
-
|
70
|
+
ActiveSupport::Inflector.prepend(ActiveSupportInflectorPatch)
|
18
71
|
else
|
19
|
-
|
72
|
+
ActiveSupport::Inflector.prepend(ActiveSupportInflectorOldPatch)
|
20
73
|
end
|
74
|
+
|
75
|
+
ActiveSupport::Inflector.alias_method(:as_underscore, :underscore)
|
76
|
+
String.prepend(ActiveSupportStringPatch)
|
21
77
|
end
|
22
78
|
end
|
23
79
|
|
24
80
|
if defined?(ActiveSupport)
|
25
|
-
FastUnderscore.
|
81
|
+
FastUnderscore.active_support
|
26
82
|
else
|
27
83
|
module ActiveSupport
|
28
84
|
module Inflector
|
29
|
-
|
30
|
-
prepend(
|
31
|
-
Module.new do
|
32
|
-
# Hooks into ActiveSupport::Inflector and waits for the #underscore
|
33
|
-
# method to be defined. When it is, it automatically redefines it.
|
34
|
-
# Using this `prepend` trick to attempt to be a good citizen in the
|
35
|
-
# case that someone else has already hooked into `method_added` on
|
36
|
-
# `Inflector`.
|
37
|
-
def method_added(method)
|
38
|
-
method == :underscore ? FastUnderscore.install : super
|
39
|
-
end
|
40
|
-
end
|
41
|
-
)
|
42
|
-
end
|
85
|
+
prepend(FastUnderscore::ActiveSupportedDelayedPatch)
|
43
86
|
end
|
44
87
|
end
|
45
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.3.
|
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,14 +58,14 @@ 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
|
@@ -86,14 +86,28 @@ dependencies:
|
|
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,18 +116,20 @@ 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
|
@@ -121,15 +137,16 @@ files:
|
|
121
137
|
- fast_underscore.gemspec
|
122
138
|
- gemfiles/5.1.gemfile
|
123
139
|
- gemfiles/5.2.gemfile
|
140
|
+
- gemfiles/6.0.gemfile
|
141
|
+
- gemfiles/6.1.gemfile
|
124
142
|
- lib/fast_underscore.rb
|
125
|
-
- lib/fast_underscore/acronym_regex.rb
|
126
|
-
- lib/fast_underscore/acronym_underscore_regex.rb
|
127
143
|
- lib/fast_underscore/version.rb
|
144
|
+
- sig/fast_underscore.rbs
|
128
145
|
homepage: https://github.com/kddeisz/fast_underscore
|
129
146
|
licenses:
|
130
147
|
- MIT
|
131
148
|
metadata: {}
|
132
|
-
post_install_message:
|
149
|
+
post_install_message:
|
133
150
|
rdoc_options: []
|
134
151
|
require_paths:
|
135
152
|
- lib
|
@@ -144,9 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
161
|
- !ruby/object:Gem::Version
|
145
162
|
version: '0'
|
146
163
|
requirements: []
|
147
|
-
|
148
|
-
|
149
|
-
signing_key:
|
164
|
+
rubygems_version: 3.2.3
|
165
|
+
signing_key:
|
150
166
|
specification_version: 4
|
151
167
|
summary: Fast String#underscore implementation
|
152
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")
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module FastUnderscore
|
4
|
-
# Uses ActiveSupport's `acronym_regex` method to construct a memoized pattern
|
5
|
-
# for replacing acronyms within strings that need to be underscored.
|
6
|
-
module AcronymRegex
|
7
|
-
def self.pattern
|
8
|
-
return @pattern if defined?(@pattern)
|
9
|
-
|
10
|
-
acronym_regex = ActiveSupport::Inflector.inflections.acronym_regex
|
11
|
-
@pattern ||= /(?:(?<=([A-Za-z\d]))|\b)(#{acronym_regex})(?=\b|[^a-z])/
|
12
|
-
end
|
13
|
-
|
14
|
-
def underscore(string)
|
15
|
-
return string unless /[A-Z-]|::/.match?(string)
|
16
|
-
|
17
|
-
response = string.dup
|
18
|
-
response.gsub!(AcronymRegex.pattern) { "#{$1 && '_'}#{$2.downcase}" }
|
19
|
-
|
20
|
-
FastUnderscore.underscore(response)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class << ActiveSupport::Inflector
|
25
|
-
alias as_underscore underscore
|
26
|
-
include AcronymRegex
|
27
|
-
end
|
28
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module FastUnderscore
|
4
|
-
# Uses ActiveSupport's `acronym_underscore_regex` method for replacing
|
5
|
-
# acronyms within strings that need to be underscored.
|
6
|
-
module AcronymUnderscoreRegex
|
7
|
-
def underscore(string)
|
8
|
-
return string unless /[A-Z-]|::/.match?(string)
|
9
|
-
|
10
|
-
response = string.dup
|
11
|
-
acronyms = ActiveSupport::Inflector.inflections.acronyms_underscore_regex
|
12
|
-
|
13
|
-
response.gsub!(acronyms) { "#{$1 && '_'}#{$2.downcase}" }
|
14
|
-
|
15
|
-
FastUnderscore.underscore(response)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class << ActiveSupport::Inflector
|
20
|
-
alias as_underscore underscore
|
21
|
-
include AcronymUnderscoreRegex
|
22
|
-
end
|
23
|
-
end
|