lib/sdoc_all/gems.rb in sdoc_all-0.1.0 vs lib/sdoc_all/gems.rb in sdoc_all-0.2.0.1

- old
+ new

@@ -1,28 +1,54 @@ -require 'enumerator' - class SdocAll class Gems < Base - def self.each(&block) - Gem.source_index.each(&block) - end + def initialize(config) + config ||= {} + config = {:only => config} unless config.is_a?(Hash) - def self.update_sources(options = {}) + @config = { + :versions => config.delete(:versions).to_s.downcase, + :only => config_only_option(config), + :exclude => config_exclude_option(config), + } + + raise_unknown_options_if_not_blank!(config) end - def self.add_rdoc_tasks(options = {}) - each do |gem_name, spec| + def add_tasks(options = {}) + specs = config[:versions] == 'all' ? self.class.all_specs : self.class.latest_specs + + specs.sort_by!{ |spec| [spec.name.downcase, spec.sort_obj] } + + specs.delete_if{ |spec| !config[:only].include?(spec.name.downcase) } if config[:only] + specs.delete_if{ |spec| config[:exclude].include?(spec.name.downcase) } + + specs.each do |spec| main = nil spec.rdoc_options.each_cons(2) do |options| main = options[1] if %w(--main -m).include?(options[0]) end - add_rdoc_task( - :name_parts => [spec.name, spec.version], + Base.add_task( :src_path => spec.full_gem_path, - :doc_path => "gems/#{gem_name}", - :pathes => spec.require_paths + spec.extra_rdoc_files, - :main => main + :doc_path => "gems.#{spec.full_name}", + :paths => spec.require_paths + spec.extra_rdoc_files, + :main => main, + :title => "gems: #{spec.full_name}" ) end end + + module ClassMethods + def latest_specs + Gem.source_index.latest_specs + end + + def all_specs + specs = [] + Gem.source_index.each do |_, spec| + specs << spec + end + specs + end + end + extend ClassMethods end end