Sha256: 527b3fd60823dbdb2f6168c39ae0ef01bc46e155682a42aef57c477f45b5815c
Contents?: true
Size: 903 Bytes
Versions: 1
Compression:
Stored size: 903 Bytes
Contents
module Arbetsformedlingen PublicationSchema = Dry::Validation.Params do configure do config.type_specs = true config.messages_file = File.expand_path('../../../../config/locales/errors.yml', __FILE__) predicates(Predicates) end required(:unpublish_at, :string).filled(:yyyy_mm_dd?) required(:name, Types::StrippedString).filled required(:email, Types::StrippedString).filled(:str?, :email?) optional(:publish_at, :string).filled(:yyyy_mm_dd?) end class Publication < Model def initialize(hash) data = hash.dup publish_date = data[:publish_at] || Time.now.utc data[:publish_at] = publish_date.strftime('%Y-%m-%d') data[:unpublish_at] = data[:unpublish_at]&.strftime('%Y-%m-%d') # TODO: Validate that unpublish_at - publish_at is not greater that 180 days super(PublicationSchema.call(data)) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arbetsformedlingen-0.5.0 | lib/arbetsformedlingen/models/publication.rb |