Class: Nu::GemTools
- Inherits:
-
Object
- Object
- Nu::GemTools
- Defined in:
- lib/nu/gem_tools.rb
Instance Method Summary collapse
- #dependency_from_requirement(spec, requirement) ⇒ Object
- #find(package_name, requirement = nil) ⇒ Object
- #lib_for(name, requirement = nil) ⇒ Object
- #remote_spec_for(spec, requirement = nil) ⇒ Object
- #spec_for(spec, requirement = nil) ⇒ Object
- #write_spec(spec, dest) ⇒ Object
Instance Method Details
#dependency_from_requirement(spec, requirement) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/nu/gem_tools.rb', line 7 def dependency_from_requirement(spec, requirement) unless requirement.respond_to?('satisfied_by?') requirement = Gem::Requirement.create(requirement) end Gem::Dependency.new(spec,requirement) end |
#find(package_name, requirement = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/nu/gem_tools.rb', line 14 def find(package_name, requirement=nil) dependency = dependency_from_requirement(package_name, nil) fetcher = Gem::SpecFetcher.new specs = fetcher.fetch(dependency, true) unless specs == nil specs.map! do |item| item.first end specs.sort! {|a,b| b.version <=> a.version} end return specs unless requirement return specs.detect {|spec| spec.satisfies_requirement?(dependency)} if requirement end |
#lib_for(name, requirement = nil) ⇒ Object
50 51 52 53 54 |
# File 'lib/nu/gem_tools.rb', line 50 def lib_for(name, requirement=nil) spec = spec_for(name, requirement) gem_path = spec.full_gem_path File.(File.join(gem_path,spec.require_paths.first)) end |
#remote_spec_for(spec, requirement = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nu/gem_tools.rb', line 28 def remote_spec_for(spec, requirement=nil) dependency = dependency_from_requirement(spec, nil) fetcher = Gem::SpecFetcher.new specs = fetcher.fetch(dependency, true) dependency = dependency_from_requirement(spec, requirement) unless specs == nil specs.map! do |item| item.first end specs.sort! {|a,b| b.version <=> a.version} specs.detect {|spec| spec.satisfies_requirement?(dependency)} end end |
#spec_for(spec, requirement = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/nu/gem_tools.rb', line 42 def spec_for(spec, requirement=nil) dependency = dependency_from_requirement(spec, requirement) searcher = Gem::GemPathSearcher.new() all_installed_gems = searcher.init_gemspecs() return all_installed_gems.detect {|spec| spec.satisfies_requirement?(dependency)} end |
#write_spec(spec, dest) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nu/gem_tools.rb', line 56 def write_spec(spec, dest) dest = File.(dest) dest = File.join(dest,'nu_spec.yaml') unless spec.is_a?(Gem::Specification) spec = spec_for(spec) end File.open( dest, 'w' ) do |out| YAML.dump(spec, out) end end |