fast_underscore 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 6365c2190445bc7618c3fe443583205ae7fc08cdb0151811a6d088db7582ca9c
4
- data.tar.gz: 351dc9c1c0b4c661bc2a909f94dabf4a018eae5cd0a2bb32e2c01916a9387c43
3
+ metadata.gz: 7d28091570b3b614967f128f03463f53a4756ead6eac601f5079f243360a792d
4
+ data.tar.gz: ed2f503634f9409882bce0c0c678f5e40d20deeb5df32f90b0bad1f957feaee6
5
5
  SHA512:
6
- metadata.gz: aae5d5f8d9914d5acc70271c307e39b4e57427a7816b278bd3455f0cc1cf66ce928c844a295796beb7827a81642d511ed2ede47188ac75cef4567e398d8a34f3
7
- data.tar.gz: 8fdd103f0920380ce462ca94b2d6f122a2465e4e793df9448d2c53d04a6f86c09ede6277689acab6958cf235cf02dae9a2a24b9ea1e9fe387ab5d7530ef44c35
6
+ metadata.gz: 8c1c36bb21b58386e63507972fa55914e3942e2fc19b7448b9d2bf1b93887b732e480f4da554cc8fcbf331f1ec7cab1e0a5aa10f4fccf7341fb56317c273c295
7
+ data.tar.gz: 11eabdb8ddc721164856fe7a76856045decf07b1b561e142e6915503e3648194cb59c3f4d021a3c1809435b31d75dcf7da6d06681b88693512aeeb759e10b777
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fast_underscore (0.2.0)
4
+ fast_underscore (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -4,28 +4,41 @@ require 'fast_underscore/version'
4
4
  require 'fast_underscore/fast_underscore'
5
5
 
6
6
  module FastUnderscore
7
- # Hooks into ActiveSupport::Inflector and waits for the #underscore method to
8
- # be defined. When it is, it automatically redefines it by hooking into its
9
- # acronyms and then still calling the native extension.
10
- module ActiveSupportHook
11
- def method_added(method)
12
- return super if method != :underscore || !defined?(ActiveSupport)
13
- require 'active_support/version'
7
+ # Depending on `ActiveSupport::VERSION`, `::install` determines the manner in
8
+ # which acronyms are handled, then it redefines the
9
+ # `ActiveSupport::Inflector::underscore` method to use the `FastUnderscore`
10
+ # native extension. It leaves the existing `ActiveSupport` monkeypatch on
11
+ # `String` that allows it to call into the newly redefined `Inflector` method.
12
+ def self.install
13
+ require 'active_support/version'
14
14
 
15
- if ActiveSupport::VERSION::MAJOR == 5 &&
16
- ActiveSupport::VERSION::MINOR >= 2
17
- require 'fast_underscore/ext/acronym_underscore_regex'
18
- else
19
- require 'fast_underscore/ext/acronym_regex'
20
- end
15
+ if ActiveSupport::VERSION::MAJOR == 5 && ActiveSupport::VERSION::MINOR >= 2
16
+ require 'fast_underscore/acronym_underscore_regex'
17
+ else
18
+ require 'fast_underscore/acronym_regex'
21
19
  end
22
20
  end
23
21
  end
24
22
 
25
- module ActiveSupport
26
- module Inflector
27
- class << self
28
- prepend FastUnderscore::ActiveSupportHook
23
+ if defined?(ActiveSupport)
24
+ FastUnderscore.install
25
+ else
26
+ module ActiveSupport
27
+ module Inflector
28
+ class << self
29
+ prepend(
30
+ Module.new do
31
+ # Hooks into ActiveSupport::Inflector and waits for the #underscore
32
+ # method to be defined. When it is, it automatically redefines it.
33
+ # Using this `prepend` trick to attempt to be a good citizen in the
34
+ # case that someone else has already hooked into `method_added` on
35
+ # `Inflector`.
36
+ def method_added(method)
37
+ method == :underscore ? FastUnderscore.install : super
38
+ end
39
+ end
40
+ )
41
+ end
29
42
  end
30
43
  end
31
44
  end
@@ -23,6 +23,6 @@ module FastUnderscore
23
23
 
24
24
  class << ActiveSupport::Inflector
25
25
  alias as_underscore underscore
26
- prepend AcronymRegex
26
+ include AcronymRegex
27
27
  end
28
28
  end
@@ -18,6 +18,6 @@ module FastUnderscore
18
18
 
19
19
  class << ActiveSupport::Inflector
20
20
  alias as_underscore underscore
21
- prepend AcronymUnderscoreRegex
21
+ include AcronymUnderscoreRegex
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastUnderscore
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Deisz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-02 00:00:00.000000000 Z
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -122,9 +122,8 @@ files:
122
122
  - gemfiles/5.1.gemfile
123
123
  - gemfiles/5.2.gemfile
124
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
125
+ - lib/fast_underscore/acronym_regex.rb
126
+ - lib/fast_underscore/acronym_underscore_regex.rb
128
127
  - lib/fast_underscore/version.rb
129
128
  homepage: https://github.com/kddeisz/fast_underscore
130
129
  licenses:
@@ -1,13 +0,0 @@
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)