Module: Indexer::Conversion
- Included in:
- Metadata
- Defined in:
- lib/indexer/conversion.rb,
lib/indexer/conversion/gemfile.rb,
lib/indexer/conversion/gemspec.rb
Overview
Conversion module provides routines for converting other metadata sources to and from index format.
Instance Method Summary collapse
-
#import_gemfile(file = nil) ⇒ Object
(also: #gemfile)
Update Spec with a Gemfile.
-
#import_gemspec(gemspec) ⇒ Object
Import a Gem::Specification into Spec.
-
#to_gemspec(options = {}) ⇒ Object
Create a Gem::Specification from Metadata.
Instance Method Details
#import_gemfile(file = nil) ⇒ Object Also known as: gemfile
Update Spec with a Gemfile.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/indexer/conversion/gemfile.rb', line 11 def import_gemfile(file=nil) require 'bundler' case file when String # FIXME: Is this the correct way to load a gemfile? bundle = ::Bundler::Dsl.new bundle.eval_gemfile(file) when NilClass bundle = ::Bundler.definition end begin merge!(bundle..to_h) rescue end bundle.dependencies.each do |d| add_requirement(d.name, :version => d.requirement.to_s, # may need to parse this :groups => d.groups, :development => (d.type == :development) #:engines => d.platforms ? #:platforms => ? ) end end |
#import_gemspec(gemspec) ⇒ Object
Ensure all data possible is gathered from the gemspec.
Import a Gem::Specification into Spec. This is intended to make it
fairly easy to build the metadata from a pre-existing .gemspec
.
By making this an instance method, it is possible to import other
resources into the Spec prior to a .gemspec
.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/indexer/conversion/gemspec.rb', line 50 def import_gemspec(gemspec) require 'rubygems' if not Gem::Specification === gemspec # TODO: YAML-based gem specs ? gemspec = Gem::Specification.load(gemspec) end # TODO: ensure this is robust = ( zip = [gemspec.].flatten.zip([gemspec.email].flatten) zip.map do |(name, email)| email ? {:name=>name, :email=>email} : {:name=>name} end ) # TODO: how to handle license(s) ? self.name = gemspec.name self.version = gemspec.version.to_s self.date = gemspec.date self.title = gemspec.name.capitalize self.summary = gemspec.summary self.description = gemspec.description || gemspec.summary self. = self.paths['load'] = gemspec.require_paths self.homepage = gemspec.homepage #self.engines = gemspec.platform #self.extensions = gemspec.extensions # TODO: Spec currently doesn't support multiple constraints for requirements. # Probably 99.999% of the time it doesn't matter. gemspec.dependencies.each do |d| if d.type == :runtime add_requirement(d.name, :versions=>d.requirements_list.first) else add_requirement(d.name, :versions=>d.requirements_list.first, :development=>true) end end end |
#to_gemspec(options = {}) ⇒ Object
Create a Gem::Specification from Metadata.
Becuase the specificaiton is extensive, a Gem::Specification can be created that is sufficient for most needs. However, there are a few points where the two do not intersect. In these cases the remaining gemspec fields need to be provided post conversion.
Gem::Specification fields that the specification can't provide include:
- platform
In addition, some information can only be provided if a project's root
directory is given. In these cases the most common project conventions
are utilized in determining field values. Gem::Specification fields that
draw from project files include:
- files
- bindir
- extensions
- rdoc_options
- rdoc_extra_files
Any or all of which can be reassigned post conversion, if need be.
36 37 38 39 |
# File 'lib/indexer/conversion/gemspec.rb', line 36 def to_gemspec(={}) [:data] = self.to_h GemspecExporter.new().to_gemspec end |