class Alexandria::BookProviders::AbstractProvider

Attributes

fullname[RW]
name[RW]
prefs[R]

Public Class Methods

abstract?() click to toggle source
# File lib/alexandria/book_providers.rb, line 269
def self.abstract?
  !included_modules.include?(Singleton)
end
new(name, fullname = nil) click to toggle source
# 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
unabstract() click to toggle source

FIXME: Clean up this complex abstract/concrete class system

# 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

Public Instance Methods

<=>(other) click to toggle source
# File lib/alexandria/book_providers.rb, line 273
def <=>(other)
  fullname <=> other.fullname
end
abstract?() click to toggle source
# File lib/alexandria/book_providers.rb, line 265
def abstract?
  self.class.abstract?
end
action_name() click to toggle source
# File lib/alexandria/ui/init.rb, line 63
def action_name
  "At" + name
end
enabled() click to toggle source
# File lib/alexandria/book_providers.rb, line 208
def enabled
  @prefs["enabled"]
end
reinitialize(fullname) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/alexandria/book_providers.rb, line 212
def toggle_enabled
  old_value = enabled
  @prefs.variable_named("enabled").new_value = !old_value
end
transport() click to toggle source
# 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) click to toggle source
# 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