opal-activesupport 0.3.0 → 0.3.1
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/.travis.yml +1 -0
- data/README.md +2 -1
- data/Rakefile +1 -0
- data/lib/opal/activesupport/version.rb +1 -1
- data/opal/active_support/core_ext/string.rb +10 -7
- data/opal/active_support/inflector/inflections.rb +29 -10
- data/test/core_ext/string_ext_test.rb +13 -14
- data/test/inflector_test_cases.rb +2 -2
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: ab212ff0639ad0d73aa14079bee64d887be2a76cda925d7b06f714f0c6dbca83
         | 
| 4 | 
            +
              data.tar.gz: 85681bc3a9c4baaf2e8ef296e7b78e0bed6c517e1d9799a86f446970dbb90a39
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c95184d0f80dfd759498b94be051c527eec9bd918d72f37e3fbe493df5fc8c417ce4a5659afa0d55208d3bec0be85ec7210efce55715d4440f6763941d285a28
         | 
| 7 | 
            +
              data.tar.gz: aa831820632011e8ff2f6879fc5a2d8073da35e96d2a904d73ffc9162089ad1ad2b1ddcef3e24ea5e2ac8fb80e28b8e2a6ef3b1c4540c50f5980632e7654e8b4
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,7 +1,8 @@ | |
| 1 1 | 
             
            # Opal: ActiveSupport
         | 
| 2 2 |  | 
| 3 | 
            +
            _@dhh [6:44 PM - Oct 23, 2012](https://twitter.com/dhh/status/260783823254601728):_
         | 
| 3 4 | 
             
            > @AstonJ But it's vanilla Ruby. It's not like you have ActiveSupport available, which somewhat defeats it for me.
         | 
| 4 | 
            -
             | 
| 5 | 
            +
             | 
| 5 6 |  | 
| 6 7 | 
             
            ## Installation
         | 
| 7 8 |  | 
    
        data/Rakefile
    CHANGED
    
    | @@ -5,6 +5,7 @@ require 'opal/minitest/rake_task' | |
| 5 5 | 
             
            # Opal::Minitest::RakeTask.new
         | 
| 6 6 |  | 
| 7 7 | 
             
            task :test do
         | 
| 8 | 
            +
              Opal::Config.arity_check_enabled = true
         | 
| 8 9 | 
             
              files = Dir['test/**/*_test.rb'].map {|f| "-r #{f.chomp('.rb').sub(/^test\//, '')}"}
         | 
| 9 10 | 
             
              sh "bundle exec ruby -r opal/minitest -S opal -Dwarning -Itest -Iopal #{files.join(' ')} -e puts"
         | 
| 10 11 | 
             
            end
         | 
| @@ -6,10 +6,11 @@ class String | |
| 6 6 | 
             
              end
         | 
| 7 7 |  | 
| 8 8 | 
             
              def dasherize
         | 
| 9 | 
            -
                `#{self}.replace(/[-_\s]+/g, '-')
         | 
| 9 | 
            +
                result = `#{self}.replace(/[-_\s]+/g, '-')
         | 
| 10 10 | 
             
                        .replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1-$2')
         | 
| 11 11 | 
             
                        .replace(/([a-z\d])([A-Z])/g, '$1-$2')
         | 
| 12 12 | 
             
                        .toLowerCase()`
         | 
| 13 | 
            +
                result
         | 
| 13 14 | 
             
              end
         | 
| 14 15 |  | 
| 15 16 | 
             
              def demodulize
         | 
| @@ -25,18 +26,20 @@ class String | |
| 25 26 | 
             
              end
         | 
| 26 27 |  | 
| 27 28 | 
             
              def underscore
         | 
| 28 | 
            -
                `#{self}.replace(/[-\s]+/g, '_')
         | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 29 | 
            +
                result = `#{self}.replace(/[-\s]+/g, '_')
         | 
| 30 | 
            +
                        .replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1_$2')
         | 
| 31 | 
            +
                        .replace(/([a-z\d])([A-Z])/g, '$1_$2')
         | 
| 32 | 
            +
                        .replace(/-/g, '_')
         | 
| 33 | 
            +
                        .toLowerCase()`
         | 
| 34 | 
            +
                result
         | 
| 33 35 | 
             
              end
         | 
| 34 36 |  | 
| 35 37 | 
             
              def camelize(first_letter = :upper)
         | 
| 36 | 
            -
                `#{underscore}.replace(/(^|_)([^_]+)/g, function(match, pre, word, index) {
         | 
| 38 | 
            +
                result = `#{underscore}.replace(/(^|_)([^_]+)/g, function(match, pre, word, index) {
         | 
| 37 39 | 
             
                  var capitalize = #{first_letter} === #{:upper} || index > 0;
         | 
| 38 40 | 
             
                  return capitalize ? word.substr(0,1).toUpperCase()+word.substr(1) : word;
         | 
| 39 41 | 
             
                })`
         | 
| 42 | 
            +
                result
         | 
| 40 43 | 
             
              end
         | 
| 41 44 | 
             
              alias_method :camelcase, :camelize
         | 
| 42 45 | 
             
            end
         | 
| @@ -4,7 +4,7 @@ module ActiveSupport | |
| 4 4 | 
             
              module Inflector
         | 
| 5 5 | 
             
                extend self
         | 
| 6 6 |  | 
| 7 | 
            -
                def inflections
         | 
| 7 | 
            +
                def inflections(lang = :en)
         | 
| 8 8 | 
             
                  if block_given?
         | 
| 9 9 | 
             
                    yield Inflections.instance
         | 
| 10 10 | 
             
                  else
         | 
| @@ -57,15 +57,9 @@ module ActiveSupport | |
| 57 57 | 
             
                  if inflections.uncountables.include?(result.downcase)
         | 
| 58 58 | 
             
                    result
         | 
| 59 59 | 
             
                  else
         | 
| 60 | 
            -
                    rules. | 
| 61 | 
            -
                       | 
| 62 | 
            -
                      unless changed == result
         | 
| 63 | 
            -
                        result = changed
         | 
| 64 | 
            -
                        break
         | 
| 65 | 
            -
                      end
         | 
| 60 | 
            +
                    rules.detect do |rule, replacement|
         | 
| 61 | 
            +
                      break result.sub(rule, replacement) if result.index(rule)
         | 
| 66 62 | 
             
                    end
         | 
| 67 | 
            -
             | 
| 68 | 
            -
                    result
         | 
| 69 63 | 
             
                  end
         | 
| 70 64 | 
             
                end
         | 
| 71 65 |  | 
| @@ -92,8 +86,33 @@ module ActiveSupport | |
| 92 86 | 
             
                    words.each { |w| @uncountables << w.downcase }
         | 
| 93 87 | 
             
                  end
         | 
| 94 88 |  | 
| 95 | 
            -
                  def irregular()
         | 
| 89 | 
            +
                  def irregular(singular, plural)
         | 
| 90 | 
            +
                    @uncountables.delete(singular)
         | 
| 91 | 
            +
                    @uncountables.delete(plural)
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                    s0 = singular[0]
         | 
| 94 | 
            +
                    srest = singular[1..-1]
         | 
| 96 95 |  | 
| 96 | 
            +
                    p0 = plural[0]
         | 
| 97 | 
            +
                    prest = plural[1..-1]
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                    if s0.upcase == p0.upcase
         | 
| 100 | 
            +
                      plural(/(#{s0})#{srest}$/i, '\1' + prest)
         | 
| 101 | 
            +
                      plural(/(#{p0})#{prest}$/i, '\1' + prest)
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                      singular(/(#{s0})#{srest}$/i, '\1' + srest)
         | 
| 104 | 
            +
                      singular(/(#{p0})#{prest}$/i, '\1' + srest)
         | 
| 105 | 
            +
                    else
         | 
| 106 | 
            +
                      plural(/#{s0.upcase}(?i)#{srest}$/,   p0.upcase   + prest)
         | 
| 107 | 
            +
                      plural(/#{s0.downcase}(?i)#{srest}$/, p0.downcase + prest)
         | 
| 108 | 
            +
                      plural(/#{p0.upcase}(?i)#{prest}$/,   p0.upcase   + prest)
         | 
| 109 | 
            +
                      plural(/#{p0.downcase}(?i)#{prest}$/, p0.downcase + prest)
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                      singular(/#{s0.upcase}(?i)#{srest}$/,   s0.upcase   + srest)
         | 
| 112 | 
            +
                      singular(/#{s0.downcase}(?i)#{srest}$/, s0.downcase + srest)
         | 
| 113 | 
            +
                      singular(/#{p0.upcase}(?i)#{prest}$/,   s0.upcase   + srest)
         | 
| 114 | 
            +
                      singular(/#{p0.downcase}(?i)#{prest}$/, s0.downcase + srest)
         | 
| 115 | 
            +
                    end
         | 
| 97 116 | 
             
                  end
         | 
| 98 117 | 
             
                end
         | 
| 99 118 | 
             
              end
         | 
| @@ -4,7 +4,6 @@ require 'abstract_unit' | |
| 4 4 | 
             
            require 'inflector_test_cases'
         | 
| 5 5 | 
             
            # require 'constantize_test_cases'
         | 
| 6 6 |  | 
| 7 | 
            -
            require 'active_support/inflector'
         | 
| 8 7 | 
             
            require 'active_support/core_ext/string'
         | 
| 9 8 | 
             
            require 'active_support/time'
         | 
| 10 9 | 
             
            # require 'active_support/core_ext/string/strip'
         | 
| @@ -52,19 +51,19 @@ class StringInflectionsTest < ActiveSupport::TestCase | |
| 52 51 | 
             
              #     baz
         | 
| 53 52 | 
             
              #   EOS
         | 
| 54 53 | 
             
              # end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
               | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
               | 
| 67 | 
            -
             | 
| 54 | 
            +
             | 
| 55 | 
            +
              def test_pluralize
         | 
| 56 | 
            +
                SingularToPlural.each do |singular, plural|
         | 
| 57 | 
            +
                  assert_equal(plural, singular.pluralize)
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                assert_equal("plurals", "plurals".pluralize)
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                assert_equal("blargles", "blargle".pluralize(0))
         | 
| 63 | 
            +
                # assert_equal("blargle", "blargle".pluralize(1))
         | 
| 64 | 
            +
                assert_equal("blargles", "blargle".pluralize(2))
         | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
             | 
| 68 67 | 
             
              # def test_singularize
         | 
| 69 68 | 
             
              #   SingularToPlural.each do |singular, plural|
         | 
| 70 69 | 
             
              #     assert_equal(singular, plural.singularize)
         | 
| @@ -14,7 +14,7 @@ module InflectorTestCases | |
| 14 14 | 
             
                "fish"        => "fish",
         | 
| 15 15 | 
             
                "jeans"       => "jeans",
         | 
| 16 16 | 
             
                "funky jeans" => "funky jeans",
         | 
| 17 | 
            -
                "my money"    => "my money",
         | 
| 17 | 
            +
                # "my money"    => "my money", <= multi-word uncountables not supported yet
         | 
| 18 18 |  | 
| 19 19 | 
             
                "category"    => "categories",
         | 
| 20 20 | 
             
                "query"       => "queries",
         | 
| @@ -105,7 +105,7 @@ module InflectorTestCases | |
| 105 105 | 
             
                "prize"       => "prizes",
         | 
| 106 106 | 
             
                "edge"        => "edges",
         | 
| 107 107 |  | 
| 108 | 
            -
                "cow"         => " | 
| 108 | 
            +
                "cow"         => "cows",
         | 
| 109 109 | 
             
                "database"    => "databases",
         | 
| 110 110 |  | 
| 111 111 | 
             
                # regression tests against improper inflection regexes
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: opal-activesupport
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Elia Schito
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2018-01-28 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: opal
         | 
| @@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 146 146 | 
             
                  version: '0'
         | 
| 147 147 | 
             
            requirements: []
         | 
| 148 148 | 
             
            rubyforge_project: 
         | 
| 149 | 
            -
            rubygems_version: 2.4 | 
| 149 | 
            +
            rubygems_version: 2.7.4
         | 
| 150 150 | 
             
            signing_key: 
         | 
| 151 151 | 
             
            specification_version: 4
         | 
| 152 152 | 
             
            summary: The port of the glorious ActiveSupport for Opal
         |