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.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
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', '~> 1'
27
+ spec.add_development_dependency 'bundler', '~> 2'
28
28
  spec.add_development_dependency 'minitest', '~> 5'
29
- spec.add_development_dependency 'rake', '~> 12'
30
- spec.add_development_dependency 'rake-compiler', '~> 0'
31
- spec.add_development_dependency 'rubocop', '~> 0.52'
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
@@ -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.7'
@@ -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.5'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec path: '..'
6
+
7
+ gem 'activesupport', '~> 6.0.3'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec path: '..'
6
+
7
+ gem 'activesupport', '~> 6.1.3'
@@ -3,29 +3,86 @@
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)
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
- response = dup
12
- acronyms = ActiveSupport::Inflector.inflections.acronym_regex
17
+ def underscore(string)
18
+ return string unless /[A-Z-]|::/.match?(string)
13
19
 
14
- response.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{acronyms})(?=\b|[^a-z])/) do
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
- class << ActiveSupport::Inflector
23
- define_method(:underscore, &FastUnderscore.method(:underscore))
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
- else
26
- String.prepend(Module.new do
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
- FastUnderscore.underscore(self)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastUnderscore
4
- VERSION = '0.0.3'
4
+ VERSION = '0.3.2'
5
5
  end
@@ -0,0 +1,10 @@
1
+ module FastUnderscore
2
+ VERSION: String
3
+
4
+ def self.active_support: () -> void
5
+ def self.underscore: (String string) -> String
6
+ end
7
+
8
+ class String
9
+ def underscore: () -> String
10
+ 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.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: 2017-12-17 00:00:00.000000000 Z
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: '1'
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: '1'
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: '12'
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: '12'
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: '0'
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: '0'
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: '0.52'
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: '0.52'
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
- - ".travis.yml"
123
+ - CHANGELOG.md
124
+ - CODE_OF_CONDUCT.md
108
125
  - Gemfile
109
126
  - Gemfile.lock
110
- - LICENSE.txt
127
+ - LICENSE
111
128
  - README.md
112
129
  - Rakefile
113
- - bin/benchmark
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
- rubyforge_project:
144
- rubygems_version: 2.6.13
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
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm: 2.4.3
3
- branches:
4
- only: master
5
- cache: bundler
6
- script: bin/rubocop && bin/rake
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")