grape-entity 1.0.1 → 1.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 +4 -4
- data/.github/workflows/ci.yml +3 -3
- data/.rspec +1 -0
- data/.rubocop_todo.yml +5 -0
- data/CHANGELOG.md +6 -7
- data/README.md +5 -0
- data/bench/serializing.rb +2 -2
- data/grape-entity.gemspec +1 -3
- data/lib/grape_entity/entity.rb +50 -11
- data/lib/grape_entity/json.rb +12 -0
- data/lib/grape_entity/version.rb +1 -1
- data/spec/grape_entity/entity_spec.rb +96 -37
- data/spec/grape_entity/exposure/nesting_exposure/nested_exposures_spec.rb +0 -2
- data/spec/grape_entity/exposure/represent_exposure_spec.rb +0 -2
- data/spec/grape_entity/exposure_spec.rb +0 -2
- data/spec/grape_entity/hash_spec.rb +0 -2
- data/spec/grape_entity/json_spec.rb +7 -0
- data/spec/grape_entity/options_spec.rb +0 -2
- metadata +6 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8beeb296491f1be5721d415c0a3b9a3bfc5caeede002c8bc4a2e009fc83706f1
|
|
4
|
+
data.tar.gz: 5d219fab3a94ecae43c7f253682fc3d6640723ad27e4e75020b9cecc359ae7d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4063dd57bec2dd189ee05e492fc6a1d36dceb45be1e5c02f16749dba303557490494e874d8f302ae668e51b846035efb5e8e10977273127f57e05d175390cd3b
|
|
7
|
+
data.tar.gz: 06d176afda782549915c74f0085f641047e0077270e507725fbd1c1c9ad7f929b75362d54c73e20626e0643ef4c3c54de2f75cf1ed678d72ee868406deaa1226
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -15,7 +15,7 @@ jobs:
|
|
|
15
15
|
rubocop:
|
|
16
16
|
runs-on: ubuntu-latest
|
|
17
17
|
steps:
|
|
18
|
-
- uses: actions/checkout@
|
|
18
|
+
- uses: actions/checkout@v6
|
|
19
19
|
- uses: ruby/setup-ruby@v1
|
|
20
20
|
with:
|
|
21
21
|
ruby-version: '3.0'
|
|
@@ -28,10 +28,10 @@ jobs:
|
|
|
28
28
|
needs: ['rubocop']
|
|
29
29
|
strategy:
|
|
30
30
|
matrix:
|
|
31
|
-
ruby-version: ['3.0', '3.1', '3.2', '3.3', '
|
|
31
|
+
ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4']
|
|
32
32
|
steps:
|
|
33
33
|
- name: Check out branch
|
|
34
|
-
uses: actions/checkout@
|
|
34
|
+
uses: actions/checkout@v6
|
|
35
35
|
- name: Set up Ruby
|
|
36
36
|
uses: ruby/setup-ruby@v1
|
|
37
37
|
with:
|
data/.rspec
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -29,6 +29,11 @@ Gemspec/RequiredRubyVersion:
|
|
|
29
29
|
Exclude:
|
|
30
30
|
- 'grape-entity.gemspec'
|
|
31
31
|
|
|
32
|
+
# Offense count: 1
|
|
33
|
+
Style/OneClassPerFile:
|
|
34
|
+
Exclude:
|
|
35
|
+
- 'bench/serializing.rb'
|
|
36
|
+
|
|
32
37
|
# Offense count: 6
|
|
33
38
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
34
39
|
Lint/BooleanSymbol:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
### Next
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Your contribution here.
|
|
3
|
+
### 1.0.2 (2026-04-13)
|
|
6
4
|
|
|
7
5
|
#### Fixes
|
|
8
6
|
|
|
9
|
-
*
|
|
10
|
-
|
|
7
|
+
* [#394](https://github.com/ruby-grape/grape-entity/pull/394): Add `Entity.[]` for Grape >= 3.2 param type compatibility - [@numbata](https://github.com/numbata).
|
|
8
|
+
* [#388](https://github.com/ruby-grape/grape-entity/pull/388): Drop ruby-head from test matrix - [@numbata](https://github.com/numbata).
|
|
9
|
+
* [#384](https://github.com/ruby-grape/grape-entity/pull/384): Fix `inspect` to correctly handle `nil` values - [@fcce](https://github.com/fcce).
|
|
11
10
|
|
|
12
|
-
###
|
|
11
|
+
### 1.0.1 (2024-04-10)
|
|
13
12
|
|
|
14
13
|
#### Fixes
|
|
15
14
|
|
|
16
15
|
* [#381](https://github.com/ruby-grape/grape-entity/pull/381): Fix `expose_nil: false` when using a block - [@magni-](https://github.com/magni-).
|
|
17
16
|
|
|
18
17
|
|
|
19
|
-
###
|
|
18
|
+
### 1.0.0 (2023-02-16)
|
|
20
19
|
|
|
21
20
|
#### Fixes
|
|
22
21
|
|
data/README.md
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
- [Using Entities](#using-entities)
|
|
34
34
|
- [Entity Organization](#entity-organization)
|
|
35
35
|
- [Caveats](#caveats)
|
|
36
|
+
- [Preloading Associations](#preloading-associations)
|
|
36
37
|
- [Installation](#installation)
|
|
37
38
|
- [Testing with Entities](#testing-with-entities)
|
|
38
39
|
- [Project Resources](#project-resources)
|
|
@@ -674,6 +675,10 @@ end
|
|
|
674
675
|
|
|
675
676
|
Also note that an `ArgumentError` is raised when unknown options are passed to either `expose` or `with_options`.
|
|
676
677
|
|
|
678
|
+
### Preloading Associations
|
|
679
|
+
|
|
680
|
+
Use [Grape::Entity::Preloader](https://github.com/OuYangJinTing/grape-entity-preloader) to preload associations and callbacks and avoid N+1 operations.
|
|
681
|
+
|
|
677
682
|
## Installation
|
|
678
683
|
|
|
679
684
|
Add this line to your application's Gemfile:
|
data/bench/serializing.rb
CHANGED
|
@@ -35,7 +35,7 @@ module Models
|
|
|
35
35
|
attr_accessor :tenure
|
|
36
36
|
|
|
37
37
|
def initialize(opts = {})
|
|
38
|
-
super
|
|
38
|
+
super
|
|
39
39
|
@tenure = opts[:tenure]
|
|
40
40
|
end
|
|
41
41
|
end
|
|
@@ -44,7 +44,7 @@ module Models
|
|
|
44
44
|
attr_reader :grade
|
|
45
45
|
|
|
46
46
|
def initialize(opts = {})
|
|
47
|
-
super
|
|
47
|
+
super
|
|
48
48
|
@grade = opts[:grade]
|
|
49
49
|
end
|
|
50
50
|
end
|
data/grape-entity.gemspec
CHANGED
|
@@ -16,9 +16,7 @@ Gem::Specification.new do |s|
|
|
|
16
16
|
|
|
17
17
|
s.required_ruby_version = '>= 3.0'
|
|
18
18
|
|
|
19
|
-
s.
|
|
20
|
-
# FIXME: remove dependecy
|
|
21
|
-
s.add_runtime_dependency 'multi_json', '>= 1.3.2'
|
|
19
|
+
s.add_dependency 'activesupport', '>= 3.0.0'
|
|
22
20
|
|
|
23
21
|
s.files = `git ls-files`.split("\n")
|
|
24
22
|
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
data/lib/grape_entity/entity.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require '
|
|
3
|
+
require 'grape_entity/json'
|
|
4
4
|
|
|
5
5
|
module Grape
|
|
6
6
|
# An Entity is a lightweight structure that allows you to easily
|
|
@@ -129,6 +129,12 @@ module Grape
|
|
|
129
129
|
def delegation_opts
|
|
130
130
|
@delegation_opts ||= { hash_access: hash_access }
|
|
131
131
|
end
|
|
132
|
+
|
|
133
|
+
# Satisfies the respond_to?(:[]) check in Grape::DryTypes (>= 3.2)
|
|
134
|
+
# so Entity subclasses can be used as param types.
|
|
135
|
+
def [](val)
|
|
136
|
+
val
|
|
137
|
+
end
|
|
132
138
|
end
|
|
133
139
|
|
|
134
140
|
@formatters = {}
|
|
@@ -472,8 +478,13 @@ module Grape
|
|
|
472
478
|
|
|
473
479
|
# Prevent default serialization of :options or :delegator.
|
|
474
480
|
def inspect
|
|
475
|
-
|
|
476
|
-
|
|
481
|
+
object = serializable_hash
|
|
482
|
+
if object.nil?
|
|
483
|
+
"#<#{self.class.name}:#{object_id} nil>"
|
|
484
|
+
else
|
|
485
|
+
fields = object.map { |k, v| "#{k}=#{v}" }
|
|
486
|
+
"#<#{self.class.name}:#{object_id} #{fields.join(' ')}>"
|
|
487
|
+
end
|
|
477
488
|
end
|
|
478
489
|
|
|
479
490
|
def initialize(object, options = {})
|
|
@@ -514,19 +525,47 @@ module Grape
|
|
|
514
525
|
end
|
|
515
526
|
|
|
516
527
|
def exec_with_object(options, &block)
|
|
517
|
-
if block
|
|
528
|
+
arity = if symbol_to_proc_wrapper?(block)
|
|
529
|
+
ensure_block_arity!(block)
|
|
530
|
+
else
|
|
531
|
+
block.arity
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
if arity.zero?
|
|
518
535
|
instance_exec(object, &block)
|
|
519
536
|
else
|
|
520
537
|
instance_exec(object, options, &block)
|
|
521
538
|
end
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
def ensure_block_arity!(block)
|
|
542
|
+
# MRI currently always includes "( &:foo )" for symbol-to-proc wrappers.
|
|
543
|
+
# If this format changes in a new Ruby version, this logic must be updated.
|
|
544
|
+
origin_method_name = block.to_s.scan(/(?<=\(&:)[^)]+(?=\))/).first&.to_sym
|
|
545
|
+
return 0 unless origin_method_name
|
|
546
|
+
|
|
547
|
+
unless object.respond_to?(origin_method_name, true)
|
|
548
|
+
raise ArgumentError, <<~MSG
|
|
549
|
+
Cannot use `&:#{origin_method_name}` because that method is not defined in the object.
|
|
550
|
+
MSG
|
|
527
551
|
end
|
|
528
552
|
|
|
529
|
-
|
|
553
|
+
arity = object.method(origin_method_name).arity
|
|
554
|
+
return 0 if arity.zero?
|
|
555
|
+
|
|
556
|
+
raise ArgumentError, <<~MSG
|
|
557
|
+
Cannot use `&:#{origin_method_name}` because that method expects #{arity} argument#{'s' if arity != 1}.
|
|
558
|
+
Symbol‐to‐proc shorthand only works for zero‐argument methods.
|
|
559
|
+
MSG
|
|
560
|
+
end
|
|
561
|
+
|
|
562
|
+
def symbol_to_proc_wrapper?(block)
|
|
563
|
+
params = block.parameters
|
|
564
|
+
|
|
565
|
+
return false unless block.lambda? && block.source_location.nil?
|
|
566
|
+
return false unless params.size >= 2
|
|
567
|
+
|
|
568
|
+
params[0].first == :req && params[1].first == :rest
|
|
530
569
|
end
|
|
531
570
|
|
|
532
571
|
def exec_with_attribute(attribute, &block)
|
|
@@ -558,7 +597,7 @@ module Grape
|
|
|
558
597
|
|
|
559
598
|
def to_json(options = {})
|
|
560
599
|
options = options.to_h if options&.respond_to?(:to_h)
|
|
561
|
-
|
|
600
|
+
Grape::Entity::Json.dump(serializable_hash(options))
|
|
562
601
|
end
|
|
563
602
|
|
|
564
603
|
def to_xml(options = {})
|
data/lib/grape_entity/version.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'spec_helper'
|
|
4
3
|
require 'ostruct'
|
|
5
4
|
|
|
6
5
|
describe Grape::Entity do
|
|
@@ -394,6 +393,14 @@ describe Grape::Entity do
|
|
|
394
393
|
'result'
|
|
395
394
|
end
|
|
396
395
|
|
|
396
|
+
def method_with_one_arg(_object)
|
|
397
|
+
'result'
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
def method_with_multiple_args(_object, _options)
|
|
401
|
+
'result'
|
|
402
|
+
end
|
|
403
|
+
|
|
397
404
|
def raises_argument_error
|
|
398
405
|
raise ArgumentError, 'something different'
|
|
399
406
|
end
|
|
@@ -424,28 +431,49 @@ describe Grape::Entity do
|
|
|
424
431
|
end
|
|
425
432
|
|
|
426
433
|
context 'with block passed in via &' do
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
subject.expose :method_without_args, as: :that_method_without_args_again
|
|
431
|
-
|
|
432
|
-
object = SomeObject.new
|
|
433
|
-
expect do
|
|
434
|
-
subject.represent(object).value_for(:that_method_without_args)
|
|
435
|
-
end.to raise_error Grape::Entity::Deprecated
|
|
436
|
-
|
|
437
|
-
value2 = subject.represent(object).value_for(:that_method_without_args_again)
|
|
438
|
-
expect(value2).to eq('result')
|
|
439
|
-
end
|
|
440
|
-
else
|
|
441
|
-
specify do
|
|
442
|
-
subject.expose :that_method_without_args_again, &:method_without_args
|
|
434
|
+
specify do
|
|
435
|
+
subject.expose :that_method_without_args, &:method_without_args
|
|
436
|
+
subject.expose :method_without_args, as: :that_method_without_args_again
|
|
443
437
|
|
|
444
|
-
|
|
438
|
+
object = SomeObject.new
|
|
445
439
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
440
|
+
value = subject.represent(object).value_for(:method_without_args)
|
|
441
|
+
expect(value).to be_nil
|
|
442
|
+
|
|
443
|
+
value = subject.represent(object).value_for(:that_method_without_args)
|
|
444
|
+
expect(value).to eq('result')
|
|
445
|
+
|
|
446
|
+
value = subject.represent(object).value_for(:that_method_without_args_again)
|
|
447
|
+
expect(value).to eq('result')
|
|
448
|
+
end
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
context 'with block passed in via &' do
|
|
452
|
+
specify do
|
|
453
|
+
subject.expose :that_method_with_one_arg, &:method_with_one_arg
|
|
454
|
+
subject.expose :that_method_with_multple_args, &:method_with_multiple_args
|
|
455
|
+
|
|
456
|
+
object = SomeObject.new
|
|
457
|
+
|
|
458
|
+
expect do
|
|
459
|
+
subject.represent(object).value_for(:that_method_with_one_arg)
|
|
460
|
+
end.to raise_error ArgumentError, match(/method expects 1 argument/)
|
|
461
|
+
|
|
462
|
+
expect do
|
|
463
|
+
subject.represent(object).value_for(:that_method_with_multple_args)
|
|
464
|
+
end.to raise_error ArgumentError, match(/method expects 2 arguments/)
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
context 'with symbol-to-proc passed in via &' do
|
|
469
|
+
specify do
|
|
470
|
+
subject.expose :that_undefined_method, &:unknown_method
|
|
471
|
+
|
|
472
|
+
object = SomeObject.new
|
|
473
|
+
|
|
474
|
+
expect do
|
|
475
|
+
subject.represent(object).value_for(:that_undefined_method)
|
|
476
|
+
end.to raise_error ArgumentError, match(/method is not defined in the object/)
|
|
449
477
|
end
|
|
450
478
|
end
|
|
451
479
|
end
|
|
@@ -982,6 +1010,22 @@ describe Grape::Entity do
|
|
|
982
1010
|
end
|
|
983
1011
|
end
|
|
984
1012
|
|
|
1013
|
+
describe '.[]' do
|
|
1014
|
+
it 'returns the input unchanged' do
|
|
1015
|
+
hash = { name: 'Test' }
|
|
1016
|
+
expect(subject[hash]).to eq(hash)
|
|
1017
|
+
end
|
|
1018
|
+
|
|
1019
|
+
it 'returns nil unchanged' do
|
|
1020
|
+
expect(subject[nil]).to be_nil
|
|
1021
|
+
end
|
|
1022
|
+
|
|
1023
|
+
it 'is inherited by subclasses' do
|
|
1024
|
+
subclass = Class.new(subject)
|
|
1025
|
+
expect(subclass[{ id: 1 }]).to eq(id: 1)
|
|
1026
|
+
end
|
|
1027
|
+
end
|
|
1028
|
+
|
|
985
1029
|
describe '.represent' do
|
|
986
1030
|
it 'returns a single entity if called with one object' do
|
|
987
1031
|
expect(subject.represent(Object.new)).to be_kind_of(subject)
|
|
@@ -995,7 +1039,7 @@ describe Grape::Entity do
|
|
|
995
1039
|
representation = subject.represent(Array.new(4) { Object.new })
|
|
996
1040
|
expect(representation).to be_kind_of Array
|
|
997
1041
|
expect(representation.size).to eq(4)
|
|
998
|
-
expect(representation.
|
|
1042
|
+
expect(representation.grep_v(subject)).to be_empty
|
|
999
1043
|
end
|
|
1000
1044
|
|
|
1001
1045
|
it 'adds the collection: true option if called with a collection' do
|
|
@@ -1341,7 +1385,7 @@ describe Grape::Entity do
|
|
|
1341
1385
|
expect(representation).to have_key 'things'
|
|
1342
1386
|
expect(representation['things']).to be_kind_of Array
|
|
1343
1387
|
expect(representation['things'].size).to eq 4
|
|
1344
|
-
expect(representation['things'].
|
|
1388
|
+
expect(representation['things'].grep_v(subject)).to be_empty
|
|
1345
1389
|
end
|
|
1346
1390
|
end
|
|
1347
1391
|
|
|
@@ -1350,7 +1394,7 @@ describe Grape::Entity do
|
|
|
1350
1394
|
representation = subject.represent(Array.new(4) { Object.new }, root: false)
|
|
1351
1395
|
expect(representation).to be_kind_of Array
|
|
1352
1396
|
expect(representation.size).to eq 4
|
|
1353
|
-
expect(representation.
|
|
1397
|
+
expect(representation.grep_v(subject)).to be_empty
|
|
1354
1398
|
end
|
|
1355
1399
|
it 'can use a different name' do
|
|
1356
1400
|
representation = subject.represent(Array.new(4) { Object.new }, root: 'others')
|
|
@@ -1358,7 +1402,7 @@ describe Grape::Entity do
|
|
|
1358
1402
|
expect(representation).to have_key 'others'
|
|
1359
1403
|
expect(representation['others']).to be_kind_of Array
|
|
1360
1404
|
expect(representation['others'].size).to eq 4
|
|
1361
|
-
expect(representation['others'].
|
|
1405
|
+
expect(representation['others'].grep_v(subject)).to be_empty
|
|
1362
1406
|
end
|
|
1363
1407
|
end
|
|
1364
1408
|
end
|
|
@@ -1382,7 +1426,7 @@ describe Grape::Entity do
|
|
|
1382
1426
|
representation = subject.represent(Array.new(4) { Object.new })
|
|
1383
1427
|
expect(representation).to be_kind_of Array
|
|
1384
1428
|
expect(representation.size).to eq 4
|
|
1385
|
-
expect(representation.
|
|
1429
|
+
expect(representation.grep_v(subject)).to be_empty
|
|
1386
1430
|
end
|
|
1387
1431
|
end
|
|
1388
1432
|
end
|
|
@@ -1405,7 +1449,7 @@ describe Grape::Entity do
|
|
|
1405
1449
|
expect(representation).to have_key('things')
|
|
1406
1450
|
expect(representation['things']).to be_kind_of Array
|
|
1407
1451
|
expect(representation['things'].size).to eq 4
|
|
1408
|
-
expect(representation['things'].
|
|
1452
|
+
expect(representation['things'].grep_v(subject)).to be_empty
|
|
1409
1453
|
end
|
|
1410
1454
|
end
|
|
1411
1455
|
end
|
|
@@ -1430,7 +1474,7 @@ describe Grape::Entity do
|
|
|
1430
1474
|
expect(representation).to have_key('things')
|
|
1431
1475
|
expect(representation['things']).to be_kind_of Array
|
|
1432
1476
|
expect(representation['things'].size).to eq 4
|
|
1433
|
-
expect(representation['things'].
|
|
1477
|
+
expect(representation['things'].grep_v(child_class)).to be_empty
|
|
1434
1478
|
end
|
|
1435
1479
|
end
|
|
1436
1480
|
end
|
|
@@ -1755,6 +1799,16 @@ describe Grape::Entity do
|
|
|
1755
1799
|
end
|
|
1756
1800
|
end
|
|
1757
1801
|
|
|
1802
|
+
describe '#to_json' do
|
|
1803
|
+
before do
|
|
1804
|
+
fresh_class.expose :name
|
|
1805
|
+
end
|
|
1806
|
+
|
|
1807
|
+
it 'returns a json' do
|
|
1808
|
+
expect(fresh_class.new(model).to_json).to eq(JSON.generate(attributes.slice(:name)))
|
|
1809
|
+
end
|
|
1810
|
+
end
|
|
1811
|
+
|
|
1758
1812
|
describe '#inspect' do
|
|
1759
1813
|
before do
|
|
1760
1814
|
fresh_class.class_eval do
|
|
@@ -1769,6 +1823,11 @@ describe Grape::Entity do
|
|
|
1769
1823
|
expect(data).to_not include '@options'
|
|
1770
1824
|
expect(data).to_not include '@delegator'
|
|
1771
1825
|
end
|
|
1826
|
+
|
|
1827
|
+
it 'returns a nil string when subject is nil' do
|
|
1828
|
+
data = subject.class.new(nil).inspect
|
|
1829
|
+
expect(data).to include 'nil'
|
|
1830
|
+
end
|
|
1772
1831
|
end
|
|
1773
1832
|
|
|
1774
1833
|
describe '#value_for' do
|
|
@@ -1796,7 +1855,7 @@ describe Grape::Entity do
|
|
|
1796
1855
|
|
|
1797
1856
|
it 'instantiates a representation if that is called for' do
|
|
1798
1857
|
rep = subject.value_for(:friends)
|
|
1799
|
-
expect(rep.
|
|
1858
|
+
expect(rep.grep_v(fresh_class)).to be_empty
|
|
1800
1859
|
expect(rep.first.serializable_hash[:name]).to eq 'Friend 1'
|
|
1801
1860
|
expect(rep.last.serializable_hash[:name]).to eq 'Friend 2'
|
|
1802
1861
|
end
|
|
@@ -1818,7 +1877,7 @@ describe Grape::Entity do
|
|
|
1818
1877
|
|
|
1819
1878
|
rep = subject.value_for(:friends)
|
|
1820
1879
|
expect(rep).to be_kind_of Array
|
|
1821
|
-
expect(rep.
|
|
1880
|
+
expect(rep.grep_v(EntitySpec::FriendEntity)).to be_empty
|
|
1822
1881
|
expect(rep.first.serializable_hash[:name]).to eq 'Friend 1'
|
|
1823
1882
|
expect(rep.last.serializable_hash[:name]).to eq 'Friend 2'
|
|
1824
1883
|
end
|
|
@@ -1839,7 +1898,7 @@ describe Grape::Entity do
|
|
|
1839
1898
|
|
|
1840
1899
|
rep = subject.value_for(:custom_friends)
|
|
1841
1900
|
expect(rep).to be_kind_of Array
|
|
1842
|
-
expect(rep.
|
|
1901
|
+
expect(rep.grep_v(EntitySpec::FriendEntity)).to be_empty
|
|
1843
1902
|
expect(rep.first.serializable_hash).to eq(name: 'Friend 1', email: 'friend1@example.com')
|
|
1844
1903
|
expect(rep.last.serializable_hash).to eq(name: 'Friend 2', email: 'friend2@example.com')
|
|
1845
1904
|
end
|
|
@@ -1897,7 +1956,7 @@ describe Grape::Entity do
|
|
|
1897
1956
|
|
|
1898
1957
|
rep = subject.value_for(:characteristics)
|
|
1899
1958
|
expect(rep).to be_kind_of Array
|
|
1900
|
-
expect(rep.
|
|
1959
|
+
expect(rep.grep_v(EntitySpec::CharacteristicsEntity)).to be_empty
|
|
1901
1960
|
expect(rep.first.serializable_hash[:key]).to eq 'hair_color'
|
|
1902
1961
|
expect(rep.first.serializable_hash[:value]).to eq 'brown'
|
|
1903
1962
|
end
|
|
@@ -1917,13 +1976,13 @@ describe Grape::Entity do
|
|
|
1917
1976
|
|
|
1918
1977
|
rep = subject.value_for(:friends)
|
|
1919
1978
|
expect(rep).to be_kind_of Array
|
|
1920
|
-
expect(rep.
|
|
1979
|
+
expect(rep.grep_v(EntitySpec::FriendEntity)).to be_empty
|
|
1921
1980
|
expect(rep.first.serializable_hash[:email]).to be_nil
|
|
1922
1981
|
expect(rep.last.serializable_hash[:email]).to be_nil
|
|
1923
1982
|
|
|
1924
1983
|
rep = subject.value_for(:friends, Grape::Entity::Options.new(user_type: :admin))
|
|
1925
1984
|
expect(rep).to be_kind_of Array
|
|
1926
|
-
expect(rep.
|
|
1985
|
+
expect(rep.grep_v(EntitySpec::FriendEntity)).to be_empty
|
|
1927
1986
|
expect(rep.first.serializable_hash[:email]).to eq 'friend1@example.com'
|
|
1928
1987
|
expect(rep.last.serializable_hash[:email]).to eq 'friend2@example.com'
|
|
1929
1988
|
end
|
|
@@ -1943,7 +2002,7 @@ describe Grape::Entity do
|
|
|
1943
2002
|
|
|
1944
2003
|
rep = subject.value_for(:friends, Grape::Entity::Options.new(collection: false))
|
|
1945
2004
|
expect(rep).to be_kind_of Array
|
|
1946
|
-
expect(rep.
|
|
2005
|
+
expect(rep.grep_v(EntitySpec::FriendEntity)).to be_empty
|
|
1947
2006
|
expect(rep.first.serializable_hash[:email]).to eq 'friend1@example.com'
|
|
1948
2007
|
expect(rep.last.serializable_hash[:email]).to eq 'friend2@example.com'
|
|
1949
2008
|
end
|
|
@@ -2022,7 +2081,7 @@ describe Grape::Entity do
|
|
|
2022
2081
|
rep = subject.value_for(:friends)
|
|
2023
2082
|
expect(rep).to be_kind_of Array
|
|
2024
2083
|
expect(rep.size).to eq 2
|
|
2025
|
-
expect(rep.all?
|
|
2084
|
+
expect(rep.all?(EntitySpec::UserEntity)).to be true
|
|
2026
2085
|
end
|
|
2027
2086
|
|
|
2028
2087
|
it 'class' do
|
|
@@ -2033,7 +2092,7 @@ describe Grape::Entity do
|
|
|
2033
2092
|
rep = subject.value_for(:friends)
|
|
2034
2093
|
expect(rep).to be_kind_of Array
|
|
2035
2094
|
expect(rep.size).to eq 2
|
|
2036
|
-
expect(rep.all?
|
|
2095
|
+
expect(rep.all?(EntitySpec::UserEntity)).to be true
|
|
2037
2096
|
end
|
|
2038
2097
|
end
|
|
2039
2098
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: grape-entity
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- LeFnord
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2026-04-13 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -25,20 +25,6 @@ dependencies:
|
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
27
|
version: 3.0.0
|
|
28
|
-
- !ruby/object:Gem::Dependency
|
|
29
|
-
name: multi_json
|
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
|
31
|
-
requirements:
|
|
32
|
-
- - ">="
|
|
33
|
-
- !ruby/object:Gem::Version
|
|
34
|
-
version: 1.3.2
|
|
35
|
-
type: :runtime
|
|
36
|
-
prerelease: false
|
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
-
requirements:
|
|
39
|
-
- - ">="
|
|
40
|
-
- !ruby/object:Gem::Version
|
|
41
|
-
version: 1.3.2
|
|
42
28
|
description: Extracted from Grape, A Ruby framework for rapid API development with
|
|
43
29
|
great conventions.
|
|
44
30
|
email:
|
|
@@ -92,6 +78,7 @@ files:
|
|
|
92
78
|
- lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb
|
|
93
79
|
- lib/grape_entity/exposure/nesting_exposure/output_builder.rb
|
|
94
80
|
- lib/grape_entity/exposure/represent_exposure.rb
|
|
81
|
+
- lib/grape_entity/json.rb
|
|
95
82
|
- lib/grape_entity/options.rb
|
|
96
83
|
- lib/grape_entity/version.rb
|
|
97
84
|
- spec/grape_entity/entity_spec.rb
|
|
@@ -99,6 +86,7 @@ files:
|
|
|
99
86
|
- spec/grape_entity/exposure/represent_exposure_spec.rb
|
|
100
87
|
- spec/grape_entity/exposure_spec.rb
|
|
101
88
|
- spec/grape_entity/hash_spec.rb
|
|
89
|
+
- spec/grape_entity/json_spec.rb
|
|
102
90
|
- spec/grape_entity/options_spec.rb
|
|
103
91
|
- spec/spec_helper.rb
|
|
104
92
|
homepage: https://github.com/ruby-grape/grape-entity
|
|
@@ -120,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
120
108
|
- !ruby/object:Gem::Version
|
|
121
109
|
version: '0'
|
|
122
110
|
requirements: []
|
|
123
|
-
rubygems_version: 3.5.
|
|
111
|
+
rubygems_version: 3.5.22
|
|
124
112
|
signing_key:
|
|
125
113
|
specification_version: 4
|
|
126
114
|
summary: A simple facade for managing the relationship between your model and API.
|
|
@@ -130,5 +118,6 @@ test_files:
|
|
|
130
118
|
- spec/grape_entity/exposure/represent_exposure_spec.rb
|
|
131
119
|
- spec/grape_entity/exposure_spec.rb
|
|
132
120
|
- spec/grape_entity/hash_spec.rb
|
|
121
|
+
- spec/grape_entity/json_spec.rb
|
|
133
122
|
- spec/grape_entity/options_spec.rb
|
|
134
123
|
- spec/spec_helper.rb
|