Class: TicGitNG::Attachment
- Inherits:
-
Object
- Object
- TicGitNG::Attachment
- Defined in:
- lib/ticgit-ng/attachment.rb
Instance Attribute Summary collapse
-
#added ⇒ Object
readonly
Returns the value of attribute added.
-
#attachment_name ⇒ Object
readonly
Returns the value of attribute attachment_name.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#original_filename ⇒ Object
readonly
Returns the value of attribute original_filename.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
-
#initialize(fname) ⇒ Attachment
constructor
A new instance of Attachment.
- #read ⇒ Object
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 = temp.reverse.join('_') if trailing_underscore << '_' end end |
Instance Attribute Details
#added ⇒ Object (readonly)
Returns the value of attribute added.
3 4 5 |
# File 'lib/ticgit-ng/attachment.rb', line 3 def added @added end |
#attachment_name ⇒ Object (readonly)
Returns the value of attribute attachment_name.
3 4 5 |
# File 'lib/ticgit-ng/attachment.rb', line 3 def end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/ticgit-ng/attachment.rb', line 3 def filename @filename end |
#original_filename ⇒ Object (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 |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
3 4 5 |
# File 'lib/ticgit-ng/attachment.rb', line 3 def sha @sha end |
#user ⇒ Object (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.( File.join( File.join( ticket.ticket_name, 'ATTACHMENTS' ), ticket.(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
#read ⇒ Object
5 |
# File 'lib/ticgit-ng/attachment.rb', line 5 alias :read :initialize |