grape-entity 1.0.4 → 1.1.0
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/CHANGELOG.md +12 -0
- data/lib/grape_entity/entity.rb +43 -18
- data/lib/grape_entity/version.rb +1 -1
- metadata +5 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 629fcce5dd878171471587ff40412484bdf2dad7207260e640178cad5de5906d
|
|
4
|
+
data.tar.gz: 6ffde278282ef2538348ebbb64e2f81ec212c5afb049b05245ab124e9a61d5b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac996bcc2636195158354945aafbba70a619aa104537e2dfb7ec1a55b00bc572be9569926c0b7973fa56be4d6a38618ff93699f987525120c283cb546cb5d12a
|
|
7
|
+
data.tar.gz: 933701a08a1c20e521615a0dea7e4cab08787ce20efe4f33dbb383e704cbf3c37ac2bd652f64d0435521a70ec716b00d0a9f5b28bf46fdd0891c6e796553a00c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
### 1.1.0 (2026-06-05)
|
|
2
|
+
|
|
3
|
+
#### Features
|
|
4
|
+
|
|
5
|
+
* [#404](https://github.com/ruby-grape/grape-entity/pull/404): Drop `MultiJson` dependency, use `Hash#to_json` for ActiveSupport-aware serialization - [@numbata](https://github.com/numbata).
|
|
6
|
+
|
|
7
|
+
#### Fixes
|
|
8
|
+
|
|
9
|
+
* [#406](https://github.com/ruby-grape/grape-entity/pull/406): Handle symbol-to-proc wrappers (`&:method_name`) where the method uses `delegate` or `method_missing`, and let unknown methods raise a native `NoMethodError` - [@marcrohloff](https://github.com/marcrohloff).
|
|
10
|
+
|
|
11
|
+
|
|
1
12
|
### 1.0.4 (2026-04-17)
|
|
2
13
|
|
|
3
14
|
#### Fixes
|
|
@@ -5,6 +16,7 @@
|
|
|
5
16
|
* [#405](https://github.com/ruby-grape/grape-entity/pull/405): Fix `Time` serialization regression by reverting #385 and restoring `MultiJson.dump` - [@numbata](https://github.com/numbata).
|
|
6
17
|
* [#402](https://github.com/ruby-grape/grape-entity/pull/402): Remove `Json::ParseError` assignment - [@olivier-thatch](https://github.com/olivier-thatch).
|
|
7
18
|
|
|
19
|
+
|
|
8
20
|
### 1.0.3 (2026-04-15)
|
|
9
21
|
|
|
10
22
|
#### Features
|
data/lib/grape_entity/entity.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'multi_json'
|
|
4
|
-
|
|
5
3
|
module Grape
|
|
6
4
|
# An Entity is a lightweight structure that allows you to easily
|
|
7
5
|
# represent data from your application in a consistent and abstracted
|
|
@@ -293,7 +291,7 @@ module Grape
|
|
|
293
291
|
end
|
|
294
292
|
|
|
295
293
|
# This allows you to declare a Proc in which exposures can be formatted with.
|
|
296
|
-
# It
|
|
294
|
+
# It takes a block with a single argument which is passed as the value of the exposed attribute.
|
|
297
295
|
#
|
|
298
296
|
# @param name [Symbol] the name of the formatter
|
|
299
297
|
# @param block [Proc] the block that will interpret the exposed attribute
|
|
@@ -536,26 +534,53 @@ module Grape
|
|
|
536
534
|
end
|
|
537
535
|
|
|
538
536
|
def ensure_block_arity!(block)
|
|
539
|
-
#
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
MSG
|
|
548
|
-
end
|
|
537
|
+
# Strict anchor to match MRI Proc#to_s format for symbol-to-proc: #<Proc:0x0...(&:method_name) (lambda)>
|
|
538
|
+
match = block.to_s.match(/\A#<Proc:(?:0x)?\h+\(&:(?<name>.+)\) \(lambda\)>\z/)
|
|
539
|
+
return unless match # Unrecognized format -> bail safe rather than misidentify
|
|
540
|
+
|
|
541
|
+
origin_method_name = match[:name].to_sym
|
|
542
|
+
required_positional_arg_count, required_keyword_arg_count, variadic_positional =
|
|
543
|
+
arity_requirement_for(origin_method_name)
|
|
544
|
+
return unless required_positional_arg_count
|
|
549
545
|
|
|
550
|
-
|
|
551
|
-
|
|
546
|
+
required_arguments =
|
|
547
|
+
required_arguments_summary(required_positional_arg_count, required_keyword_arg_count, variadic_positional)
|
|
552
548
|
|
|
553
549
|
raise ArgumentError, <<~MSG
|
|
554
|
-
Cannot use `&:#{origin_method_name}` because that method expects #{
|
|
555
|
-
Symbol
|
|
550
|
+
Cannot use `&:#{origin_method_name}` because that method expects #{required_arguments}.
|
|
551
|
+
Symbol-to-proc shorthand only works for methods that can be called with no arguments.
|
|
556
552
|
MSG
|
|
557
553
|
end
|
|
558
554
|
|
|
555
|
+
def arity_requirement_for(method_name)
|
|
556
|
+
origin_method = object.method(method_name)
|
|
557
|
+
parameters = origin_method.parameters
|
|
558
|
+
|
|
559
|
+
required_positional_arg_count = parameters.count { |type, _| type == :req }
|
|
560
|
+
required_keyword_arg_count = parameters.count { |type, _| type == :keyreq }
|
|
561
|
+
return nil if required_positional_arg_count.zero? && required_keyword_arg_count.zero?
|
|
562
|
+
|
|
563
|
+
[required_positional_arg_count, required_keyword_arg_count, parameters.any? { |type, _| type == :rest }]
|
|
564
|
+
rescue NameError
|
|
565
|
+
# Delegation wrappers and method_missing proxies may not expose a Method; let Ruby raise natively at call time.
|
|
566
|
+
nil
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
def required_arguments_summary(required_positional_arg_count, required_keyword_arg_count, variadic_positional)
|
|
570
|
+
parts = []
|
|
571
|
+
unless required_positional_arg_count.zero?
|
|
572
|
+
suffix = required_positional_arg_count == 1 ? 'argument' : 'arguments'
|
|
573
|
+
suffix += ' or more' if variadic_positional
|
|
574
|
+
parts << "#{required_positional_arg_count} #{suffix}"
|
|
575
|
+
end
|
|
576
|
+
unless required_keyword_arg_count.zero?
|
|
577
|
+
suffix = required_keyword_arg_count == 1 ? 'keyword argument' : 'keyword arguments'
|
|
578
|
+
parts << "#{required_keyword_arg_count} #{suffix}"
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
parts.join(' and ')
|
|
582
|
+
end
|
|
583
|
+
|
|
559
584
|
def symbol_to_proc_wrapper?(block)
|
|
560
585
|
params = block.parameters
|
|
561
586
|
|
|
@@ -594,7 +619,7 @@ module Grape
|
|
|
594
619
|
|
|
595
620
|
def to_json(options = {})
|
|
596
621
|
options = options.to_h if options&.respond_to?(:to_h)
|
|
597
|
-
|
|
622
|
+
serializable_hash(options).to_json
|
|
598
623
|
end
|
|
599
624
|
|
|
600
625
|
def to_xml(options = {})
|
data/lib/grape_entity/version.rb
CHANGED
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.1.0
|
|
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: 2026-04
|
|
12
|
+
date: 2026-06-04 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.0'
|
|
35
|
-
type: :runtime
|
|
36
|
-
prerelease: false
|
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
-
requirements:
|
|
39
|
-
- - ">="
|
|
40
|
-
- !ruby/object:Gem::Version
|
|
41
|
-
version: '1.0'
|
|
42
28
|
description: Extracted from Grape, A Ruby framework for rapid API development with
|
|
43
29
|
great conventions.
|
|
44
30
|
email:
|
|
@@ -83,9 +69,9 @@ licenses:
|
|
|
83
69
|
metadata:
|
|
84
70
|
homepage_uri: https://github.com/ruby-grape/grape-entity
|
|
85
71
|
bug_tracker_uri: https://github.com/ruby-grape/grape-entity/issues
|
|
86
|
-
changelog_uri: https://github.com/ruby-grape/grape-entity/blob/v1.0
|
|
87
|
-
documentation_uri: https://www.rubydoc.info/gems/grape-entity/1.0
|
|
88
|
-
source_code_uri: https://github.com/ruby-grape/grape-entity/tree/v1.0
|
|
72
|
+
changelog_uri: https://github.com/ruby-grape/grape-entity/blob/v1.1.0/CHANGELOG.md
|
|
73
|
+
documentation_uri: https://www.rubydoc.info/gems/grape-entity/1.1.0
|
|
74
|
+
source_code_uri: https://github.com/ruby-grape/grape-entity/tree/v1.1.0
|
|
89
75
|
rubygems_mfa_required: 'true'
|
|
90
76
|
post_install_message:
|
|
91
77
|
rdoc_options: []
|