Sha256: e499102c17ea5aef5afd3fbf8bb769b632b220d7b052eccfd167f85f2b4e5598

Contents?: true

Size: 864 Bytes

Versions: 13

Compression:

Stored size: 864 Bytes

Contents

module CustomFields

  module Types

    module File

      module Field; end

      module Target

        extend ActiveSupport::Concern

        module ClassMethods

          # Adds a file field (using carrierwave)
          #
          # @param [ Class ] klass The class to modify
          # @param [ Hash ] rule It contains the name of the field and if it is required or not
          #
          def apply_file_custom_field(klass, rule)
            name = rule['name']

            klass.mount_uploader name, FileUploader

            if rule['localized'] == true
              klass.replace_field name, ::String, true
            end

            if rule['required']
              klass.validates_presence_of name
            end
          end

        end

      end

      class FileUploader < ::CarrierWave::Uploader::Base
      end

    end

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
custom_fields-2.0.0.rc13 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc12 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc11 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc10 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc9 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc8 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc7 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc6 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc5 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc4 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc3 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc2 lib/custom_fields/types/file.rb
custom_fields-2.0.0.rc1 lib/custom_fields/types/file.rb