Class: PictureHandler::Uploader::Base

Inherits:
Object
  • Object
show all
Includes:
ImgVersion, MiniMagick
Defined in:
lib/picture_handler/uploader/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ImgVersion

#process, #version

Methods included from MiniMagick

included

Constructor Details

#initialize(model = nil) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/picture_handler/uploader/base.rb', line 13

def initialize(model=nil)
  # Set once
  @image = nil
  @model = model
  @versions = {}
  register_versions

  # Changing runtime
  @current_version = nil
  @info_built = false
  @infos = {}
  @real_filename
end

Instance Attribute Details

#imageObject

Returns the value of attribute image.



10
11
12
# File 'lib/picture_handler/uploader/base.rb', line 10

def image
  @image
end

#modelObject

Returns the value of attribute model.



10
11
12
# File 'lib/picture_handler/uploader/base.rb', line 10

def model
  @model
end

#real_filenameObject (readonly)

Returns the value of attribute real_filename.



11
12
13
# File 'lib/picture_handler/uploader/base.rb', line 11

def real_filename
  @real_filename
end

#versionsObject

Returns the value of attribute versions.



10
11
12
# File 'lib/picture_handler/uploader/base.rb', line 10

def versions
  @versions
end

Instance Method Details

#delete_allObject



70
71
72
# File 'lib/picture_handler/uploader/base.rb', line 70

def delete_all
  delete_all_with_file_system
end

#filenameObject



27
28
29
# File 'lib/picture_handler/uploader/base.rb', line 27

def filename
  "unamed"
end

#infoObject

—————————– # —— Public Method ——– # —————————– #



52
53
54
55
# File 'lib/picture_handler/uploader/base.rb', line 52

def info
  build_infos unless @info_built
  @infos
end

#remote_pathObject



35
36
37
# File 'lib/picture_handler/uploader/base.rb', line 35

def remote_path
  nil
end

#storeObject

When a Model.save is done



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/picture_handler/uploader/base.rb', line 58

def store

  # Get the filename once and will use the same for all futur save
  @real_filename = filename
  # Is the model new ? delete old record if true
  delete_all if @model.old_record

  process_original_image
  apply_versions

end

#store_dirObject



31
32
33
# File 'lib/picture_handler/uploader/base.rb', line 31

def store_dir
  "public/ph_pictures/"
end

#versions_infoObject



39
40
41
42
43
44
45
# File 'lib/picture_handler/uploader/base.rb', line 39

def versions_info
  res = info
  res = res.select do |obj|
    obj == :position || (res[:versions].include? obj)
  end
  res
end