Sha256: 54def5313ca09a3dc468be674cb8d118573abe71f5084e1b11c600a6f07cf4ab

Contents?: true

Size: 1011 Bytes

Versions: 50

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    module Admin
      # A form object used to create conference media link from the admin dashboard.
      class MediaLinkForm < Form
        include TranslatableAttributes

        mimic :conference_media_link

        translatable_attribute :title, String

        attribute :link, String
        attribute :date, Decidim::Attributes::LocalizedDate
        attribute :weight, Integer, default: 0

        validates :title, :date, :link, presence: true
        validate :link_format

        def link
          return if super.blank?

          return "http://#{super}" unless super.match?(%r{\A(http|https)://}i)

          super
        end

        private

        def link_format
          return if link.blank?

          uri = URI.parse(link)
          errors.add :link, :invalid if !uri.is_a?(URI::HTTP) || uri.host.nil?
        rescue URI::InvalidURIError
          errors.add :link, :invalid
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
decidim-conferences-0.29.1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.28.4 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.27.9 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.29.0 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.28.3 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.27.8 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.29.0.rc4 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.29.0.rc3 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.29.0.rc2 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.29.0.rc1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.28.2 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.27.7 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.28.1 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.27.6 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.26.10 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.26.9 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.28.0 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.27.5 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.28.0.rc5 app/forms/decidim/conferences/admin/media_link_form.rb
decidim-conferences-0.28.0.rc4 app/forms/decidim/conferences/admin/media_link_form.rb