d12n 0.0.2
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 +7 -0
- data/README.md +10 -0
- data/lib/d12n.rb +17 -0
- data/lib/d12n/model_support.rb +21 -0
- data/lib/d12n/strategy/decimal_comma.rb +13 -0
- data/lib/d12n/strategy/decimal_point.rb +13 -0
- metadata +97 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: d7f5272c965cf1760fd4b29e164c5d29239a4bbc
         | 
| 4 | 
            +
              data.tar.gz: 6bdb55faf6a3398b75649e6c491a5d87866f21c6
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 99f69169106d94058ce9c73b85291217843168ade6f354f65b3a0decc2fb520f6a1f52d3fdabe57c8dd6d7bccf550ce1c518c45f2e88ece59ab863d6fb5f850c
         | 
| 7 | 
            +
              data.tar.gz: dd625aa1931466ddb5e968e09abfb406eea4be3bd066ff89a9ab221aa63f3463d1e7101d4bf57fb0d450c641c90690c50a368200d7bd436cc7efed29a1c1413d
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            # D12n
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            D12n (=delocalization) can be used to cast model attributes from localized format BigDecimal. This is done by adding an
         | 
| 4 | 
            +
            additional attribute to the model which keeps the original value the user is entering. This has the advantage that the
         | 
| 5 | 
            +
            original user input can be validated and rendered back to the user during validation errors.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## Usage
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ```ruby
         | 
| 10 | 
            +
            gem 'd12n'
         | 
    
        data/lib/d12n.rb
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            require 'active_support/configurable'
         | 
| 2 | 
            +
            require 'bigdecimal'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module D12n
         | 
| 5 | 
            +
              include ActiveSupport::Configurable
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              module Strategy
         | 
| 8 | 
            +
                autoload :DecimalPoint, 'd12n/strategy/decimal_point'
         | 
| 9 | 
            +
                autoload :DecimalComma, 'd12n/strategy/decimal_comma'
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              autoload :ModelSupport, 'd12n/model_support'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def self.strategy
         | 
| 15 | 
            +
                config.strategy || Strategy::DecimalPoint
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            module D12n
         | 
| 2 | 
            +
              module ModelSupport
         | 
| 3 | 
            +
                module ClassMethods
         | 
| 4 | 
            +
                  def d12n_attribute(*args)
         | 
| 5 | 
            +
                    options = args.extract_options!
         | 
| 6 | 
            +
                    prefix = options[:prefix] || 'local'
         | 
| 7 | 
            +
                    args.each do |name|
         | 
| 8 | 
            +
                      attr_reader "#{prefix}_#{name}"
         | 
| 9 | 
            +
                      define_method "#{prefix}_#{name}=" do |val|
         | 
| 10 | 
            +
                        instance_variable_set "@#{prefix}_#{name}", val
         | 
| 11 | 
            +
                        send "#{name}=", D12n.strategy.number_to_bigdecimal(val)
         | 
| 12 | 
            +
                      end
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def self.included(base)
         | 
| 18 | 
            +
                  base.extend ClassMethods
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,97 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: d12n
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - mkon
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2017-11-09 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: activesupport
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 5.0.2
         | 
| 20 | 
            +
                - - "<"
         | 
| 21 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            +
                    version: '6'
         | 
| 23 | 
            +
              type: :runtime
         | 
| 24 | 
            +
              prerelease: false
         | 
| 25 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - ">="
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: 5.0.2
         | 
| 30 | 
            +
                - - "<"
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: '6'
         | 
| 33 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 34 | 
            +
              name: rspec
         | 
| 35 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 36 | 
            +
                requirements:
         | 
| 37 | 
            +
                - - "~>"
         | 
| 38 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 39 | 
            +
                    version: '3'
         | 
| 40 | 
            +
              type: :development
         | 
| 41 | 
            +
              prerelease: false
         | 
| 42 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 43 | 
            +
                requirements:
         | 
| 44 | 
            +
                - - "~>"
         | 
| 45 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 46 | 
            +
                    version: '3'
         | 
| 47 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 48 | 
            +
              name: rubocop
         | 
| 49 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 50 | 
            +
                requirements:
         | 
| 51 | 
            +
                - - "~>"
         | 
| 52 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            +
                    version: '0'
         | 
| 54 | 
            +
              type: :development
         | 
| 55 | 
            +
              prerelease: false
         | 
| 56 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
                requirements:
         | 
| 58 | 
            +
                - - "~>"
         | 
| 59 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 60 | 
            +
                    version: '0'
         | 
| 61 | 
            +
            description: Delocalize numbers
         | 
| 62 | 
            +
            email:
         | 
| 63 | 
            +
            - konstantin@munteanu.de
         | 
| 64 | 
            +
            executables: []
         | 
| 65 | 
            +
            extensions: []
         | 
| 66 | 
            +
            extra_rdoc_files: []
         | 
| 67 | 
            +
            files:
         | 
| 68 | 
            +
            - README.md
         | 
| 69 | 
            +
            - lib/d12n.rb
         | 
| 70 | 
            +
            - lib/d12n/model_support.rb
         | 
| 71 | 
            +
            - lib/d12n/strategy/decimal_comma.rb
         | 
| 72 | 
            +
            - lib/d12n/strategy/decimal_point.rb
         | 
| 73 | 
            +
            homepage: https://github.com/mkon
         | 
| 74 | 
            +
            licenses:
         | 
| 75 | 
            +
            - MIT
         | 
| 76 | 
            +
            metadata: {}
         | 
| 77 | 
            +
            post_install_message: 
         | 
| 78 | 
            +
            rdoc_options: []
         | 
| 79 | 
            +
            require_paths:
         | 
| 80 | 
            +
            - lib
         | 
| 81 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 82 | 
            +
              requirements:
         | 
| 83 | 
            +
              - - ">="
         | 
| 84 | 
            +
                - !ruby/object:Gem::Version
         | 
| 85 | 
            +
                  version: '0'
         | 
| 86 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 87 | 
            +
              requirements:
         | 
| 88 | 
            +
              - - ">="
         | 
| 89 | 
            +
                - !ruby/object:Gem::Version
         | 
| 90 | 
            +
                  version: '0'
         | 
| 91 | 
            +
            requirements: []
         | 
| 92 | 
            +
            rubyforge_project: 
         | 
| 93 | 
            +
            rubygems_version: 2.6.11
         | 
| 94 | 
            +
            signing_key: 
         | 
| 95 | 
            +
            specification_version: 4
         | 
| 96 | 
            +
            summary: Delocalization
         | 
| 97 | 
            +
            test_files: []
         |