diff --git a/CHANGELOG.md b/CHANGELOG.md index 675e2373..13bba44f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [#215](https://github.com/ruby-grape/grape-entity/pull/217): Fix: `#delegate_attribute` no longer delegates to methods included with `Kernel` - [@maltoe](https://github.com/maltoe). * [#219](https://github.com/ruby-grape/grape-entity/pull/219): Fix: double pass options in serializable_hash - [@sbatykov](https://github.com/sbatykov). * [#226](https://github.com/ruby-grape/grape-entity/pull/226): Add fetch method to fetch from opts_hash - [@alanjcfs](https://github.com/alanjcfs). +* [#232](https://github.com/ruby-grape/grape-entity/pull/232): Add `#kind_of?` and `#is_a?` to `OutputBuilder` to get an exact class of an `output` object. [#213](https://github.com/ruby-grape/grape-entity/issues/213) - [@avyy](https://github.com/avyy). * Your contribution here. 0.5.1 (2016-4-4) diff --git a/Gemfile b/Gemfile index 24358d55..5dba8d81 100644 --- a/Gemfile +++ b/Gemfile @@ -13,8 +13,9 @@ end group :development, :test do gem 'rake' - gem 'json' + gem 'json', '~> 1.8.3' gem 'rspec' + gem 'rack', '~> 1.6.4' gem 'rack-test', '~> 0.6.2', require: 'rack/test' gem 'rubocop', '0.31.0' end diff --git a/grape-entity.gemspec b/grape-entity.gemspec index 2051e35a..507ef1b3 100644 --- a/grape-entity.gemspec +++ b/grape-entity.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.rubyforge_project = 'grape-entity' - s.add_runtime_dependency 'activesupport' + s.add_runtime_dependency 'activesupport', '< 5' s.add_runtime_dependency 'multi_json', '>= 1.3.2' s.add_development_dependency 'rake' diff --git a/lib/grape_entity/exposure/nesting_exposure/output_builder.rb b/lib/grape_entity/exposure/nesting_exposure/output_builder.rb index 00647597..5fc4a63b 100644 --- a/lib/grape_entity/exposure/nesting_exposure/output_builder.rb +++ b/lib/grape_entity/exposure/nesting_exposure/output_builder.rb @@ -25,6 +25,11 @@ def add(exposure, result) end end + def kind_of?(klass) + klass == output.class || super + end + alias_method :is_a?, :kind_of? + def __getobj__ output end diff --git a/spec/grape_entity/entity_spec.rb b/spec/grape_entity/entity_spec.rb index c0daa476..b35c8bf6 100644 --- a/spec/grape_entity/entity_spec.rb +++ b/spec/grape_entity/entity_spec.rb @@ -905,6 +905,7 @@ class Parent < Person representation = subject.represent(4.times.map { Object.new }, serializable: true) expect(representation).to be_kind_of(Grape::Entity::Exposure::NestingExposure::OutputBuilder) + expect(representation).to be_kind_of(Hash) expect(representation).to have_key :my_items expect(representation[:my_items]).to be_kind_of Array expect(representation[:my_items].size).to be 4