Parent

Included Modules

Repositories

Attributes

source_cache[RW]

Public Class Methods

each(&block) click to toggle source
# File lib/commands/plugin/repositories.rb, line 125
def self.each(&block)
  self.instance.each(&block)
end
instance() click to toggle source
# File lib/commands/plugin/repositories.rb, line 120
def self.instance
  # TODO Use test cache file if $testing
  @instance ||= Repositories.new
end
new(cache_file = File.join(find_home, ".rails", "plugin_source_cache.yml")) click to toggle source
# File lib/commands/plugin/repositories.rb, line 8
def initialize(cache_file = File.join(find_home, ".rails", "plugin_source_cache.yml"))
  @cache_file = File.expand_path(cache_file)
  load!
end

Public Instance Methods

add(uri) click to toggle source
# File lib/commands/plugin/repositories.rb, line 17
def add(uri)
  unless find { |repo| repo.uri == uri }
    repository = Repository.new(uri)
    refresh_repository!(repository)
    @repositories.push(repository).last
  end
end
all() click to toggle source
# File lib/commands/plugin/repositories.rb, line 33
def all
  @repositories
end
cached_plugins() click to toggle source

List the known plugins from the sources cache.

# File lib/commands/plugin/repositories.rb, line 52
def cached_plugins
  @source_cache['plugins'].keys.sort.map do |plugin_name| 
    Plugin.new(@source_cache['plugins'][plugin_name]['plugin'], plugin_name)
  end
end
defaults() click to toggle source
# File lib/commands/plugin/repositories.rb, line 95
def defaults
  {
    'repositories' => ['http://dev.rubyonrails.com/svn/rails/plugins/'],
    'plugins' => {}
    }
end
each(&block) click to toggle source
# File lib/commands/plugin/repositories.rb, line 13
def each(&block)
  @repositories.each(&block)
end
exist?(uri) click to toggle source
# File lib/commands/plugin/repositories.rb, line 29
def exist?(uri)
  @repositories.detect{|repo| repo.uri == uri }
end
find_home() click to toggle source
# File lib/commands/plugin/repositories.rb, line 102
def find_home
  ['HOME', 'USERPROFILE'].each do |homekey|
    return ENV[homekey] if ENV[homekey]
  end
  if ENV['HOMEDRIVE'] && ENV['HOMEPATH']
    return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}"
  end
  begin
    File.expand_path("~")
  rescue StandardError => ex
    if File::ALT_SEPARATOR
      "C:/"
    else
      "/"
    end
  end
end
find_plugin(name) click to toggle source
# File lib/commands/plugin/repositories.rb, line 37
def find_plugin(name)
  # Try to get plugin from cache first
  if @source_cache['plugins'].has_key?(name) && @source_cache['plugins'][name].has_key?('plugin')
    return Plugin.new(@source_cache['plugins'][name]['plugin'], name)
  end
  
  @repositories.each do |repo|
    repo.each do |plugin|
      return plugin if plugin.name == name
    end
  end
  return nil
end
load!() click to toggle source
# File lib/commands/plugin/repositories.rb, line 80
def load!
  @source_cache = File.exist?(@cache_file) ? YAML.load(File.read(@cache_file)) : defaults
  @source_cache = defaults if @source_cache.keys.nil?
  @repositories = @source_cache['repositories'].map { |source| Repository.new(source.strip) }
end
plugin_count() click to toggle source

Returns the number of known plugins in the cache.

# File lib/commands/plugin/repositories.rb, line 59
def plugin_count
  source_cache['plugins'].keys.length
rescue
  0
end
refresh!() click to toggle source

Gets the updated list of plugins available at each repository.

# File lib/commands/plugin/repositories.rb, line 66
def refresh!
  @repositories.each { |repo| refresh_repository!(repo) }
end
refresh_repository!(repository) click to toggle source

Gets the list of plugins available at this repository.

# File lib/commands/plugin/repositories.rb, line 71
def refresh_repository!(repository)
  repository.plugins.each do |plugin|
    if about_hash = plugin.about(true)
      @source_cache['plugins'][plugin.name] = about_hash
    end
  end    
end
remove(uri) click to toggle source
# File lib/commands/plugin/repositories.rb, line 25
def remove(uri)
  @repositories.reject!{|repo| repo.uri == uri}
end
save() click to toggle source
# File lib/commands/plugin/repositories.rb, line 86
def save
  mkdir_p(File.dirname(@cache_file)) unless File.exist?(File.dirname(@cache_file))
  File.open(@cache_file, 'w') do |f|
    @source_cache['repositories'] = @repositories.map {|r| r.uri }.uniq
    f.write(@source_cache.to_yaml)
    f.write("\n")
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.