fast_underscore 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
 - data/Gemfile.lock +1 -1
 - data/README.md +12 -1
 - data/bin/console +1 -0
 - data/lib/fast_underscore.rb +8 -2
 - data/lib/fast_underscore/version.rb +1 -1
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 84633c6f2e1999fd6b93ee69f0d6a7ea14f24f44
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7144cd7352002a733c739d4cca97f9f187ea6c02
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 67c6c5a8b86fee5594a47b7bd84da9498cf141d809e24539758deb7eb6e62e6462f63109d98bca10a0e2885bd89ee7728f601896ba21930eefb6732d5afa7c0c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 44a54f7a4dc34584b792bd9ba2e1b2adb11891f14e16d5ef2e0207853d23997d99de64e95dfe62d03fdd2b3b9ff032776d2ee7e7bf37c3b974a7185e91764a85
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        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 
     | 
    
         | 
    
        data/bin/console
    CHANGED
    
    
    
        data/lib/fast_underscore.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
             
     | 
| 
      
 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( 
     | 
| 
      
 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
         
     | 
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 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. 
     | 
| 
      
 144 
     | 
    
         
            +
            rubygems_version: 2.6.13
         
     | 
| 
       145 
145 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       146 
146 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       147 
147 
     | 
    
         
             
            summary: Fast String#underscore implementation
         
     |