Skip to content

Instantly share code, notes, and snippets.

@emptyflask
Created October 31, 2021 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emptyflask/42828cf8a1d071bf6b47b7742682ccc0 to your computer and use it in GitHub Desktop.
Save emptyflask/42828cf8a1d071bf6b47b7742682ccc0 to your computer and use it in GitHub Desktop.
Virtus
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