Module: Dragonfly::HasFilename

Included in:
ActiveModelExtensions::Attachment, TempObject, UrlAttributes
Defined in:
lib/dragonfly/has_filename.rb

Overview

Convenience methods for setting basename and extension Including class needs to define a 'name' accessor which is assumed to hold a filename-style string

Instance Method Summary (collapse)

Instance Method Details

- (Object) basename



7
8
9
# File 'lib/dragonfly/has_filename.rb', line 7

def basename
  File.basename(name, '.*') if name
end

- (Object) basename=(basename)



11
12
13
# File 'lib/dragonfly/has_filename.rb', line 11

def basename=(basename)
  self.name = [basename, ext].compact.join('.')
end

- (Object) ext



15
16
17
# File 'lib/dragonfly/has_filename.rb', line 15

def ext
  File.extname(name)[/\.(.*)/, 1] if name
end

- (Object) ext=(ext)



19
20
21
# File 'lib/dragonfly/has_filename.rb', line 19

def ext=(ext)
  self.name = [(basename || 'file'), ext].join('.')
end