nu 0.1.17 → 0.1.18

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
data/lib/nu/cli.rb CHANGED
@@ -4,46 +4,54 @@ require 'yaml'
4
4
 
5
5
  module Nu
6
6
  class CLI < Thor
7
- include Thor::Actions
8
-
9
- def initialize(*)
10
- super
11
-
12
- @proj = Nu::Project.new
13
- end
14
-
7
+ include Thor::Actions
8
+
9
+ def initialize(*)
10
+ super
11
+
12
+ @proj = Nu::Project.new
13
+ end
14
+
15
15
  desc "install GEMNAME", "installs a gem in the 'pwd'"
16
- method_options :location => :string
17
-
18
- def install(*names)
19
-
20
- loc = @proj.location
21
- cl = options['location']
22
- loc = cl unless cl.nil?
23
-
24
- names.each do |n|
25
- Nu::Loader.load n, loc
26
- end
16
+ method_options :location => :string, :version => :string
17
+
18
+ def install(*names)
19
+
20
+ loc = @proj.location
21
+ cl = options['location']
22
+ ver = options['version']
23
+
24
+ loc = cl unless cl.nil?
25
+
26
+ names.each do |n|
27
+ loader = Nu::Loader.new(n, loc, ver)
28
+ loader.copy_to_lib
27
29
  end
28
-
29
- desc "lib FOLDER", "where do you want to store the gems"
30
- def lib(folder)
31
- @proj.location= folder
32
- end
33
-
34
- desc "uselongnames", "turn the option of name + version number on"
35
- def uselongnames
36
- @proj.use_long_names
37
- end
38
-
39
- desc "useshortnames", "turn the option of name + version number off"
40
- def useshortnames
41
- @proj.use_short_names
42
- end
43
-
44
- def self.source_root
45
- File.dirname(__FILE__)
46
- end
47
-
30
+ end
31
+
32
+ desc "uninstall GEM", "remove the specified gem from the lib folder"
33
+ def uninstall(gem)
34
+
35
+ end
36
+
37
+ desc "lib FOLDER", "where do you want to store the gems"
38
+ def lib(folder)
39
+ @proj.location= folder
40
+ end
41
+
42
+ desc "uselongnames", "turn the option of name + version number on"
43
+ def uselongnames
44
+ @proj.use_long_names
45
+ end
46
+
47
+ desc "useshortnames", "turn the option of name + version number off"
48
+ def useshortnames
49
+ @proj.use_short_names
50
+ end
51
+
52
+ def self.source_root
53
+ File.dirname(__FILE__)
54
+ end
55
+
48
56
  end
49
57
  end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+
3
+ module Nu
4
+ class GemTools
5
+
6
+ def self.spec_for(name, requirement=nil)
7
+ unless requirement.respond_to?('satisfied_by?')
8
+ requirement = Gem::Requirement.create(requirement)
9
+ end
10
+ dependency = Gem::Dependency.new(name,requirement)
11
+ searcher = Gem::GemPathSearcher.new()
12
+ all_installed_gems = searcher.init_gemspecs()
13
+
14
+ return all_installed_gems.detect {|spec| spec.satisfies_requirement?(dependency)}
15
+ end
16
+
17
+ def self.lib_for(name, requirement=nil)
18
+ gem = spec_for(name, requirement)
19
+ gem_path = gem.full_gem_path
20
+ libdir = File.join(gem_path,"lib")
21
+ unless File.exist?(libdir)
22
+ libdir = IO.readlines(File.join(gem_path, ".require_paths"))[0].strip
23
+ libdir = File.expand_path(File.join(gem_path,libdir))
24
+ end
25
+ libdir
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+
3
+ module Nu
4
+ class LibTools
5
+
6
+ def self.gemspec_for(name)
7
+ gems = Gem.source_index.find_name name
8
+ return gems.last if gems.length > 0
9
+ end
10
+
11
+ def self.folder_name_for(gem_name, lib, long_name=false)
12
+ spec = gemspec_for(gem_name)
13
+
14
+ if long_name
15
+ name = spec.full_name
16
+ else
17
+ name = spec.name
18
+ end
19
+ Dir.pwd + "/#{lib}/#{name}"
20
+ end
21
+ end
22
+ end
data/lib/nu/loader.rb CHANGED
@@ -1,103 +1,92 @@
1
1
  require 'rubygems'
2
2
  require 'rubygems/dependency_installer'
3
+ require File.expand_path(File.dirname(__FILE__) + "/lib_tools.rb")
4
+ require File.expand_path(File.dirname(__FILE__) + "/gem_tools.rb")
5
+ require File.expand_path(File.dirname(__FILE__) + "/project.rb")
3
6
 
4
7
  module Nu
5
8
  class Loader
6
9
 
7
- def self.load(name)
8
- load(name, 'lib')
9
- end
10
-
11
- def self.load(name, location)
10
+ attr :gem_name
11
+ attr :location
12
+ attr :version
13
+
14
+ def initialize(name, location, version)
12
15
  #improve the crap out of this
13
- @gem_to_copy = name
14
- @location = location
16
+ @gem_name = name
17
+ @location = location
18
+ @version = version
15
19
 
16
-
17
- if !Gem.available? @gem_to_copy
18
- puts "Gem unavailable - trying to install"
19
- begin
20
- inst = Gem::DependencyInstaller.new
21
- inst.install @gem_to_copy
22
- inst.installed_gems.each do |spec|
23
- puts "Successfully installed #{spec.full_name}"
24
- end
25
- rescue Gem::GemNotFoundException => e
26
- puts "ERROR: #{e.message}"
27
- return #GTFO
28
- end
20
+ if !gem_available?
21
+ puts "Gem #{@gem_name} #{@version} is not installed locally - I am now going to try and install it"
22
+ begin
23
+ inst = Gem::DependencyInstaller.new
24
+ inst.install @gem_name, @version
25
+ inst.installed_gems.each do |spec|
26
+ puts "Successfully installed #{spec.full_name}"
27
+ end
28
+ rescue Gem::GemNotFoundException => e
29
+ puts "ERROR: #{e.message}"
30
+ return #GTFO
31
+ end
29
32
  else
30
33
  puts "Found Gem"
31
34
  end
32
35
  #TODO: better error handling flow control for above
33
-
34
-
35
- start_here = get_copy_from()
36
- puts "Copy From: #{start_here}"
37
-
38
- to = get_copy_to()
39
- puts "Copy To: #{to}"
40
-
41
- FileUtils.copy_entry start_here, to
42
-
43
- process_dependencies
44
- end
45
-
46
- def self.get_libdir(name)
47
- g = get_gemspec name
48
- #puts "GemSpec #{g.full_gem_path}"
49
- l = g.full_gem_path
50
- d = File.join(l,"lib")
51
- #puts d
52
- d
53
- end
54
-
55
- def self.get_gemspec(name)
56
- gems = Gem.source_index.find_name name
57
- return gems.last if gems.length > 0
58
36
  end
59
-
60
- def self.get_copy_from
61
- libdir = get_libdir @gem_to_copy
62
- #puts File.expand_path libdir
63
- #try Dir.glob("{bin,lib}/**/*")
64
- libdir.gsub '{lib}','lib'
65
- end
66
-
67
- def self.get_files
68
- spec = get_gemspec @gem_to_copy
69
- files = spec.lib_files #get full path
70
- files
37
+
38
+ def copy_to_lib
39
+ start_here = copy_source
40
+ puts "Copy From: #{start_here}"
41
+
42
+ to = copy_dest
43
+ puts "Copy To: #{to}"
44
+
45
+ FileUtils.copy_entry start_here, to
46
+
47
+ process_dependencies
48
+ end
49
+
50
+ def gemspec
51
+ Nu::GemTools.spec_for(@gem_name, @version)
52
+ end
53
+
54
+ def gem_available?
55
+ Gem.available? @gem_name, @version
56
+ end
57
+
58
+ def copy_source
59
+ Nu::GemTools.lib_for(@gem_name, @version).gsub '{lib}','lib'
71
60
  end
72
-
73
- def self.get_copy_to
74
- proj = Nu::Project.new
75
-
76
- spec = get_gemspec @gem_to_copy
61
+
62
+ def copy_dest
63
+ proj = Nu::Project.new
64
+
77
65
  #to be used in copying
78
- if proj.should_use_long_names?
79
- name = spec.full_name
80
- else
81
- name = spec.name
82
- end
66
+ if proj.should_use_long_names?
67
+ name = gemspec.full_name
68
+ else
69
+ name = gemspec.name
70
+ end
83
71
  to = Dir.pwd + "/#{@location}/#{name}"
84
72
  if Dir[to] == [] #may need a smarter guy here
85
73
  FileUtils.mkpath to
86
74
  end
87
75
  to
88
76
  end
89
-
90
- def self.process_dependencies
91
- spec = get_gemspec @gem_to_copy
92
- spec.dependencies.each do |d|
93
- if Gem.available? d.name
94
- puts "loading #{d.name}"
95
- load d.name, @location
96
- else
97
- puts "#{d.name} is not installed locally"
98
- puts "please run 'gem install #{d.name}"
99
- end
100
- end
101
- end
77
+
78
+ def process_dependencies
79
+ gemspec.dependencies.each do |d|
80
+ if Gem.available? d.name
81
+ puts "Loading dependency: #{d.name} #{d.requirement}"
82
+ loader = Loader.new(d.name, @location, d.requirement)
83
+ loader.copy_to_lib
84
+ else
85
+ puts "#{d.name} is not installed locally"
86
+ puts "please run 'gem install #{d.name}"
87
+ end
88
+ end
89
+ end
90
+
102
91
  end
103
92
  end
data/lib/nu/project.rb CHANGED
@@ -2,74 +2,73 @@ require 'FileUtils'
2
2
 
3
3
  module Nu
4
4
  class Project
5
-
5
+
6
6
  def initialize
7
7
  @config_file = ".nu/options.yaml"
8
- ensure_default_config
8
+ ensure_default_config
9
9
  end
10
10
 
11
-
12
-
13
- #need to meta awesome this
11
+ # need to meta awesome this
14
12
  def location
15
- opts = get_options
16
- opts['lib']
17
- end
18
- #need to meta awesome this
19
- def location=(name)
20
- opts = get_options
21
- opts['lib']=name
22
- save_file(opts)
23
- nil
13
+ opts = get_options
14
+ opts['lib']
15
+ end
16
+
17
+ # need to meta awesome this
18
+ def location=(name)
19
+ opts = get_options
20
+ opts['lib']=name
21
+ save_file(opts)
22
+ nil
23
+ end
24
+
25
+ #need to meta awesome this
26
+ def should_use_long_names?
27
+ opts = get_options
28
+ opts['uselongnames']
29
+ end
30
+
31
+ #need to meta awesome this
32
+ def use_long_names
33
+ opts = get_options
34
+ opts['uselongnames']=true
35
+ save_file(opts)
36
+ nil
37
+ end
38
+
39
+ #need to meta awesome this
40
+ def use_short_names
41
+ opts = get_options
42
+ opts['uselongnames']=false
43
+ save_file(opts)
44
+ nil
24
45
  end
25
-
26
- #need to meta awesome this
27
- def should_use_long_names?
28
- opts = get_options
29
- opts['uselongnames']
30
- end
31
-
32
- #need to meta awesome this
33
- def use_long_names
34
- opts = get_options
35
- opts['uselongnames']=true
36
- save_file(opts)
37
- nil
38
- end
39
- #need to meta awesome this
40
- def use_short_names
41
- opts = get_options
42
- opts['uselongnames']=false
43
- save_file(opts)
44
- nil
45
- end
46
-
47
-
46
+
48
47
  def add_file(name, content)
49
48
  FileUtils.mkdir_p(File.dirname(name))
50
49
  File.open(name, 'w'){|f| f.write(content)}
51
50
  end
52
-
53
- private
54
- def ensure_default_config
55
- if File.exist? @config_file
56
- return
57
- end
58
-
59
- save_file( {'lib'=>'lib','uselongnames'=>false} )
60
- end
61
-
62
- def get_options
63
- YAML.load_file @config_file
64
- end
65
-
66
- def save_file(opts)
67
- content = YAML::dump(opts)
68
- File.delete @config_file if File.exist? @config_file
69
- dir_name = File.dirname(@config_file)
70
- FileUtils.mkdir_p(dir_name) unless File.exist? dir_name
71
- File.open(@config_file, 'w') {|f| f.write(content) }
72
- end
73
-
51
+
52
+ private
53
+ def ensure_default_config
54
+ if File.exist? @config_file
55
+ return
56
+ end
57
+
58
+ save_file( {'lib'=>'lib','uselongnames'=>false} )
59
+ end
60
+
61
+ def get_options
62
+ YAML.load_file @config_file
63
+ end
64
+
65
+ def save_file(opts)
66
+ content = YAML::dump(opts)
67
+ File.delete @config_file if File.exist? @config_file
68
+ dir_name = File.dirname(@config_file)
69
+ FileUtils.mkdir_p(dir_name) unless File.exist? dir_name
70
+ File.open(@config_file, 'w') {|f| f.write(content) }
71
+ end
72
+
74
73
  end
75
- end
74
+ end
metadata CHANGED
@@ -1,23 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 17
10
- version: 0.1.17
9
+ - 18
10
+ version: 0.1.18
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dru Sellers
14
14
  - Chris Patterson
15
15
  - Rob Reynold
16
+ - Travis Smith
16
17
  autorequire:
17
18
  bindir: bin
18
19
  cert_chain: []
19
20
 
20
- date: 2010-07-22 00:00:00 -05:00
21
+ date: 2010-08-25 00:00:00 -05:00
21
22
  default_executable:
22
23
  dependencies:
23
24
  - !ruby/object:Gem::Dependency
@@ -49,6 +50,8 @@ files:
49
50
  - bin/nu
50
51
  - lib/nu/cli.rb
51
52
  - lib/nu/config.rb
53
+ - lib/nu/gem_tools.rb
54
+ - lib/nu/lib_tools.rb
52
55
  - lib/nu/loader.rb
53
56
  - lib/nu/project.rb
54
57
  - lib/nu.rb