Class: SimpleFileUploader::BaseUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_file_uploader/base_uploader.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_uploadersObject (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_valueObject

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

#errorsObject

Returns the value of attribute errors.



5
6
7
# File 'lib/simple_file_uploader/base_uploader.rb', line 5

def errors
  @errors
end

#modelObject

Returns the value of attribute model.



5
6
7
# File 'lib/simple_file_uploader/base_uploader.rb', line 5

def model
  @model
end

#mounted_asObject

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

#plainObject



17
# File 'lib/simple_file_uploader/base_uploader.rb', line 17

def plain; column_value; end

#validate_callbackObject



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