fast_underscore 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -1
- data/.travis.yml +3 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/bin/benchmark +1 -1
- data/gemfiles/5.1.gemfile +7 -0
- data/gemfiles/5.2.gemfile +7 -0
- data/lib/fast_underscore.rb +5 -24
- data/lib/fast_underscore/ext/acronym_regex.rb +29 -0
- data/lib/fast_underscore/ext/acronym_underscore_regex.rb +24 -0
- data/lib/fast_underscore/ext/plain_string.rb +13 -0
- data/lib/fast_underscore/version.rb +2 -1
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07fbe0b6f67b99fa5786e31ff487a444e1ac649b
|
4
|
+
data.tar.gz: 467ac00f6bec4ef82f4ba862dff95751e3ad5063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a075571a7c8b3d84ace4442410bf11b3387a19cd1eb85de6207931426f568b48a7ca02eb8bd007a2e5e4238e4eca8b7eac96e38899a121173515e490aa012620
|
7
|
+
data.tar.gz: 1e87466be79faddedb5f69fa3b554aecb708bb16eaee1e71d7a03b0c1a9fb880456ed3fe39557c05559e9dd5fc9e357edcdacec265777b9b1824cd1bcb8385a4
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fast_underscore (0.0
|
4
|
+
fast_underscore (0.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activesupport (5.
|
9
|
+
activesupport (5.2.0.beta2)
|
10
10
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
11
|
i18n (~> 0.7)
|
12
12
|
minitest (~> 5.1)
|
@@ -42,7 +42,7 @@ PLATFORMS
|
|
42
42
|
ruby
|
43
43
|
|
44
44
|
DEPENDENCIES
|
45
|
-
activesupport (~> 5.
|
45
|
+
activesupport (~> 5.2.0.beta2)
|
46
46
|
benchmark-ips (~> 2)
|
47
47
|
bundler (~> 1)
|
48
48
|
fast_underscore!
|
data/bin/benchmark
CHANGED
data/lib/fast_underscore.rb
CHANGED
@@ -3,29 +3,10 @@
|
|
3
3
|
require 'fast_underscore/version'
|
4
4
|
require 'fast_underscore/fast_underscore'
|
5
5
|
|
6
|
-
if defined?(ActiveSupport)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
response = dup
|
12
|
-
acronyms = ActiveSupport::Inflector.inflections.acronym_regex
|
13
|
-
|
14
|
-
response.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{acronyms})(?=\b|[^a-z])/) do
|
15
|
-
"#{$1 && '_'}#{$2.downcase}"
|
16
|
-
end
|
17
|
-
|
18
|
-
FastUnderscore.underscore(response)
|
19
|
-
end
|
20
|
-
end)
|
21
|
-
|
22
|
-
class << ActiveSupport::Inflector
|
23
|
-
define_method(:underscore, &FastUnderscore.method(:underscore))
|
24
|
-
end
|
6
|
+
if !defined?(ActiveSupport)
|
7
|
+
require 'fast_underscore/ext/plain_string'
|
8
|
+
elsif ActiveSupport::VERSION::MAJOR == 5 && ActiveSupport::VERSION::MINOR >= 2
|
9
|
+
require 'fast_underscore/ext/acronym_underscore_regex'
|
25
10
|
else
|
26
|
-
|
27
|
-
def underscore
|
28
|
-
FastUnderscore.underscore(self)
|
29
|
-
end
|
30
|
-
end)
|
11
|
+
require 'fast_underscore/ext/acronym_regex'
|
31
12
|
end
|
@@ -0,0 +1,29 @@
|
|
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
|
15
|
+
return self unless /[A-Z-]|::/.match?(self)
|
16
|
+
|
17
|
+
response = dup
|
18
|
+
response.gsub!(AcronymRegex.pattern) { "#{$1 && '_'}#{$2.downcase}" }
|
19
|
+
|
20
|
+
FastUnderscore.underscore(response)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
String.prepend(FastUnderscore::AcronymRegex)
|
26
|
+
|
27
|
+
class << ActiveSupport::Inflector
|
28
|
+
define_method(:underscore, &FastUnderscore.method(:underscore))
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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
|
8
|
+
return self unless /[A-Z-]|::/.match?(self)
|
9
|
+
|
10
|
+
response = 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
|
+
end
|
19
|
+
|
20
|
+
String.prepend(FastUnderscore::AcronymUnderscoreRegex)
|
21
|
+
|
22
|
+
class << ActiveSupport::Inflector
|
23
|
+
define_method(:underscore, &FastUnderscore.method(:underscore))
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FastUnderscore
|
4
|
+
# Extends String to include an underscore method that delegates over to
|
5
|
+
# FastUnderscore's `#underscore` method.
|
6
|
+
module StringExtension
|
7
|
+
def underscore
|
8
|
+
FastUnderscore.underscore(self)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
String.prepend(FastUnderscore::StringExtension)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_underscore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
@@ -119,7 +119,12 @@ files:
|
|
119
119
|
- ext/fast_underscore/fast_underscore.c
|
120
120
|
- ext/fast_underscore/fast_underscore.h
|
121
121
|
- fast_underscore.gemspec
|
122
|
+
- gemfiles/5.1.gemfile
|
123
|
+
- gemfiles/5.2.gemfile
|
122
124
|
- lib/fast_underscore.rb
|
125
|
+
- lib/fast_underscore/ext/acronym_regex.rb
|
126
|
+
- lib/fast_underscore/ext/acronym_underscore_regex.rb
|
127
|
+
- lib/fast_underscore/ext/plain_string.rb
|
123
128
|
- lib/fast_underscore/version.rb
|
124
129
|
homepage: https://github.com/kddeisz/fast_underscore
|
125
130
|
licenses:
|