mlightner-require_directory 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Test the library.'
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = true
10
+ end
11
+ task :default => [':test']
12
+
13
+ desc "Update gem files list"
14
+ task :gemfiles do
15
+ file_name = "require_directory.gemspec"
16
+ files = `find ./ | grep -v \.git`.each_line.collect { |f| f.strip }.reject { |e| e =~ /^[^\W]*$$/ }
17
+ files.shift
18
+ file = File.new(file_name)
19
+ lines = file.readlines
20
+ file.close
21
+
22
+ newf = []
23
+ lines.each do |line|
24
+ if line =~ /^\s+s\.files\s*\=/
25
+ newf.push " s.files = [\"#{files.join('","')}\"]\n"
26
+ else
27
+ newf.push(line.rstrip + "\n")
28
+ end
29
+ end
30
+
31
+ # Don't write the file if there are no changes
32
+ file = File.new(file_name,'w')
33
+ newf.each do |line|
34
+ file.write(line)
35
+ end
36
+ file.close
37
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Kernel
4
+
5
+ # Require all the ruby files in a directory (which must be in the load path
6
+ def require_directory(dir, add_to_load_path = false, skip_invalid_syntax = false)
7
+ raise "Not a directory: #{dir}" unless File.directory?(dir)
8
+ if add_to_load_path
9
+ $LOAD_PATH << dir
10
+ end
11
+ Dir.glob(File.join(dir + '/*.rb')).each do |file|
12
+ if (skip_invalid_syntax && !(`/usr/bin/env ruby -c #{file}` =~ /Syntax OK/m))
13
+ warn "Invalid syntax in: #{file}"
14
+ next
15
+ end
16
+ require file
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{require_directory}
3
+ s.version = "0.1.0"
4
+ s.author = "Matt Lightner"
5
+ s.default_executable = %q{require_directory}
6
+ s.description = %q{Require all files in a directory easily.}
7
+ s.email = %q{mlightner@gmail.com}
8
+ s.files = ["./README","./lib","./lib/require_directory.rb","./test","./test/test_directory_reqiire.rb","./test/sample_requires","./test/sample_requires/things.rb","./test/sample_requires/stuff.rb","./test/sample_requires/widgets.rb","./test/sample_requires_with_error","./test/sample_requires_with_error/gremlins.rb","./test/sample_requires_with_error/things.rb","./test/sample_requires_with_error/stuff.rb","./test/sample_requires_with_error/widgets.rb","./test/test_helper.rb","./Rakefile","./require_directory.gemspec"]
9
+ s.has_rdoc = false
10
+ s.homepage = %q{http://github.com/mlightner/require_directory}
11
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "require_directory", "--main"]
12
+ s.require_paths = ["lib"]
13
+ s.summary = %q{Require all files in a directory.}
14
+ end
@@ -0,0 +1,3 @@
1
+ class Stuff
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class Things
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class Widgets
2
+
3
+ end
@@ -0,0 +1,5 @@
1
+ class Gremlins
2
+
3
+ something here bad syntax!
4
+
5
+ end
@@ -0,0 +1,3 @@
1
+ class Stuff
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class Things
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ class Widgets
2
+
3
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestDirectoryRequires < Test::Unit::TestCase
4
+
5
+ def test_require_directory_good
6
+ require_directory File.dirname(__FILE__) + '/sample_requires'
7
+ %w{ Widgets Things Stuff }.each do |cl|
8
+ assert Object.const_defined?(cl.to_sym)
9
+ assert_equal Class, eval("#{cl}").class
10
+ end
11
+ end
12
+
13
+ def test_require_directory_bad
14
+ begin
15
+ assert_raises(Exception) do
16
+ require_directory File.dirname(__FILE__) + '/sample_requires_with_error'
17
+ end
18
+ rescue Exception => e
19
+ assert e.kind_of?(Exception)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/require_directory'
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mlightner-require_directory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Lightner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable: require_directory
14
+ dependencies: []
15
+
16
+ description: Require all files in a directory easily.
17
+ email: mlightner@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - ./README
26
+ - ./lib
27
+ - ./lib/require_directory.rb
28
+ - ./test
29
+ - ./test/test_directory_reqiire.rb
30
+ - ./test/sample_requires
31
+ - ./test/sample_requires/things.rb
32
+ - ./test/sample_requires/stuff.rb
33
+ - ./test/sample_requires/widgets.rb
34
+ - ./test/sample_requires_with_error
35
+ - ./test/sample_requires_with_error/gremlins.rb
36
+ - ./test/sample_requires_with_error/things.rb
37
+ - ./test/sample_requires_with_error/stuff.rb
38
+ - ./test/sample_requires_with_error/widgets.rb
39
+ - ./test/test_helper.rb
40
+ - ./Rakefile
41
+ - ./require_directory.gemspec
42
+ has_rdoc: false
43
+ homepage: http://github.com/mlightner/require_directory
44
+ licenses:
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --line-numbers
48
+ - --inline-source
49
+ - --title
50
+ - require_directory
51
+ - --main
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: Require all files in a directory.
73
+ test_files: []
74
+