Skip to content

Commit

Permalink
Add ability to define multiple versions of validator in one block
Browse files Browse the repository at this point in the history
  • Loading branch information
thexa4 committed Aug 3, 2023
1 parent 5534b44 commit 4471d4a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.2.0

- Add ability to define multiple versions using one block

## 2.1.1

- Fix Ruby 2.6 to 2.7 incompatible change
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ class Venue
attribute :altitude, AllowNil(Numeric)
end

version 1 do
versions [1, 2] do |v|
collection :location do
link :extra if v > 1

attribute :latitude, Numeric
attribute :longitude, Numeric
attribute :altitude, AllowNil(Numeric)
Expand Down
13 changes: 13 additions & 0 deletions lib/media_types/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ def version(version, &block)
Validations.new(media_type.version(version), registry, &block)
end

##
# Runs the block for multiple versions
#
# @param [Array] list of versions to run this on
#
def versions(versions, &block)
versions.each do |v|
Validations.new(media_type.version(v), registry) do
block(v)
end
end
end

##
# Switches the inner block to a specific view
#
Expand Down

0 comments on commit 4471d4a

Please sign in to comment.