Class: Transmission::Model::Torrent
- Inherits:
-
Object
- Object
- Transmission::Model::Torrent
show all
- Defined in:
- lib/transmission/model/torrent.rb
Defined Under Namespace
Classes: DuplicateTorrentError, MissingAttributesError, TorrentError, TorrentNotFoundError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(torrent_object, connector) ⇒ Torrent
Returns a new instance of Torrent.
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/transmission/model/torrent.rb', line 11
def initialize(torrent_object, connector)
if torrent_object.is_a? Array
is_single = torrent_object.size == 1
@attributes = is_single ? torrent_object.first : {}
@ids = is_single ? [@attributes['id'].to_i] : []
@torrents = torrent_object.inject([]) do |torrents, torrent|
@ids << torrent['id'].to_i
torrents << Torrent.new([torrent], connector)
end unless is_single
end
@connector = connector
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/transmission/model/torrent.rb', line 99
def method_missing(symbol, *args)
string = symbol.to_s
if string[-1] == '='
string = string[0..-2]
key = Transmission::Arguments::TorrentSet.real_key string
return @attributes[key] = args.first if !!key
else
key = Transmission::Fields::TorrentGet.real_key string
return @attributes[key] if !!key
end
super
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
9
10
11
|
# File 'lib/transmission/model/torrent.rb', line 9
def attributes
@attributes
end
|
#connector ⇒ Object
Returns the value of attribute connector.
9
10
11
|
# File 'lib/transmission/model/torrent.rb', line 9
def connector
@connector
end
|
#deleted ⇒ Object
Returns the value of attribute deleted.
9
10
11
|
# File 'lib/transmission/model/torrent.rb', line 9
def deleted
@deleted
end
|
#ids ⇒ Object
Returns the value of attribute ids.
9
10
11
|
# File 'lib/transmission/model/torrent.rb', line 9
def ids
@ids
end
|
#torrents ⇒ Object
Returns the value of attribute torrents.
9
10
11
|
# File 'lib/transmission/model/torrent.rb', line 9
def torrents
@torrents
end
|
Class Method Details
.add(options = {}) ⇒ Object
127
128
129
130
131
132
|
# File 'lib/transmission/model/torrent.rb', line 127
def add(options = {})
rpc = options[:connector] || connector
body = rpc.add_torrent options[:arguments]
raise DuplicateTorrentError if body['torrent-duplicate']
find body['torrent-added']['id'], options
end
|
.all(options = {}) ⇒ Object
113
114
115
116
117
|
# File 'lib/transmission/model/torrent.rb', line 113
def all(options = {})
rpc = options[:connector] || connector
body = rpc.get_torrent nil, options[:fields]
Torrent.new body['torrents'], rpc
end
|
.find(id, options = {}) ⇒ Object
119
120
121
122
123
124
125
|
# File 'lib/transmission/model/torrent.rb', line 119
def find(id, options = {})
rpc = options[:connector] || connector
ids = id.is_a?(Array) ? id : [id]
body = rpc.get_torrent ids, options[:fields]
raise TorrentNotFoundError if body['torrents'].size == 0
Torrent.new body['torrents'], rpc
end
|
.start_all!(options = {}) ⇒ Object
134
135
136
137
|
# File 'lib/transmission/model/torrent.rb', line 134
def start_all!(options = {})
rpc = options[:connector] || connector
rpc.start_torrent nil
end
|
.stop_all!(options = {}) ⇒ Object
139
140
141
142
|
# File 'lib/transmission/model/torrent.rb', line 139
def stop_all!(options = {})
rpc = options[:connector] || connector
rpc.stop_torrent nil
end
|
Instance Method Details
#delete!(remove_local_data = false) ⇒ Object
24
25
26
27
|
# File 'lib/transmission/model/torrent.rb', line 24
def delete!(remove_local_data = false)
connector.remove_torrent @ids, remove_local_data
@deleted = true
end
|
#finished? ⇒ Boolean
78
79
80
|
# File 'lib/transmission/model/torrent.rb', line 78
def finished?
self.percent_done == 1
end
|
#is_multi? ⇒ Boolean
74
75
76
|
# File 'lib/transmission/model/torrent.rb', line 74
def is_multi?
@ids.size > 1
end
|
#move_bottom! ⇒ Object
46
47
48
|
# File 'lib/transmission/model/torrent.rb', line 46
def move_bottom!
connector.move_bottom_torrent @ids
end
|
#move_down! ⇒ Object
38
39
40
|
# File 'lib/transmission/model/torrent.rb', line 38
def move_down!
connector.move_down_torrent @ids
end
|
#move_top! ⇒ Object
42
43
44
|
# File 'lib/transmission/model/torrent.rb', line 42
def move_top!
connector.move_top_torrent @ids
end
|
#move_up! ⇒ Object
34
35
36
|
# File 'lib/transmission/model/torrent.rb', line 34
def move_up!
connector.move_up_torrent @ids
end
|
#re_announce! ⇒ Object
66
67
68
|
# File 'lib/transmission/model/torrent.rb', line 66
def re_announce!
connector.re_announce_torrent @ids
end
|
#reload! ⇒ Object
82
83
84
85
86
87
|
# File 'lib/transmission/model/torrent.rb', line 82
def reload!
torrents = Torrent.find @ids, connector: @connector
@ids = torrents.ids
@attributes = torrents.attributes
@torrents = torrents.torrents
end
|
#set_location(new_location, move = false) ⇒ Object
70
71
72
|
# File 'lib/transmission/model/torrent.rb', line 70
def set_location(new_location, move = false)
connector.torrent_set_location @ids, location: new_location, move: move
end
|
#start! ⇒ Object
50
51
52
|
# File 'lib/transmission/model/torrent.rb', line 50
def start!
connector.start_torrent @ids
end
|
#start_now! ⇒ Object
54
55
56
|
# File 'lib/transmission/model/torrent.rb', line 54
def start_now!
connector.start_torrent_now @ids
end
|
#stop! ⇒ Object
58
59
60
|
# File 'lib/transmission/model/torrent.rb', line 58
def stop!
connector.stop_torrent @ids
end
|
#to_json ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/transmission/model/torrent.rb', line 89
def to_json
if is_multi?
@torrents.inject([]) do |torrents, torrent|
torrents << torrent.to_json
end
else
@attributes
end
end
|
#verify! ⇒ Object
62
63
64
|
# File 'lib/transmission/model/torrent.rb', line 62
def verify!
connector.verify_torrent @ids
end
|