Class: Alexandria::BookProviders::AbstractProvider
- Inherits:
-
Object
- Object
- Alexandria::BookProviders::AbstractProvider
show all
- Includes:
- GetText
- Defined in:
- lib/alexandria/book_providers.rb,
lib/alexandria/ui/init.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, fullname = nil) ⇒ AbstractProvider
Returns a new instance of AbstractProvider.
204
205
206
207
208
209
|
# File 'lib/alexandria/book_providers.rb', line 204
def initialize(name, fullname = nil)
@name = name
@fullname = fullname || name
@prefs = Preferences.new(self)
@prefs.add("enabled", _("Enabled"), true, [true, false])
end
|
Instance Attribute Details
#fullname ⇒ Object
Returns the value of attribute fullname.
202
203
204
|
# File 'lib/alexandria/book_providers.rb', line 202
def fullname
@fullname
end
|
#name ⇒ Object
Returns the value of attribute name.
202
203
204
|
# File 'lib/alexandria/book_providers.rb', line 202
def name
@name
end
|
#prefs ⇒ Object
Returns the value of attribute prefs.
201
202
203
|
# File 'lib/alexandria/book_providers.rb', line 201
def prefs
@prefs
end
|
Class Method Details
.abstract? ⇒ Boolean
272
273
274
|
# File 'lib/alexandria/book_providers.rb', line 272
def self.abstract?
!included_modules.include?(Singleton)
end
|
.unabstract ⇒ Object
FIXME: Clean up this complex abstract/concrete class system
281
282
283
284
285
286
287
288
|
# File 'lib/alexandria/book_providers.rb', line 281
def self.unabstract
include Singleton
undef_method :reinitialize
undef_method :name=
undef_method :fullname=
undef_method :remove
end
|
Instance Method Details
#<=>(other) ⇒ Object
276
277
278
|
# File 'lib/alexandria/book_providers.rb', line 276
def <=>(other)
fullname <=> other.fullname
end
|
#abstract? ⇒ Boolean
268
269
270
|
# File 'lib/alexandria/book_providers.rb', line 268
def abstract?
self.class.abstract?
end
|
#action_name ⇒ Object
63
64
65
|
# File 'lib/alexandria/ui/init.rb', line 63
def action_name
"At" + name
end
|
#enabled ⇒ Object
211
212
213
|
# File 'lib/alexandria/book_providers.rb', line 211
def enabled
@prefs["enabled"]
end
|
#reinitialize(fullname) ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/alexandria/book_providers.rb', line 220
def reinitialize(fullname)
@name = "#{name}_#{fullname.hash}"
@fullname = fullname
prefs = Alexandria::Preferences.instance
ary = prefs.get_variable :abstract_providers
ary ||= []
ary << @name
prefs.set_variable :abstract_providers, ary
message = variable_name("name")
prefs.set_variable(message, @fullname)
end
|
#remove ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/alexandria/book_providers.rb', line 232
def remove
prefs = Alexandria::Preferences.instance
if (ary = prefs.get_variable :abstract_providers)
ary.delete(@name)
prefs.set_variable :abstract_providers, ary
end
if (ary = prefs.providers_priority) && ary.include?(@name)
ary.delete(@name)
prefs.providers_priority = ary
end
self.prefs.each do |variable|
name = variable_name(variable)
prefs.remove_preference(name)
end
name = variable_name("name")
prefs.remove_preference(name)
prefs.save!
end
|
#toggle_enabled ⇒ Object
215
216
217
218
|
# File 'lib/alexandria/book_providers.rb', line 215
def toggle_enabled
old_value = enabled
@prefs.variable_named("enabled").new_value = !old_value
end
|
#transport ⇒ Object
263
264
265
266
|
# File 'lib/alexandria/book_providers.rb', line 263
def transport
config = Alexandria::Preferences.instance.http_proxy_config
config ? Net::HTTP.Proxy(*config) : Net::HTTP
end
|
#variable_name(object) ⇒ Object
251
252
253
254
255
256
257
258
259
260
261
|
# File 'lib/alexandria/book_providers.rb', line 251
def variable_name(object)
s = case object
when String
object
when Preferences::Variable
object.name
else
raise
end
@name.downcase + "_" + s
end
|