Created
October 31, 2021 16:00
-
-
Save emptyflask/42828cf8a1d071bf6b47b7742682ccc0 to your computer and use it in GitHub Desktop.
Virtus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
require 'active_model' | |
require 'active_support/concern' | |
require 'virtus' | |
module EventParams | |
include Virtus.module | |
extend ActiveSupport::Concern | |
include ActiveModel::Validations | |
attribute :event_params | |
included do | |
validate :validate_event_params | |
end | |
def validate_event_params | |
if event_params | |
errors.add(:event_params, 'Should have at least one event parameter') if event_params[:phone_numbers].blank? | |
end | |
end | |
end | |
class Event | |
include EventParams | |
end | |
puts Event.new(event_params: {phone_numbers: ['1235554567']}).valid? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment