qwandry 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -14,6 +14,18 @@ module Qwandry
14
14
  builders[name] << block
15
15
  end
16
16
 
17
+ # Registers a configuration is a specific binary is available. If `binary` is not specified,
18
+ # it is assumed to be the same as the configuration name.
19
+ def register_if_present name, binary=nil, &block
20
+ binary ||= name
21
+ register(name, &block) if present? binary
22
+ end
23
+
24
+ # Returns true if binary `name` is present.
25
+ def present? name
26
+ system("which #{name}", STDOUT=>"/dev/null")
27
+ end
28
+
17
29
  # Sets the default configuration to launch, if no `configurations` are passed
18
30
  # in, it returns their names.
19
31
  def default(*configurations)
@@ -30,7 +42,7 @@ module Qwandry
30
42
  end
31
43
 
32
44
  # Loads a configuration file, and executes it in the context of the Qwandry::Configuration
33
- # class. See default_configuration.rb for an example, or run:
45
+ # class. See `configuration/default.rb` for an example, or run:
34
46
  #
35
47
  # qw --customize
36
48
  #
@@ -9,7 +9,7 @@ register :ruby do
9
9
  end
10
10
 
11
11
  # Register the default ruby gems configuration:
12
- register :gem do
12
+ register_if_present :gem do
13
13
  # Get the gem paths from the ruby load paths:
14
14
  paths = ($:).grep(/gems/).map{|p| p[/.+\/gems\//]}.uniq
15
15
 
@@ -18,7 +18,7 @@ register :gem do
18
18
  end
19
19
 
20
20
  # Register a perl configuration:
21
- register :perl do
21
+ register_if_present :perl do
22
22
  # Execute a perl script to find all of the perl load paths:
23
23
  perl_paths = `perl -e 'foreach $k (@INC){print $k,"\n";}'` rescue ''
24
24
 
@@ -30,7 +30,7 @@ register :perl do
30
30
  end
31
31
 
32
32
  # Add python repositories:
33
- register :python do
33
+ register_if_present :python do
34
34
  # Execute a python script to find all of the python load paths:
35
35
  python_paths = `python -c 'import sys;print(\"\\n\".join(sys.path))'` rescue ''
36
36
 
@@ -42,7 +42,7 @@ register :python do
42
42
  end
43
43
 
44
44
  # Add node.js repositories:
45
- register :node do
45
+ register_if_present :node do
46
46
  # Execute a node script to find all of the load paths:
47
47
  node_script_path = File.join(File.dirname(__FILE__),'probe_node.js')
48
48
  node_paths = `node #{node_script_path}` rescue ''
@@ -52,6 +52,24 @@ register :node do
52
52
  add node_paths
53
53
  end
54
54
 
55
+ # If this is mri ruby and we can figure out where the user's ruby source directory is, add it.
56
+ # This might not be quite right...
57
+ #
58
+ # TODO figure out how to identify different ruby variants.
59
+ if RUBY_ENGINE == 'ruby'
60
+ register_if_present :mri, :rvm do
61
+ # If present, use the current rvm's ruby source.
62
+ paths = []
63
+ root = File.join(ENV['rvm_src_path'], ENV['rvm_ruby_string'])
64
+ paths << root # core objects: String, etc
65
+ paths << File.join(root, 'ext') # c extensions: Fiber, IO, etc.
66
+ paths << File.join(root, 'lib') # pure ruby libraries
67
+
68
+ # Add the sources, use a LibraryRepository to bundle .h and .c files
69
+ add paths, :reject=>/\.(o|a|s|inc|def|dylib)$/, :class=>Qwandry::LibraryRepository
70
+ end
71
+ end
72
+
55
73
  # Qwandry is a ruby app after all, so activate ruby and gem by default. Other defaults can be set
56
74
  # with a custom init.rb
57
75
  default :ruby, :gem
@@ -11,7 +11,7 @@ module Qwandry
11
11
  def scan(pattern)
12
12
  results = []
13
13
  all_paths.select do |path|
14
- if File.fnmatch?(pattern, File.basename(path))
14
+ if File.fnmatch?(pattern, File.basename(path), File::FNM_CASEFOLD)
15
15
  results << package(File.basename(path), [path])
16
16
  end
17
17
  end
@@ -18,6 +18,7 @@ module Qwandry
18
18
  packages.concat(repo.scan(pattern))
19
19
  end
20
20
 
21
+ differentiate packages
21
22
  packages
22
23
  end
23
24
 
@@ -38,6 +39,20 @@ module Qwandry
38
39
  # Launch the editor with its options and any paths that we have been passed
39
40
  system(*(editor_and_options + paths))
40
41
  end
41
-
42
+
43
+ private
44
+
45
+ # If there are multiple packages named the same, append their path to the name.
46
+ # This could later be handled in other ways, for instance by merging the paths.
47
+ def differentiate(packages)
48
+ named_groups = Hash.new{|h,k| h[k] = []}
49
+ packages.each{|p| named_groups[p.name] << p }
50
+ named_groups.each do |name, packages|
51
+ if packages.length > 1
52
+ packages.each{|p| p.name = "#{p.name} (#{p.paths.first})"}
53
+ end
54
+ end
55
+ end
56
+
42
57
  end
43
58
  end
@@ -14,7 +14,7 @@ module Qwandry
14
14
  results = Hash.new{|h,k| h[k] = package(k)}
15
15
  all_paths.select do |path|
16
16
  basename = File.basename(path)
17
- if File.fnmatch?(pattern, basename)
17
+ if File.fnmatch?(pattern, basename, File::FNM_CASEFOLD)
18
18
  # strip any file extension
19
19
  basename.sub! /\.\w+$/,'' unless File.directory?(path)
20
20
  results[basename].paths << path
@@ -1,8 +1,8 @@
1
1
  module Qwandry
2
2
  class Package
3
- attr_reader :name
4
- attr_reader :paths
5
- attr_reader :repository
3
+ attr_accessor :name
4
+ attr_accessor :paths
5
+ attr_reader :repository
6
6
 
7
7
  def initialize(name, paths, repository)
8
8
  @name = name
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qwandry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Sanderson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-30 00:00:00 -07:00
18
+ date: 2011-01-01 00:00:00 -07:00
19
19
  default_executable: qw
20
20
  dependencies: []
21
21