Module: SequelImage::InstanceMethods

Defined in:
lib/ramaze/contrib/sequel/image.rb

Instance Method Summary collapse

Instance Method Details

#basenameObject



148
149
150
# File 'lib/ramaze/contrib/sequel/image.rb', line 148

def basename
  File.basename(original, File.extname(original))
end

#cleanupObject



168
169
170
171
172
173
174
175
176
177
# File 'lib/ramaze/contrib/sequel/image.rb', line 168

def cleanup
  conf[:sizes].each do |name, args|
    out = public_file(name)
    Ramaze::Log.debug "Remove Thumbnail: #{out}"
    FileUtils.rm_f(out)
  end

  Ramaze::Log.debug "Remove original: #{original}"
  FileUtils.rm_f(original)
end

#confObject



164
165
166
# File 'lib/ramaze/contrib/sequel/image.rb', line 164

def conf
  self.class::IMAGE
end

#file(size = nil) ⇒ Object



127
128
129
# File 'lib/ramaze/contrib/sequel/image.rb', line 127

def file(size = nil)
  File.join('/', path, filename(size))
end

#filename(size) ⇒ Object



156
157
158
159
160
161
162
# File 'lib/ramaze/contrib/sequel/image.rb', line 156

def filename(size)
  if size
    "#{basename}_#{size}.png"
  else
    "#{basename}.png"
  end
end

#generate_thumbnailsObject



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/ramaze/contrib/sequel/image.rb', line 179

def generate_thumbnails
  FileUtils.mkdir_p(public_path)

  sizes, algorithm = conf.values_at(:sizes, :algorithm)

  ImageScience.with_image(original) do |img|
    Ramaze::Log.debug "Process original: #{original}"

    sizes.each do |name, args|
      out = public_file(name)
      Ramaze::Log.debug "Generate Thumbnail: #{out}"

      img.send(algorithm, *args) do |thumb|
        thumb.save(out)
      end
    end
  end
end

#next_name(uid, ext) ⇒ Object



143
144
145
146
# File 'lib/ramaze/contrib/sequel/image.rb', line 143

def next_name(uid, ext)
  uid = uid.to_s.scan(%r![^\\/'".:?&;\s]+!).join('-')
  "#{uid}#{ext}"
end

#pathObject



139
140
141
# File 'lib/ramaze/contrib/sequel/image.rb', line 139

def path
  conf[:path] || conf[:owner].to_s.downcase
end

#public_file(size) ⇒ Object



131
132
133
# File 'lib/ramaze/contrib/sequel/image.rb', line 131

def public_file(size)
  File.join(public_path, filename(size))
end

#public_pathObject



135
136
137
# File 'lib/ramaze/contrib/sequel/image.rb', line 135

def public_path
  File.join(public_root, path)
end

#public_rootObject



152
153
154
# File 'lib/ramaze/contrib/sequel/image.rb', line 152

def public_root
  Ramaze::Global.public_root
end