diff options
-rw-r--r-- | .github/workflows/main.yml | 98 | ||||
-rw-r--r-- | .travis.yml | 34 | ||||
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | lib/hashie/extensions/dash/property_translation.rb | 7 | ||||
-rw-r--r-- | lib/hashie/extensions/indifferent_access.rb | 7 | ||||
-rw-r--r-- | lib/hashie/mash.rb | 8 | ||||
-rw-r--r-- | spec/hashie/extensions/indifferent_access_spec.rb | 12 | ||||
-rw-r--r-- | spec/hashie/mash_spec.rb | 13 | ||||
-rw-r--r-- | spec/hashie/trash_spec.rb | 17 | ||||
-rw-r--r-- | spec/integration/elasticsearch/Gemfile | 3 | ||||
-rw-r--r-- | spec/integration/omniauth-oauth2/Gemfile | 4 | ||||
-rw-r--r-- | spec/integration/omniauth/Gemfile | 4 |
14 files changed, 169 insertions, 48 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..e57056b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,98 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + danger: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7 + bundler-cache: true + - uses: MeilCli/danger-action@v5 + with: + danger_file: Dangerfile + danger_id: danger-pr + install_path: vendor/bundle + plugins_file: Gemfile + env: + DANGER_GITHUB_API_TOKEN: ${{ secrets.github_token }} + + integration-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: 2.7 + - name: Run integration tests + run: | + for dir in spec/integration/*; do + echo "testing $dir integration" + BUNDLE_GEMFILE=$dir/Gemfile bundle install --jobs 4 --retry 3 + BUNDLE_GEMFILE=$dir/Gemfile bundle exec rspec $dir + done + + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: + - 2.7 + - 2.6 + - 2.5 + - 2.4 + - 2.3 + - 2.2 + - 2.1 + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: ${{ matrix.ruby }} + - name: Install dependencies + run: bundle install --jobs 4 --retry 3 + - name: Run tests + run: bundle exec rake + + test-jruby: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: + - macos + - ubuntu + jruby: + - jruby + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: ${{ matrix.jruby }} + - name: Install dependencies + env: + JRUBY_OPTS: --debug + run: bundle install --jobs 4 --retry 3 + - name: Run tests + env: + JRUBY_OPTS: --debug + run: bundle exec rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 49230a1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: ruby -cache: bundler - -rvm: - - 2.6 - - 2.5 - - 2.4 - - 2.3 - - 2.2 - - 2.1 - - ruby-head - - jruby-9.2.11.1 - - jruby-head - - truffleruby - -matrix: - fast_finish: true - include: - - rvm: 2.7 - name: "Ruby: 2.7 (with Danger and Code Climate)" - before_script: - - bundle exec danger - after_script: - - bundle exec codeclimate-test-reporter - - rvm: 2.7 - name: "Integration Tests" - install: - - for dir in spec/integration/*; do BUNDLE_GEMFILE=$dir/Gemfile bundle; done - script: - - set -e ; for dir in spec/integration/*; do BUNDLE_GEMFILE=$dir/Gemfile bundle exec rspec $dir; done - allow_failures: - - rvm: ruby-head - - rvm: jruby-head - - rvm: truffleruby diff --git a/CHANGELOG.md b/CHANGELOG.md index c1bc0de..e54f31f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,9 +40,10 @@ Any violations of this scheme are considered to be bugs. * [#516](https://github.com/hashie/hashie/issues/516): Fixed `NoMethodError` raised when including `Hashie::Extensions::Mash::SymbolizeKeys` and `Hashie::Extensions::SymbolizeKeys` in mashes/hashes with non string or symbol keys - [@carolineartz](https://github.com/carolineartz). * [#531](https://github.com/hashie/hashie/pull/531): Fixed [slice doesn't work using symbols](https://github.com/hashie/hashie/issues/529) using hash with `IndifferentAccess` extension - [@gnomex](https://github.com/gnomex). -* [#533](https://github.com/hashie/hashie/pull/533): Fixed `NoMethodError: undefined method `to_json'` at `hashie/dash_spec` - [@gnomex](https://github.com/gnomex). +* [#533](https://github.com/hashie/hashie/pull/533): Fixed `NoMethodError: undefined method 'to_json'` at `hashie/dash_spec` - [@gnomex](https://github.com/gnomex). * [#535](https://github.com/hashie/hashie/pull/535): Restored the exporting of all properties as part of `Dash#to_h` and `Dash#to_hash` - [@michaelherold](https://github.com/michaelherold). * [#537](https://github.com/hashie/hashie/pull/537): Fixed inconsistencies with handling defaults in `Dash` with and without `IgnoreUnclared` mixed in - [@michaelherold](https://github.com/michaelherold). +* [#547](https://github.com/hashie/hashie/pull/547): Fixed issue where a source hash key can be used in translating multiple properties - [@danwa5](https://github.com/danwa5). * Your contribution here. ### Security @@ -55,6 +56,7 @@ Any violations of this scheme are considered to be bugs. ### Added +* [#545](https://github.com/hashie/hashie/pull/545): Add `Hashie::Mash#except` and `Hashie::Extensions::IndifferentAccess#except` when running under Ruby 3 to match newly added Ruby stdlib method - [@jackjennings](https://github.com/jackjennings). * [#499](https://github.com/hashie/hashie/pull/499): Add `Hashie::Extensions::Mash::PermissiveRespondTo` to make specific subclasses of Mash fully respond to messages for use with `SimpleDelegator` - [@michaelherold](https://github.com/michaelherold). ### Changed @@ -30,7 +30,7 @@ group :development do end group :test do - gem 'codeclimate-test-reporter', '~> 1.0', require: false gem 'danger-changelog', '~> 0.6.1', require: false gem 'danger-toc', '~> 0.2.0', require: false + gem 'simplecov' end @@ -2,9 +2,7 @@ [![Join the chat at https://gitter.im/hashie/hashie](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/hashie/hashie?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Gem Version](http://img.shields.io/gem/v/hashie.svg)](http://badge.fury.io/rb/hashie) -[![Build Status](http://img.shields.io/travis/hashie/hashie.svg)](https://travis-ci.org/hashie/hashie) -[![Test Coverage](https://api.codeclimate.com/v1/badges/7a0b42c8a22c945571fd/test_coverage)](https://codeclimate.com/github/hashie/hashie/test_coverage) -[![Maintainability](https://api.codeclimate.com/v1/badges/7a0b42c8a22c945571fd/maintainability)](https://codeclimate.com/github/hashie/hashie/maintainability) +[![Build Status](https://github.com/hashie/hashie/actions/workflows/main.yml/badge.svg)](https://github.com/hashie/hashie/actions/workflows/main.yml) [![eierlegende Wollmilchsau](./mascot.svg)](#mascot) Hashie is a growing collection of tools that extend Hashes and make them more useful. diff --git a/lib/hashie/extensions/dash/property_translation.rb b/lib/hashie/extensions/dash/property_translation.rb index 8149faa..69a2d71 100644 --- a/lib/hashie/extensions/dash/property_translation.rb +++ b/lib/hashie/extensions/dash/property_translation.rb @@ -153,7 +153,12 @@ module Hashie def []=(property, value) if self.class.translation_exists? property send("#{property}=", value) - super(property, value) if self.class.properties.include?(property) + + if self.class.transformation_exists? property + super property, self.class.transformed_property(property, value) + elsif self.class.properties.include?(property) + super(property, value) + end elsif self.class.transformation_exists? property super property, self.class.transformed_property(property, value) elsif property_exists? property diff --git a/lib/hashie/extensions/indifferent_access.rb b/lib/hashie/extensions/indifferent_access.rb index 2ff5f28..7702c14 100644 --- a/lib/hashie/extensions/indifferent_access.rb +++ b/lib/hashie/extensions/indifferent_access.rb @@ -167,6 +167,13 @@ module Hashie end end + with_minimum_ruby('3.0.0') do + def except(*keys) + string_keys = keys.map { |key| convert_key(key) } + super(*string_keys) + end + end + protected def hash_lacking_indifference?(other) diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index 6ab6e9a..d5cb308 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -62,7 +62,6 @@ module Hashie # mash.author # => <Mash> # class Mash < Hash - include Hashie::Extensions::PrettyInspect include Hashie::Extensions::RubyVersionCheck extend Hashie::Extensions::KeyConflictWarning @@ -352,6 +351,13 @@ module Hashie end end + with_minimum_ruby('3.0.0') do + def except(*keys) + string_keys = keys.map { |key| convert_key(key) } + self.class.new(super(*string_keys)) + end + end + protected def method_name_and_suffix(method_name) diff --git a/spec/hashie/extensions/indifferent_access_spec.rb b/spec/hashie/extensions/indifferent_access_spec.rb index 0aec787..27585f1 100644 --- a/spec/hashie/extensions/indifferent_access_spec.rb +++ b/spec/hashie/extensions/indifferent_access_spec.rb @@ -357,6 +357,18 @@ describe Hashie::Extensions::IndifferentAccess do end end end + + with_minimum_ruby('3.0.0') do + describe '#except' do + let(:h) { subject.build(foo: 'bar', baz: 'qux') } + + it 'indifferently excepts keys from the hash' do + sliced_h = { 'baz' => 'qux' } + expect(h.except('foo')).to eq sliced_h + expect(h.except(:foo)).to eq sliced_h + end + end + end end describe 'with merge initializer' do diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index 4731985..84a28ea 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -1097,4 +1097,17 @@ describe Hashie::Mash do end end end + + with_minimum_ruby('3.0.0') do + context '#except' do + subject(:mash) { described_class.new(a: 'A', b: 'B') } + it 'return a Hashie::Mash' do + expect(mash.except(:b)).to be_kind_of(described_class) + end + + it 'excludes keys' do + expect(mash.except(:b)).to eq('a' => 'A') + end + end + end end diff --git a/spec/hashie/trash_spec.rb b/spec/hashie/trash_spec.rb index 9998c8d..aaabe70 100644 --- a/spec/hashie/trash_spec.rb +++ b/spec/hashie/trash_spec.rb @@ -157,6 +157,23 @@ describe Hashie::Trash do end end + describe 'translating multiple properties from the same source hash key' do + class AnotherDataModel < Hashie::Trash + property :first_name, transform_with: ->(n) { n.upcase } + property :first_name_short, from: :first_name, transform_with: ->(n) { n[0, 3] } + end + + subject { AnotherDataModel.new(first_name: 'Cathy') } + + it 'translates the first key with the given lambda' do + expect(subject.first_name).to eq('CATHY') + end + + it 'translates the second key with the given lambda and the initial value of the first key' do + expect(subject.first_name_short).to eq('Cat') + end + end + describe 'uses with or transform_with interchangeably' do class TrashLambdaTestTransformWith < Hashie::Trash property :first_name, from: :firstName, transform_with: ->(value) { value.reverse } diff --git a/spec/integration/elasticsearch/Gemfile b/spec/integration/elasticsearch/Gemfile index 15dc04f..f2e62f3 100644 --- a/spec/integration/elasticsearch/Gemfile +++ b/spec/integration/elasticsearch/Gemfile @@ -1,6 +1,7 @@ source 'http://rubygems.org' -gem 'elasticsearch-model', '~> 7.0' +gem 'elasticsearch-api', '~> 7.0.0' +gem 'elasticsearch-model', '~> 7.0.0' gem 'hashie', path: '../../..' gem 'rake' gem 'rspec', '~> 3.5.0' diff --git a/spec/integration/omniauth-oauth2/Gemfile b/spec/integration/omniauth-oauth2/Gemfile index c081df6..91c3c2a 100644 --- a/spec/integration/omniauth-oauth2/Gemfile +++ b/spec/integration/omniauth-oauth2/Gemfile @@ -1,9 +1,7 @@ source 'http://rubygems.org' gem 'hashie', path: '../../..' -# Update omniauth to a pessimistic minor once omniauth releases changes in -# https://github.com/omniauth/omniauth/pull/977 -gem 'omniauth', git: 'https://github.com/omniauth/omniauth.git', branch: 'master' +gem 'omniauth' gem 'omniauth-oauth2', '~> 1.4.0' gem 'rails', '~> 5.0.1' gem 'rspec', '~> 3.5.0' diff --git a/spec/integration/omniauth/Gemfile b/spec/integration/omniauth/Gemfile index a29245b..af40e06 100644 --- a/spec/integration/omniauth/Gemfile +++ b/spec/integration/omniauth/Gemfile @@ -2,9 +2,7 @@ source 'http://rubygems.org' gem 'benchmark-ips' gem 'hashie', path: '../../..' -# Update omniauth to a pessimistic minor once https://github.com/omniauth/omniauth/issues/980 -# is resolved. -gem 'omniauth', git: 'https://github.com/omniauth/omniauth.git', branch: 'master' +gem 'omniauth' gem 'rack-test', '~> 0.6.3' gem 'rake' gem 'rspec', '~> 3.5.0' |