Skip to content

Commit ea60f9a

Browse files
authored
Add ability to define multiple versions of validator in one block (#144)
1 parent 5534b44 commit ea60f9a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.2.0
4+
5+
- Add ability to define multiple versions using one block
6+
37
## 2.1.1
48

59
- Fix Ruby 2.6 to 2.7 incompatible change

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ class Venue
9494
attribute :altitude, AllowNil(Numeric)
9595
end
9696

97-
version 1 do
97+
versions [1, 2] do |v|
9898
collection :location do
99+
link :extra if v > 1
100+
99101
attribute :latitude, Numeric
100102
attribute :longitude, Numeric
101103
attribute :altitude, AllowNil(Numeric)

lib/media_types/validations.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ def version(version, &block)
8989
Validations.new(media_type.version(version), registry, &block)
9090
end
9191

92+
##
93+
# Runs the block for multiple versions
94+
#
95+
# @param [Array] list of versions to run this on
96+
#
97+
def versions(versions, &block)
98+
versions.each do |v|
99+
Validations.new(media_type.version(v), registry) do
100+
block(v)
101+
end
102+
end
103+
end
104+
92105
##
93106
# Switches the inner block to a specific view
94107
#

0 commit comments

Comments
 (0)