nu 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/nu CHANGED
File without changes
@@ -39,6 +39,9 @@ module Nu
39
39
  log YAML.dump(@project_settings).gsub('!ruby/object:OpenStruct','').gsub(/\s*table:/,'').gsub('---','')
40
40
  log ""
41
41
  end
42
+
43
+ @lib_tools = Nu::LibTools.new
44
+ @gem_tools = Nu::GemTools.new
42
45
  end
43
46
 
44
47
  def self.store_setting(name, value)
@@ -72,7 +75,7 @@ module Nu
72
75
  end
73
76
 
74
77
  def self.version_string
75
- nu_spec = Nu::GemTools.spec_for("nu")
78
+ nu_spec = @gem_tools.spec_for("nu")
76
79
  "Nubular, version #{nu_spec.version}"
77
80
  end
78
81
 
@@ -88,7 +91,38 @@ module Nu
88
91
 
89
92
  def self.report()
90
93
  log "Report called."
91
- Nu::LibTools.read_specs_from_lib(@project_settings.lib.location)
94
+ @lib_tools.read_specs_from_lib(@project_settings.lib.location)
95
+ end
96
+
97
+ def self.retrieve_specification_with_version(name, version, source = {:from => :lib})
98
+ log "Retrieve Specification With Version called. Name: #{name} Version: #{version} Source: #{source}"
99
+
100
+ return case source[:from]
101
+ when :cache then
102
+ @gem_tools.spec_for(name, version)
103
+ when :remote then
104
+ @gem_tools.remote_spec_for(name, version)
105
+ else
106
+ raise "source can only be :cache, or :remote"
107
+ end
108
+ end
109
+
110
+ def self.retrieve_specification(name, source = {:from => :lib})
111
+ log "Retrieve Specification called. Name: #{name} Source: #{source}"
112
+
113
+ return case source[:from]
114
+ when :lib then
115
+ installed = @lib_tools.read_specs_from_lib(@project_settings.lib.location)
116
+ installed.select{|spec| spec.name == name}.first
117
+ when :cache then
118
+ @gem_tools.spec_for(name)
119
+ when :remote then
120
+ @gem_tools.remote_spec_for(name)
121
+ else
122
+ raise "source can only be :lib, :cache, or :remote"
123
+ end
124
+
125
+
92
126
  end
93
127
 
94
128
  private
@@ -23,15 +23,16 @@ class App
23
23
 
24
24
  @arguments = arguments
25
25
 
26
+ Nu::Api.set_log(lambda {|msg| log msg})
27
+ Nu::Api.set_out(lambda {|msg| disp msg})
28
+ @shim = CliShim.new(lambda {|msg| disp msg}, lambda {|msg| log msg})
29
+
26
30
  #special case, they want to know our version
27
31
  if arguments.length == 1 && (arguments[0] == '--version' || arguments[0] == '-v')
28
- output_version
32
+ @commands << lambda {output_version}
33
+ execute_commands
29
34
  exit 0
30
35
  end
31
-
32
- Nu::Api.set_log(lambda {|msg| log msg})
33
- Nu::Api.set_out(lambda {|msg| disp msg})
34
- @shim = CliShim.new(lambda {|msg| disp msg}, lambda {|msg| log msg})
35
36
 
36
37
  begin
37
38
  OptionParser.new do |opts|
@@ -57,14 +58,13 @@ class App
57
58
  end
58
59
 
59
60
  # Specify options
61
+ @options.source = :lib
62
+ opts.on('--remote', 'Use package server for query operations.') {@options.source = :remote}
63
+ opts.on('--cache', 'Use local package cache for query operations.') {@options.source = :cache unless @options.source == :remote}
60
64
  opts.on('-V', '--verbose') { @options.verbose = true }
61
65
  opts.on('-q', '--quiet') { @options.quiet = true }
62
66
  opts.on('--json', 'Run in JSON mode. All outputs will be in JSON, status messages silenced.') do
63
- @options.json = true
64
- @shim = JsonShim.new(lambda do |json|
65
- puts json
66
- log_to_file(json)
67
- end, lambda {|msg| log msg})
67
+ set_json
68
68
  end
69
69
 
70
70
  opts.on_tail( '-h', '--help', 'Display this screen' ) do
@@ -75,7 +75,9 @@ class App
75
75
 
76
76
  end.parse!
77
77
  rescue
78
- @help_command.call
78
+ @commands << @help_command
79
+ execute_commands
80
+ exit 0
79
81
  end
80
82
 
81
83
  post_process_options
@@ -87,29 +89,40 @@ class App
87
89
  if arguments_valid?
88
90
 
89
91
  log "Start at #{DateTime.now}\n\n"
90
- output_version if @options.verbose
91
92
  output_inputs if @options.verbose
92
93
 
93
- Nu::Api.load_project_settings('nuniverse.yaml')
94
-
95
- @commands.reverse.each {|command| command.call}
94
+ execute_commands
96
95
 
97
96
  log "\nFinished at #{DateTime.now}"
98
97
 
99
98
  else
100
- @help_command.call
99
+ @commands << @help_command
100
+ execute_commands
101
+ exit 0
101
102
  end
102
103
 
103
104
  end
104
105
 
105
106
  protected
106
107
 
108
+ def execute_commands
109
+ Nu::Api.load_project_settings('nuniverse.yaml')
110
+ @commands.reverse.each {|command| command.call}
111
+ end
112
+
107
113
  def extract_commands
108
114
  if @arguments.length > 0
109
115
  @options.command = @arguments[0].downcase
110
116
  case @options.command
111
117
  when 'report'
112
118
  @commands << lambda {@shim.report}
119
+ when 'specification'
120
+ if @options.source == :lib && @options.package_version
121
+ puts "The --version flag can not be used with the specification command unless either --cache or --remote is also specified."
122
+ exit 1
123
+ end
124
+ set_json
125
+ @commands << lambda {@shim.specification(@arguments[1], @options.package_version, @options.source)}
113
126
  when 'install'
114
127
  assert_param_count(2)
115
128
  @options.package = @arguments[1]
@@ -194,4 +207,12 @@ class App
194
207
  @file_logger.debug("#{DateTime.now} - #{msg.strip}")
195
208
  end
196
209
  end
210
+
211
+ def set_json
212
+ @options.json = true
213
+ @shim = JsonShim.new(lambda do |json|
214
+ puts json
215
+ log_to_file(json)
216
+ end, lambda {|msg| log msg})
217
+ end
197
218
  end
@@ -4,29 +4,42 @@ require 'yaml'
4
4
  module Nu
5
5
  class GemTools
6
6
 
7
- def self.spec_for(spec, requirement=nil)
7
+ def dependency_from_requirement(spec, requirement)
8
8
  unless requirement.respond_to?('satisfied_by?')
9
9
  requirement = Gem::Requirement.create(requirement)
10
10
  end
11
- dependency = Gem::Dependency.new(spec,requirement)
11
+ Gem::Dependency.new(spec,requirement)
12
+ end
13
+
14
+ def remote_spec_for(spec, requirement=nil)
15
+ dependency = dependency_from_requirement(spec, nil)
16
+ fetcher = Gem::SpecFetcher.new
17
+ specs = fetcher.fetch(dependency, true)
18
+ dependency = dependency_from_requirement(spec, requirement)
19
+ unless specs == nil
20
+ specs.map! do |item|
21
+ item.first
22
+ end
23
+ specs.sort! {|a,b| b.version <=> a.version}
24
+ specs.detect {|spec| spec.satisfies_requirement?(dependency)}
25
+ end
26
+ end
27
+
28
+ def spec_for(spec, requirement=nil)
29
+ dependency = dependency_from_requirement(spec, requirement)
12
30
  searcher = Gem::GemPathSearcher.new()
13
31
  all_installed_gems = searcher.init_gemspecs()
14
-
32
+
15
33
  return all_installed_gems.detect {|spec| spec.satisfies_requirement?(dependency)}
16
34
  end
17
35
 
18
- def self.lib_for(name, requirement=nil)
36
+ def lib_for(name, requirement=nil)
19
37
  spec = spec_for(name, requirement)
20
38
  gem_path = spec.full_gem_path
21
- libdir = File.join(gem_path,"lib")
22
- unless File.exist?(libdir)
23
- libdir = IO.readlines(File.join(gem_path, ".require_paths"))[0].strip
24
- libdir = File.expand_path(File.join(gem_path,libdir))
25
- end
26
- libdir
39
+ File.expand_path(File.join(gem_path,spec.require_paths.first))
27
40
  end
28
41
 
29
- def self.write_spec(spec, dest)
42
+ def write_spec(spec, dest)
30
43
  dest = File.expand_path(dest)
31
44
  dest = File.join(dest,'nu_spec.yaml')
32
45
 
@@ -17,4 +17,13 @@ class JsonShim < HasOutAndLog
17
17
  out ({:name => name, :value => Nu::Api.get_setting(name) }.to_json)
18
18
  end
19
19
 
20
+ def specification(name, version, source)
21
+ log "Json Shim Specification called. name: #{name} version: #{version} source:#{source}"
22
+ if version == nil
23
+ out Nu::Api.retrieve_specification(name, :from => source).to_json
24
+ else
25
+ out Nu::Api.retrieve_specification_with_version(name, version, :from => source).to_json
26
+ end
27
+ end
28
+
20
29
  end
@@ -3,14 +3,15 @@ require 'rubygems'
3
3
  module Nu
4
4
  class LibTools
5
5
 
6
- def self.folder_for(spec, lib, long_name=false)
6
+ def folder_for(spec, lib, long_name=false)
7
+ lib = File.expand_path(lib)
7
8
  if long_name
8
9
  name = spec.full_name
9
10
  else
10
11
  name = spec.name
11
12
  end
12
13
 
13
- to = Dir.pwd + "/#{lib}/#{name}"
14
+ to = "#{lib}/#{name}"
14
15
  if Dir[to] == [] #may need a smarter guy here
15
16
  FileUtils.mkpath to
16
17
  end
@@ -18,7 +19,7 @@ module Nu
18
19
  return to
19
20
  end
20
21
 
21
- def self.read_specs_from_lib(lib)
22
+ def read_specs_from_lib(lib)
22
23
  lib = File.expand_path(lib)
23
24
  glob = "#{lib}/**/nu_spec.yaml"
24
25
  files = Dir.glob(glob)
@@ -17,6 +17,8 @@ module Nu
17
17
  @gem_name = name
18
18
  @location = location
19
19
  @version = version
20
+ @lib_tools = Nu::LibTools.new
21
+ @gem_tools = Nu::GemTools.new
20
22
  super(out, log)
21
23
  end
22
24
 
@@ -47,13 +49,13 @@ module Nu
47
49
  log "Copy To: #{to}"
48
50
 
49
51
  FileUtils.copy_entry start_here, to
50
- Nu::GemTools.write_spec(gemspec, to)
52
+ @gem_tools.write_spec(gemspec, to)
51
53
 
52
54
  process_dependencies
53
55
  end
54
56
 
55
57
  def gemspec
56
- Nu::GemTools.spec_for(@gem_name, @version)
58
+ @gem_tools.spec_for(@gem_name, @version)
57
59
  end
58
60
 
59
61
  def gem_available?
@@ -65,11 +67,11 @@ module Nu
65
67
  end
66
68
 
67
69
  def copy_source
68
- Nu::GemTools.lib_for(@gem_name, @version).gsub '{lib}','lib'
70
+ @gem_tools.lib_for(@gem_name, @version).gsub '{lib}','lib'
69
71
  end
70
72
 
71
73
  def copy_dest
72
- Nu::LibTools.folder_for(gemspec, @location, @long_names)
74
+ @lib_tools.folder_for(gemspec, @location, @long_names)
73
75
  end
74
76
 
75
77
  def process_dependencies
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 4
10
- version: 0.2.4
9
+ - 5
10
+ version: 0.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dru Sellers
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-09-02 00:00:00 -05:00
21
+ date: 2010-09-10 00:00:00 -05:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency