Class ValidateMbsFile
In: generators/multi_bit_shift/templates/models/mbs_validation_settings.rb
Parent: Object

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")}

Methods

Constants

MAIN_CLASS = {"files" => "Testa"}.freeze   Contains the string names of the main classes that will be used. (i.e. The one that will have files associated with it, but not contain the files)
FILE_CLASS = {"files" => "MbsFile"}.freeze   Contains the string names of the classes that will possess each file.
MAIN_COLUMN = {"files" => :files}.freeze   Contains the column in the main class that files will be assoicated with
FILE_COLUMN = {"files" => :file_name}.freeze   Contains the column in the file class that actually represents the file.
MINIMUM_FILES = {"files" => 1}.freeze   Minimum number of files that can be uploaded
MAXIMUM_FILES = {"files" => 3}.freeze   Maximum number of files that can be uploaded
MINIMUM_FILE_SIZE = {"files" => 0}.freeze   Minimum size of each file
MAXIMUM_FILE_SIZE = {"files" => 10.kilobytes}.freeze   Maximum size of each file
MAXIMUM_TOTAL_FILE_SIZE = {"files" => 5000.kilobytes}.freeze   Maximum size of all files combined.
FILE_TYPES = {"files" => ["gif", "png", "jpg"]}.freeze   Possible file types
FILE_TYPE_NAME = {"files" => "Image Files"}.freeze   Description of possible file types.

Attributes

selected_item  [R]  Internal variable that specifies which index the validation pertains to.

Public Class methods

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.

[Source]

    # 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

Converts the parameters of this object into a hash that can be merged with the options hash in the multi_bit_shift_field helper.

[Source]

     # 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

Returns the file class for the specified index

[Source]

    # 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

Returns the file column for the specified index

[Source]

    # 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

Returns the range of file sizes that the selected index can have.

[Source]

     # 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

Returns the file type name for the specified index

[Source]

     # 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

Returns the file types for the specified index

[Source]

     # 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

Returns the main class for the specified index

[Source]

    # 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

Returns the main column for the specified index

[Source]

    # 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

Returns the maximum file size for the specified index

[Source]

     # 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

Returns the maximum number of files for the specified index

[Source]

    # 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

Returns the maximum total file size for the specified index

[Source]

     # 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

Returns the minimum file size for the specified index

[Source]

    # 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

Returns the minimum number of files for the specified index

[Source]

    # 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

Returns the range of files that the selected index can have

[Source]

     # 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

[Validate]