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.
201
202
203
204
205
206
|
# File 'lib/alexandria/book_providers.rb', line 201
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.
199
200
201
|
# File 'lib/alexandria/book_providers.rb', line 199
def fullname
@fullname
end
|
#name ⇒ Object
Returns the value of attribute name.
199
200
201
|
# File 'lib/alexandria/book_providers.rb', line 199
def name
@name
end
|
#prefs ⇒ Object
Returns the value of attribute prefs.
198
199
200
|
# File 'lib/alexandria/book_providers.rb', line 198
def prefs
@prefs
end
|
Class Method Details
.abstract? ⇒ Boolean
269
270
271
|
# File 'lib/alexandria/book_providers.rb', line 269
def self.abstract?
!included_modules.include?(Singleton)
end
|
.unabstract ⇒ Object
FIXME: Clean up this complex abstract/concrete class system
278
279
280
281
282
283
284
|
# File 'lib/alexandria/book_providers.rb', line 278
def self.unabstract
include Singleton
undef_method :reinitialize
undef_method :name=
undef_method :fullname=
undef_method :remove
end
|
Instance Method Details
#<=>(other) ⇒ Object
273
274
275
|
# File 'lib/alexandria/book_providers.rb', line 273
def <=>(other)
fullname <=> other.fullname
end
|
#abstract? ⇒ Boolean
265
266
267
|
# File 'lib/alexandria/book_providers.rb', line 265
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
208
209
210
|
# File 'lib/alexandria/book_providers.rb', line 208
def enabled
@prefs["enabled"]
end
|
#reinitialize(fullname) ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/alexandria/book_providers.rb', line 217
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/alexandria/book_providers.rb', line 229
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
212
213
214
215
|
# File 'lib/alexandria/book_providers.rb', line 212
def toggle_enabled
old_value = enabled
@prefs.variable_named("enabled").new_value = !old_value
end
|
#transport ⇒ Object
260
261
262
263
|
# File 'lib/alexandria/book_providers.rb', line 260
def transport
config = Alexandria::Preferences.instance.http_proxy_config
config ? Net::HTTP.Proxy(*config) : Net::HTTP
end
|
#variable_name(object) ⇒ Object
248
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/alexandria/book_providers.rb', line 248
def variable_name(object)
s = case object
when String
object
when Preferences::Variable
object.name
else
raise
end
@name.downcase + "_" + s
end
|