Class: Vetinari::Dcc::Incoming::File

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO, Celluloid::Notifications
Defined in:
lib/vetinari/dcc/incoming/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, filename, ip, port, filesize, bot) ⇒ File

Returns a new instance of File.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vetinari/dcc/incoming/file.rb', line 9

def initialize(user, filename, ip, port, filesize, bot)
  @user       = user
  @filename   = filename
  @ip         = ip
  @port       = port
  @filesize   = filesize
  @bot        = bot
  @mutex      = Mutex.new
  
  self.state = :pending
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/vetinari/dcc/incoming/file.rb', line 7

def filename
  @filename
end

#filesizeObject (readonly)

Returns the value of attribute filesize.



7
8
9
# File 'lib/vetinari/dcc/incoming/file.rb', line 7

def filesize
  @filesize
end

#ipObject (readonly)

Returns the value of attribute ip.



7
8
9
# File 'lib/vetinari/dcc/incoming/file.rb', line 7

def ip
  @ip
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/vetinari/dcc/incoming/file.rb', line 7

def port
  @port
end

#stateObject

Returns the value of attribute state.



7
8
9
# File 'lib/vetinari/dcc/incoming/file.rb', line 7

def state
  @state
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/vetinari/dcc/incoming/file.rb', line 7

def user
  @user
end

Instance Method Details

#accept(directory = '~/Downloads/', resume = false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vetinari/dcc/incoming/file.rb', line 21

def accept(directory = '~/Downloads/', resume = false)
  if @state == :pending
    self.state = :accepted
    directory = ::File.expand_path(directory)
    @filepath = ::File.join(directory, @filename)

    if resume && resumable?
      resume_transfer
    else
      download
    end
  end
end

#inspectObject



35
36
37
# File 'lib/vetinari/dcc/incoming/file.rb', line 35

def inspect
  "#<File filename=#{@filename} filesize=#{@filesize} user=#{@user.inspect}"
end

#resume_accepted(position) ⇒ Object



39
40
41
42
# File 'lib/vetinari/dcc/incoming/file.rb', line 39

def resume_accepted(position)
  self.state = :resume_accepted
  download(position)
end