Class: ValidateMbsFile
This class is generated by the multi bit shift generator, and is used to specify the validation parameters for individual files. To use the class, the constants should be modified so that a index exists for each validation set.
In the default demo configuration, the hash index files is used to represent one particular column.
This class should be used in conjunction with the automatic_mbs_validation method that we include in active record, and as the validation_object passed in the options has to the multi_bit_shift_field helper. Example:
# Should be included in the main class, and in the file class
automatic_mbs_validation ValidateMbsFile.new("files")
# The helper would be used in a form, and passes the validation params to the flash applet.
multi_bit_shift_field 'object_name', 'method', {"validation_object" => ValidateMbsFile.new("files")}
Constants
| Name | Value |
|---|---|
| MAIN_CLASS | {"files" => "Testa"}.freeze |
| FILE_CLASS | {"files" => "MbsFile"}.freeze |
| MAIN_COLUMN | {"files" => :files}.freeze |
| FILE_COLUMN | {"files" => :file_name}.freeze |
| MINIMUM_FILES | {"files" => 1}.freeze |
| MAXIMUM_FILES | {"files" => 3}.freeze |
| MINIMUM_FILE_SIZE | {"files" => 0}.freeze |
| MAXIMUM_FILE_SIZE | {"files" => 10.kilobytes}.freeze |
| MAXIMUM_TOTAL_FILE_SIZE | {"files" => 5000.kilobytes}.freeze |
| FILE_TYPES | {"files" => ["gif", "png", "jpg"]}.freeze |
| FILE_TYPE_NAME | {"files" => "Image Files"}.freeze |
Attributes
| Name | Read/write? |
|---|---|
| selected_item | R |
Public Class Methods
new (item)
Initializes the object and sets the has that the validation methods will draw from. In other words, if the validation options you wish to use are specified by the "files" index, "files" is the appropriate parameter for this method.
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 60 60: def initialize(item) 61: @selected_item = item 62: end
Public Instance Methods
convert_to_flash_params ()
Converts the parameters of this object into a hash that can be merged with the options hash in the multi_bit_shift_field helper.
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 121 121: def convert_to_flash_params 122: if !self.file_types.nil? and !self.file_type_name.nil? 123: options = {"fileLabel" => self.file_type_name, "fileExtensions" => "*.#{self.file_types.join(';*.')}"} 124: else 125: options = {} 126: end 127: return options.merge({"maximumFileBytes" => self.maximum_file_size.to_s, "maximumFilesOnServer" => self.maximum_files.to_s, 128: "maximumBytesOnServer" => self.maximum_total_file_size.to_s}) 129: end
file_class ()
Returns the file class for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 70 70: def file_class 71: return FILE_CLASS[self.selected_item] 72: end
file_column ()
Returns the file column for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 80 80: def file_column 81: return FILE_COLUMN[self.selected_item] 82: end
file_size_range ()
Returns the range of file sizes that the selected index can have.
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 137 137: def file_size_range 138: return Range.new(self.minimum_file_size, self.maximum_file_size) 139: end
file_type_name ()
Returns the file type name for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 115 115: def file_type_name 116: return FILE_TYPE_NAME[self.selected_item] 117: end
file_types ()
Returns the file types for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 110 110: def file_types 111: return FILE_TYPES[self.selected_item] 112: end
main_class ()
Returns the main class for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 65 65: def main_class 66: return MAIN_CLASS[self.selected_item] 67: end
main_column ()
Returns the main column for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 75 75: def main_column 76: return MAIN_COLUMN[self.selected_item] 77: end
maximum_file_size ()
Returns the maximum file size for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 100 100: def maximum_file_size 101: return MAXIMUM_FILE_SIZE[self.selected_item] 102: end
maximum_files ()
Returns the maximum number of files for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 90 90: def maximum_files 91: return MAXIMUM_FILES[self.selected_item] 92: end
maximum_total_file_size ()
Returns the maximum total file size for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 105 105: def maximum_total_file_size 106: return MAXIMUM_TOTAL_FILE_SIZE[self.selected_item] 107: end
minimum_file_size ()
Returns the minimum file size for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 95 95: def minimum_file_size 96: return MINIMUM_FILE_SIZE[self.selected_item] 97: end
minimum_files ()
Returns the minimum number of files for the specified index
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 85 85: def minimum_files 86: return MINIMUM_FILES[self.selected_item] 87: end
number_of_files_range ()
Returns the range of files that the selected index can have
# File generators/multi_bit_shift/templates/models/mbs_validation_settings.rb, line 132 132: def number_of_files_range 133: return Range.new(self.minimum_files, self.maximum_files) 134: end