Class: SimpleFileUploader::BaseUploader
- Inherits:
-
Object
- Object
- SimpleFileUploader::BaseUploader
- Defined in:
- lib/simple_file_uploader/base_uploader.rb
Class Attribute Summary collapse
-
.mounted_uploaders ⇒ Object
readonly
Returns the value of attribute mounted_uploaders.
Instance Attribute Summary collapse
-
#column_value ⇒ Object
Returns the value of attribute column_value.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#model ⇒ Object
Returns the value of attribute model.
-
#mounted_as ⇒ Object
Returns the value of attribute mounted_as.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(model, mounted_as) ⇒ BaseUploader
constructor
A new instance of BaseUploader.
- #plain ⇒ Object
- #validate_callback ⇒ Object
- #write_identifier! ⇒ Object
Constructor Details
#initialize(model, mounted_as) ⇒ BaseUploader
Returns a new instance of BaseUploader.
7 8 9 10 11 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 7 def initialize(model, mounted_as) @errors = [] @model, @mounted_as = model, mounted_as @column_value = @model.read_uploader(@mounted_as) end |
Class Attribute Details
.mounted_uploaders ⇒ Object (readonly)
Returns the value of attribute mounted_uploaders.
22 23 24 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 22 def mounted_uploaders @mounted_uploaders end |
Instance Attribute Details
#column_value ⇒ Object
Returns the value of attribute column_value.
5 6 7 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 5 def column_value @column_value end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 5 def errors @errors end |
#model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 5 def model @model end |
#mounted_as ⇒ Object
Returns the value of attribute mounted_as.
5 6 7 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 5 def mounted_as @mounted_as end |
Class Method Details
.find_uploader_by_uuid(uuid) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 29 def find_uploader_by_uuid(uuid) mounted_uploaders.each do |mounted_uploader| clazz = mounted_uploader[:model_class].constantize found_model = clazz.where(:"#{mounted_uploader[:column]}" => uuid).take return found_model.send(:"#{mounted_uploader[:column]}") if found_model.present? end if mounted_uploaders.present? nil end |
.remember_uploader(model_class, column) ⇒ Object
24 25 26 27 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 24 def remember_uploader(model_class, column) @mounted_uploaders ||= [] @mounted_uploaders << {model_class: model_class.name, column: column} end |
Instance Method Details
#plain ⇒ Object
17 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 17 def plain; column_value; end |
#validate_callback ⇒ Object
19 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 19 def validate_callback; end |
#write_identifier! ⇒ Object
13 14 15 |
# File 'lib/simple_file_uploader/base_uploader.rb', line 13 def write_identifier! @model.write_uploader(@mounted_as, @column_value) end |