fast_underscore 0.0.2 → 0.0.3

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
- SHA256:
3
- metadata.gz: c17dba8603583fe3bbf453105935b8096e5b2d203ee897c6dcbc615271cfc319
4
- data.tar.gz: 59957bc68910d3cfb38b1bbf010f3cfd7136e75ef4869883f101386786454ae8
2
+ SHA1:
3
+ metadata.gz: 84633c6f2e1999fd6b93ee69f0d6a7ea14f24f44
4
+ data.tar.gz: 7144cd7352002a733c739d4cca97f9f187ea6c02
5
5
  SHA512:
6
- metadata.gz: b6eba585974debc3350e9308b326ef7c9c7060adca5fc02c9dd084561f05579ff39617ad71d88b6fa02d170c1bee4fc2f7d4b867e135e2fa79cb1dae66f4a1a3
7
- data.tar.gz: adedbd73f9b7181c2648cfbe751e7bd716fc72dde0eef7ec2cf06fd33b06c393e2a282bdec55f0e1b59837457f8b537b99b3d13501439667f2bdd371d25de42a
6
+ metadata.gz: 67c6c5a8b86fee5594a47b7bd84da9498cf141d809e24539758deb7eb6e62e6462f63109d98bca10a0e2885bd89ee7728f601896ba21930eefb6732d5afa7c0c
7
+ data.tar.gz: 44a54f7a4dc34584b792bd9ba2e1b2adb11891f14e16d5ef2e0207853d23997d99de64e95dfe62d03fdd2b3b9ff032776d2ee7e7bf37c3b974a7185e91764a85
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fast_underscore (0.0.2)
4
+ fast_underscore (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -7,7 +7,18 @@
7
7
 
8
8
  ## Do I need this?
9
9
 
10
- Maybe! Run a stack profiler like [`ruby-prof`](https://github.com/ruby-prof/ruby-prof). If `String#underscore` is coming up near the top of the list, this gem might be for you! If not, you probably don't need it. Either way, your milage may vary depending on the type of strings on which you're calling `underscore`.
10
+ Maybe! Run a stack profiler like [`ruby-prof`](https://github.com/ruby-prof/ruby-prof). If `String#underscore` or `ActiveSupport::Inflector#underscore` is coming up near the top of the list, this gem might be for you! If not, you probably don't need it. Either way, your milage may vary depending on the type of strings on which you're calling `underscore`.
11
+
12
+ ## Usage with Rails
13
+
14
+ `ActiveSupport::Inflector#underscore` is actually used significantly throughout the Rails boot process, so it's best to hook into that process early to get the best results. Place the following lines above the `require 'rails'` line in your `application.rb` file:
15
+
16
+ ```ruby
17
+ require 'active_support'
18
+ require 'fast_underscore'
19
+ ```
20
+
21
+ This will allow Rails to use the faster underscore method while it is booting, which is used for autoloading dependencies, as well as determining table names.
11
22
 
12
23
  ## Is it fast?
13
24
 
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
+ require 'active_support'
4
5
  require 'fast_underscore'
5
6
 
6
7
  require 'irb'
@@ -8,14 +8,20 @@ if defined?(ActiveSupport)
8
8
  def underscore
9
9
  return self unless /[A-Z-]|::/.match?(self)
10
10
 
11
+ response = dup
11
12
  acronyms = ActiveSupport::Inflector.inflections.acronym_regex
12
- dup.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{acronyms})(?=\b|[^a-z])/) do
13
+
14
+ response.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{acronyms})(?=\b|[^a-z])/) do
13
15
  "#{$1 && '_'}#{$2.downcase}"
14
16
  end
15
17
 
16
- FastUnderscore.underscore(self)
18
+ FastUnderscore.underscore(response)
17
19
  end
18
20
  end)
21
+
22
+ class << ActiveSupport::Inflector
23
+ define_method(:underscore, &FastUnderscore.method(:underscore))
24
+ end
19
25
  else
20
26
  String.prepend(Module.new do
21
27
  def underscore
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastUnderscore
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Deisz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-16 00:00:00.000000000 Z
11
+ date: 2017-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  requirements: []
143
143
  rubyforge_project:
144
- rubygems_version: 2.7.3
144
+ rubygems_version: 2.6.13
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: Fast String#underscore implementation