Skip to content

Commit c5abc1b

Browse files
sagebombdblock
authored andcommitted
Add #is_a? and #kind_of? to OutputBuilder to check its output object class, specify rack, json and active_support version for supporting old rubies (#232)
1 parent d65df18 commit c5abc1b

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* [#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).
55
* [#219](https://github.com/ruby-grape/grape-entity/pull/219): Fix: double pass options in serializable_hash - [@sbatykov](https://github.com/sbatykov).
66
* [#226](https://github.com/ruby-grape/grape-entity/pull/226): Add fetch method to fetch from opts_hash - [@alanjcfs](https://github.com/alanjcfs).
7+
* [#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).
78
* Your contribution here.
89

910
0.5.1 (2016-4-4)

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ end
1313

1414
group :development, :test do
1515
gem 'rake'
16-
gem 'json'
16+
gem 'json', '~> 1.8.3'
1717
gem 'rspec'
18+
gem 'rack', '~> 1.6.4'
1819
gem 'rack-test', '~> 0.6.2', require: 'rack/test'
1920
gem 'rubocop', '0.31.0'
2021
end

grape-entity.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
1414

1515
s.rubyforge_project = 'grape-entity'
1616

17-
s.add_runtime_dependency 'activesupport'
17+
s.add_runtime_dependency 'activesupport', '< 5'
1818
s.add_runtime_dependency 'multi_json', '>= 1.3.2'
1919

2020
s.add_development_dependency 'rake'

lib/grape_entity/exposure/nesting_exposure/output_builder.rb

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def add(exposure, result)
2525
end
2626
end
2727

28+
def kind_of?(klass)
29+
klass == output.class || super
30+
end
31+
alias_method :is_a?, :kind_of?
32+
2833
def __getobj__
2934
output
3035
end

spec/grape_entity/entity_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ class Parent < Person
905905

906906
representation = subject.represent(4.times.map { Object.new }, serializable: true)
907907
expect(representation).to be_kind_of(Grape::Entity::Exposure::NestingExposure::OutputBuilder)
908+
expect(representation).to be_kind_of(Hash)
908909
expect(representation).to have_key :my_items
909910
expect(representation[:my_items]).to be_kind_of Array
910911
expect(representation[:my_items].size).to be 4

0 commit comments

Comments
 (0)