Sha256: 9c0d489c41fd05e3674d680bec7bce73005ee6319bd46166f1d4f75127b1e623

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'net/http'
require 'tempfile'
require 'yaml'

module Doc
  class Configurator
    class Ruby
      module Stdlib
        STDLIB_CONFIG_URL = 'http://stdlib-doc.rubyforge.org/svn/trunk/data/gendoc.yaml'
        STDLIB_CONFIG_NAME = 'stdlib-config.yaml'
        STDLIB_CONFIG_VENDOR_PATH = FSPath(__FILE__).dirname / '../../../../vendor' / STDLIB_CONFIG_NAME

        def stdlib_config(update)
          if update || !read_stdlib_config
            download_stdlib_config
          end
          read_stdlib_config || YAML.load_file(STDLIB_CONFIG_VENDOR_PATH)
        end

        def stdlib_config_path
          sources_dir / STDLIB_CONFIG_NAME
        end

        def read_stdlib_config
          YAML.load_file stdlib_config_path if stdlib_config_path.size?
        end

        def download_stdlib_config
          url = URI.parse(STDLIB_CONFIG_URL)
          response = Net::HTTP.start(url.host, url.port){ |http| http.get(url.path) }
          if response.kind_of?(Net::HTTPSuccess)
            stdlib_config_path.write(response.body)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doc-0.5.0 lib/doc/configurator/ruby/stdlib.rb
doc-0.4.1 lib/doc/configurator/ruby/stdlib.rb