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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84633c6f2e1999fd6b93ee69f0d6a7ea14f24f44
4
- data.tar.gz: 7144cd7352002a733c739d4cca97f9f187ea6c02
3
+ metadata.gz: 07fbe0b6f67b99fa5786e31ff487a444e1ac649b
4
+ data.tar.gz: 467ac00f6bec4ef82f4ba862dff95751e3ad5063
5
5
  SHA512:
6
- metadata.gz: 67c6c5a8b86fee5594a47b7bd84da9498cf141d809e24539758deb7eb6e62e6462f63109d98bca10a0e2885bd89ee7728f601896ba21930eefb6732d5afa7c0c
7
- data.tar.gz: 44a54f7a4dc34584b792bd9ba2e1b2adb11891f14e16d5ef2e0207853d23997d99de64e95dfe62d03fdd2b3b9ff032776d2ee7e7bf37c3b974a7185e91764a85
6
+ metadata.gz: a075571a7c8b3d84ace4442410bf11b3387a19cd1eb85de6207931426f568b48a7ca02eb8bd007a2e5e4238e4eca8b7eac96e38899a121173515e490aa012620
7
+ data.tar.gz: 1e87466be79faddedb5f69fa3b554aecb708bb16eaee1e71d7a03b0c1a9fb880456ed3fe39557c05559e9dd5fc9e357edcdacec265777b9b1824cd1bcb8385a4
data/.gitignore CHANGED
@@ -6,4 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+
10
+ /gemfiles/*.lock
9
11
  /lib/fast_underscore/fast_underscore.bundle
@@ -4,7 +4,7 @@ AllCops:
4
4
  TargetRubyVersion: 2.4
5
5
  Exclude:
6
6
  - 'bin/**/*'
7
- - 'vendor/**/*'
7
+ - 'gemfiles/**/*'
8
8
  - 'tmp/**/*'
9
9
 
10
10
  Style/PerlBackrefs:
@@ -4,3 +4,6 @@ branches:
4
4
  only: master
5
5
  cache: bundler
6
6
  script: bin/rubocop && bin/rake
7
+ gemfile:
8
+ - gemfiles/5.1.gemfile
9
+ - gemfiles/5.2.gemfile
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'activesupport', '~> 5.1'
7
+ gem 'activesupport', '~> 5.2.0.beta2'
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fast_underscore (0.0.3)
4
+ fast_underscore (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (5.1.4)
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.1)
45
+ activesupport (~> 5.2.0.beta2)
46
46
  benchmark-ips (~> 2)
47
47
  bundler (~> 1)
48
48
  fast_underscore!
@@ -3,8 +3,8 @@
3
3
  require 'bundler/setup'
4
4
  require 'benchmark/ips'
5
5
 
6
- require 'active_support'
7
6
  require 'fast_underscore'
7
+ require 'active_support'
8
8
 
9
9
  source =
10
10
  %w[_ - : :: / 漢字 😊🎉] + ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec path: '..'
6
+
7
+ gem 'activesupport', '~> 5.1'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec path: '..'
6
+
7
+ gem 'activesupport', '~> 5.2.0.beta2'
@@ -3,29 +3,10 @@
3
3
  require 'fast_underscore/version'
4
4
  require 'fast_underscore/fast_underscore'
5
5
 
6
- if defined?(ActiveSupport)
7
- String.prepend(Module.new do
8
- def underscore
9
- return self unless /[A-Z-]|::/.match?(self)
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
- String.prepend(Module.new do
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)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Provides a C-optimized method for underscoring a string
3
4
  module FastUnderscore
4
- VERSION = '0.0.3'
5
+ VERSION = '0.1.0'
5
6
  end
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.3
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: