Class: TicGitNG::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/ticgit-ng/attachment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fname) ⇒ Attachment

Returns a new instance of Attachment.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ticgit-ng/attachment.rb', line 7

def initialize( fname )
    #FIXME expect fname to be a raw filename that needs to be converted
    #      into a properly formatted ticket name
    @filename=fname
    trailing_underscore= File.basename(fname)[/_$/] ? true : false
    trailing_underscore=false
    temp=File.basename(fname).split('_').reverse
    @added=Time.at(temp.pop.to_i)
    @user= temp.pop
    @attachment_name= temp.reverse.join('_')
    if trailing_underscore
      @attachment_name << '_'
    end
end

Instance Attribute Details

#addedObject (readonly)

Returns the value of attribute added.



3
4
5
# File 'lib/ticgit-ng/attachment.rb', line 3

def added
  @added
end

#attachment_nameObject (readonly)

Returns the value of attribute attachment_name.



3
4
5
# File 'lib/ticgit-ng/attachment.rb', line 3

def attachment_name
  @attachment_name
end

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/ticgit-ng/attachment.rb', line 3

def filename
  @filename
end

#original_filenameObject (readonly)

Returns the value of attribute original_filename.



4
5
6
# File 'lib/ticgit-ng/attachment.rb', line 4

def original_filename
  @original_filename
end

#shaObject (readonly)

Returns the value of attribute sha.



3
4
5
# File 'lib/ticgit-ng/attachment.rb', line 3

def sha
  @sha
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/ticgit-ng/attachment.rb', line 3

def user
  @user
end

Class Method Details

.create(raw_fname, ticket, time) ⇒ Object

Called when attaching a new attachment and when reading/opening attachments FIXME Make a ‘read’ and ‘create’ function to differentiate between

between creation of a ticket and reading an existing ticket.


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ticgit-ng/attachment.rb', line 25

def self.create raw_fname, ticket, time 
    #Attachment naming format:
    #ticket_name/ATTACHMENTS/[email protected]_fubar.jpg
    #raw_fname "/home/guy/Desktop/fubar.jpg"

    #create attachment dir if first run
    a_name= File.expand_path( File.join(
        File.join( ticket.ticket_name, 'ATTACHMENTS' ), 
        ticket.create_attachment_name(raw_fname, time)
    ))
    #create new filename from ticket
    if File.exist?( File.dirname( a_name )  ) && 
       !File.directory?( File.dirname(a_name) )

        puts "Could not create ATTACHMENTS directory"
        exit 1
    elsif !File.exist?( File.dirname( a_name ) )
        Dir.mkdir File.dirname( a_name )
    end
    #copy/link the raw_filename
    Dir.chdir( File.dirname(a_name) ) do
        FileUtils.cp( raw_fname, a_name )
    end
    #call init on the new file to properly populate the variables
    a_name= File.join( 
                      File.basename( File.dirname( a_name ) ),
                      File.basename( a_name )
                     )
    return Attachment.new( a_name )
end

Instance Method Details

#readObject



5
# File 'lib/ticgit-ng/attachment.rb', line 5

alias :read :initialize