require 0.1.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/MIT-LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2009 Winton Welsh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,49 @@
1
+ Require
2
+ =======
3
+
4
+ Manage your project's dependencies with a pretty DSL.
5
+
6
+ * Gem activation
7
+ * Require calls
8
+ * Load paths
9
+ * Gemspec configuration
10
+
11
+ Install
12
+ -------
13
+
14
+ <pre>
15
+ sudo gem install require
16
+ </pre>
17
+
18
+ Example
19
+ -------
20
+
21
+ Create <code>require.rb</code> in your project's root directory:
22
+
23
+ <pre>
24
+ require 'rubygems'
25
+ require 'require'
26
+
27
+ Require File.dirname(__FILE__) do
28
+
29
+ gem(:sinatra, '=0.9.4') { require 'sinatra/base' }
30
+ gem(:haml, '=2.2.16') { require %w(haml sass) }
31
+
32
+ lib do
33
+ gem :sinatra
34
+ gem :haml
35
+ load_path 'vendor/authlogic/lib'
36
+ require 'authlogic'
37
+ end
38
+ end
39
+ </pre>
40
+
41
+ Then in your library file (<code>lib/whatever.rb</code>):
42
+
43
+ <pre>
44
+ require File.expand_path("#{File.dirname(__FILE_)}/../require")
45
+ Require.lib!
46
+ # Activates sinatra and haml gems
47
+ # Adds vendor/authlogic/lib to the load paths
48
+ # Requires authlogic
49
+ </pre>
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "#{File.dirname(__FILE__)}/require"
2
+ Require.rakefile!
data/lib/require.rb ADDED
@@ -0,0 +1,110 @@
1
+ require 'rubygems'
2
+ require "#{File.dirname(__FILE__)}/require/dsl"
3
+ require "#{File.dirname(__FILE__)}/require/gemspec"
4
+
5
+ class Require
6
+
7
+ @@dsl = Dsl.new
8
+ @@gemspec = Gemspec.new
9
+ @@root = nil
10
+
11
+ def self.call(root=nil, &block)
12
+ @@root = File.expand_path(root) if root
13
+ @@dsl.call &block
14
+ end
15
+
16
+ def self.instance
17
+ @@gemspec.instance
18
+ end
19
+
20
+ def self.get(*args)
21
+ @@dsl.get *args
22
+ end
23
+
24
+ def self.name
25
+ @@gemspec.name
26
+ end
27
+
28
+ def self.method_missing(method, value=nil, options=nil)
29
+ method = method.to_s
30
+ if method.include?('!')
31
+ method = method.gsub!('!', '').intern
32
+ gem = get(:gem, method)
33
+ profile = get(method)
34
+ if profile
35
+ profile.dsl.each do |dsl|
36
+ if dsl.gem?
37
+ require_gem! dsl.name, dsl.version, dsl.dsl
38
+ elsif dsl.load_path?
39
+ load_path! dsl.path
40
+ elsif dsl.require?
41
+ require! dsl.path
42
+ end
43
+ end
44
+ elsif gem
45
+ require_gem! gem.name
46
+ end
47
+ else
48
+ raise "Require##{method} does not exist"
49
+ end
50
+ end
51
+
52
+ def self.reset(root=nil, &block)
53
+ @@dsl = Dsl.new
54
+ @@gemspec = Gemspec.new
55
+ call root, &block
56
+ end
57
+
58
+ def self.root
59
+ @@root
60
+ end
61
+
62
+ private
63
+
64
+ def self.file_exists?(path)
65
+ (File.exists?(path) && File.file?(path)) ||
66
+ (File.exists?("#{path}.rb") && File.file?("#{path}.rb"))
67
+ end
68
+
69
+ def self.dir_exists?(path)
70
+ File.exists?(path) && File.directory?(path)
71
+ end
72
+
73
+ def self.load_path!(paths)
74
+ return unless paths
75
+ [ paths ].flatten.each do |path|
76
+ path_with_root = "#{root}/#{path}"
77
+ if root && dir_exists?(path_with_root)
78
+ $: << path_with_root
79
+ else
80
+ $: << path
81
+ end
82
+ end
83
+ end
84
+
85
+ def self.require_gem!(name, overwrite_version=nil, overwrite_dsl=nil)
86
+ gem = get(:gem, name)
87
+ if gem
88
+ Kernel.send :gem, name.to_s, overwrite_version || gem.version
89
+ (overwrite_dsl || gem.dsl).all(:require).each do |dsl|
90
+ require! dsl.path
91
+ end
92
+ end
93
+ end
94
+
95
+ def self.require!(paths)
96
+ return unless paths
97
+ [ paths ].flatten.each do |path|
98
+ path_with_root = "#{root}/#{path}"
99
+ if file_exists?(path_with_root)
100
+ Kernel.require path_with_root
101
+ else
102
+ Kernel.require path
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ def Require(root=nil, &block)
109
+ Require.call root, &block
110
+ end
@@ -0,0 +1,81 @@
1
+ class Require
2
+ class Dsl < Array
3
+
4
+ def all(*values)
5
+ if values.empty?
6
+ self
7
+ else
8
+ Dsl.new(self.select { |a| a[0..values.length-1] == values })
9
+ end
10
+ end
11
+
12
+ def call(&block)
13
+ instance_eval(&block) if block_given?
14
+ self
15
+ end
16
+
17
+ def get(*values)
18
+ self.detect { |a| a[0..values.length-1] == values }
19
+ end
20
+
21
+ def gem(*args, &block)
22
+ args.unshift(:gem)
23
+ method_missing *args, &block
24
+ end
25
+
26
+ def method_missing(*args, &block)
27
+ if args.length == 1 && a = self.get(args[0])
28
+ a[1]
29
+ else
30
+ if block_given?
31
+ args << Dsl.new.call(&block)
32
+ end
33
+ self << Args.new(args)
34
+ end
35
+ end
36
+
37
+ def require(*args, &block)
38
+ args.unshift(:require)
39
+ method_missing *args, &block
40
+ end
41
+
42
+ class Args < Array
43
+
44
+ def all(*values)
45
+ dsl.all(*values) if dsl
46
+ end
47
+
48
+ def dsl
49
+ self[-1] if self[-1].class == Require::Dsl::Args || self[-1].class == Dsl
50
+ end
51
+
52
+ def get(*values)
53
+ dsl.get(*values) if dsl
54
+ end
55
+
56
+ def gem?
57
+ self[0] == :gem
58
+ end
59
+
60
+ def load_path?
61
+ self[0] == :load_path
62
+ end
63
+
64
+ def name
65
+ self[1] if gem? && self[1] != dsl
66
+ end
67
+
68
+ def path
69
+ self[1] if (require? || load_path?) && self[1] != dsl
70
+ end
71
+
72
+ def require?
73
+ self[0] == :require
74
+ end
75
+
76
+ def version
77
+ self[2] if self[0] == :gem && self[2] != dsl
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,65 @@
1
+ class Require
2
+ class Gemspec
3
+
4
+ def clean_paths(paths, more=nil)
5
+ paths.collect { |p| p.gsub("#{root}/#{more}", '') }
6
+ end
7
+
8
+ def executables
9
+ clean_paths Dir["#{root}/bin/*"], 'bin/'
10
+ end
11
+
12
+ def extra_doc_files
13
+ clean_paths Dir["#{root}/README.*"]
14
+ end
15
+
16
+ def files
17
+ ignore = File.read("#{root}/.gitignore").split("\n").collect do |path|
18
+ "#{root}/#{path.strip}"
19
+ end
20
+ clean_paths (Dir["#{root}/**/*"] - Dir[*ignore])
21
+ end
22
+
23
+ def instance
24
+ raise "Require must be called with a root path parameter" unless root
25
+
26
+ defaults = {
27
+ :executables => executables,
28
+ :extra_rdoc_files => extra_doc_files,
29
+ :files => files,
30
+ :has_rdoc => false,
31
+ :platform => Gem::Platform::RUBY,
32
+ :require_path => 'lib'
33
+ }
34
+
35
+ ::Gem::Specification.new do |s|
36
+ Require.get(:gemspec).all.each do |(option, value)|
37
+ case option
38
+ when :dependencies then
39
+ value.all(:gem).each do |dependency|
40
+ gem = Require.get(:gem, dependency.name)
41
+ version = dependency.version || (gem.version rescue nil)
42
+ s.add_dependency(dependency.name.to_s, version)
43
+ end
44
+ else
45
+ if s.respond_to?("#{option}=")
46
+ s.send "#{option}=", value || defaults[option]
47
+ defaults[option] = nil
48
+ end
49
+ end
50
+ end
51
+ defaults.each do |option, value|
52
+ s.send("#{option}=", value) if value
53
+ end
54
+ end
55
+ end
56
+
57
+ def name
58
+ Require.get(:gemspec).get(:name)[1] rescue nil
59
+ end
60
+
61
+ def root
62
+ Require.root
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,10 @@
1
+ $testing = true
2
+ SPEC = File.dirname(__FILE__)
3
+ $:.unshift File.expand_path("#{Require.root}/lib")
4
+
5
+ # For use with rspec textmate bundle
6
+ def debug(object)
7
+ puts "<pre>"
8
+ puts object.pretty_inspect.gsub('<', '&lt;').gsub('>', '&gt;')
9
+ puts "</pre>"
10
+ end
@@ -0,0 +1,18 @@
1
+ desc "Package gem"
2
+ Rake::GemPackageTask.new(Require.instance) do |pkg|
3
+ pkg.gem_spec = Require.instance
4
+ end
5
+
6
+ desc "Install gem"
7
+ task :install do
8
+ Rake::Task['gem'].invoke
9
+ `sudo gem uninstall #{Require.name} -x`
10
+ `sudo gem install pkg/#{Require.name}*.gem`
11
+ `rm -Rf pkg`
12
+ end
13
+
14
+ desc "Run specs"
15
+ Spec::Rake::SpecTask.new do |t|
16
+ t.spec_opts = ["--format", "specdoc", "--colour"]
17
+ t.spec_files = Dir["#{Require.root}/spec/**/*_spec.rb"]
18
+ end
data/pkg/require ADDED
Binary file
data/require.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "#{File.dirname(__FILE__)}/lib/require"
2
+
3
+ Require File.dirname(__FILE__) do
4
+
5
+ gem(:rake, '=0.8.7') { require 'rake' }
6
+ gem(:rspec, '=1.3.0')
7
+
8
+ gemspec do
9
+ author 'Winton Welsh'
10
+ email 'mail@wintoni.us'
11
+ name 'require'
12
+ homepage "http://github.com/winton/#{name}"
13
+ summary "Manage your project's dependencies with a pretty DSL"
14
+ version '0.1.5'
15
+ end
16
+
17
+ rakefile do
18
+ gem(:rake) { require 'rake/gempackagetask' }
19
+ gem(:rspec) { require 'spec/rake/spectask' }
20
+ require 'lib/require/tasks'
21
+ end
22
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,60 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ class Require
4
+ describe Dsl do
5
+
6
+ it "should store method calls and a value, options array" do
7
+ dsl = Require::Dsl.new
8
+ dsl.call { a 1, 2, 3 }
9
+ dsl.should == [[:a, 1, 2, 3]]
10
+ end
11
+
12
+ it "should store child blocks" do
13
+ dsl = Require::Dsl.new
14
+ dsl.call do
15
+ a 1 do
16
+ b 2
17
+ end
18
+ end
19
+ dsl.should == [[:a, 1, [[:b, 2]]]]
20
+ end
21
+
22
+ it "should be able to retrieve a value from the block" do
23
+ dsl = Require::Dsl.new
24
+ dsl.call do
25
+ a 1
26
+ b a
27
+ end
28
+ dsl.should == [[:a, 1], [:b, 1]]
29
+ end
30
+
31
+ it "should provide a get method" do
32
+ dsl = Require::Dsl.new
33
+ dsl.call do
34
+ a 1 do
35
+ b 2
36
+ end
37
+ end
38
+ dsl.get(:a).should == [:a, 1, [[:b, 2]]]
39
+ dsl.get(:a, 1).should == [:a, 1, [[:b, 2]]]
40
+ dsl.get(:b).should == nil
41
+ dsl.get(:a).get(:b).should == [:b, 2]
42
+ dsl.get(:a).get(:b).get(:c).should == nil
43
+ end
44
+
45
+ it "should provide an all method" do
46
+ dsl = Require::Dsl.new
47
+ dsl.call do
48
+ a 1
49
+ a 2 do
50
+ b 3
51
+ b 4
52
+ end
53
+ end
54
+ dsl.all(:a).should == [[:a, 1], [:a, 2, [[:b, 3], [:b, 4]]]]
55
+ dsl.all(:a, 1).should == [[:a, 1]]
56
+ dsl.all(:b).should == []
57
+ dsl.all(:a).last.all(:b).should == [[:b, 3], [:b, 4]]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ class Require
4
+ describe Gemspec do
5
+
6
+ it "should generate a valid gemspec instance" do
7
+ Require.reset "#{File.dirname(__FILE__)}/../fixture" do
8
+ gem :rspec, '=1.3.0'
9
+
10
+ gemspec do
11
+ author 'Winton Welsh'
12
+ dependencies do
13
+ gem :rspec
14
+ end
15
+ email 'mail@wintoni.us'
16
+ name 'require'
17
+ homepage "http://github.com/winton/#{name}"
18
+ summary "summary"
19
+ version '0.1.0'
20
+ end
21
+ end
22
+
23
+ FileUtils.mkdir_p(File.expand_path("#{File.dirname(__FILE__)}/../fixture/ignore_me"))
24
+
25
+ s = Require.instance
26
+ s.authors.should == [ "Winton Welsh" ]
27
+ s.date.should == Time.utc(Date.today.year, Date.today.mon, Date.today.mday, 8)
28
+ s.default_executable.should == "bin"
29
+ s.dependencies.should == [Gem::Dependency.new("rspec", Gem::Requirement.new(["= 1.3.0"]), :runtime)]
30
+ s.email.should == 'mail@wintoni.us'
31
+ s.executables.should == ["bin"]
32
+ s.extra_rdoc_files.should == ["README.markdown"]
33
+ s.files.should == ["bin", "bin/bin", "lib", "lib/lib.rb", "README.markdown"]
34
+ s.homepage.should == "http://github.com/winton/require"
35
+ s.name.should == "require"
36
+ s.require_paths.should == ["lib"]
37
+ s.summary.should == 'summary'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,55 @@
1
+ require "#{File.dirname(__FILE__)}/spec_helper"
2
+
3
+ describe Require do
4
+
5
+ before(:all) do
6
+ @fixture = File.dirname(__FILE__) + '/fixture'
7
+ Require.reset do
8
+ gem :rake, '=0.8.7'
9
+ gem(:rspec, '=1.3.0') { require 'spec' }
10
+
11
+ rakefile do
12
+ require 'test'
13
+ load_path File.dirname(__FILE__) + '/fixture'
14
+ gem(:rake) { require 'rake/gempackagetask' }
15
+ gem(:rspec, '>1.2.9') { require 'spec/rake/spectask' }
16
+ end
17
+ end
18
+ end
19
+
20
+ it "should provide a load_path! method" do
21
+ Require.send :load_path!, @fixture
22
+ $:.include?(@fixture).should == true
23
+ end
24
+
25
+ it "should provide a require_gem! method" do
26
+ Kernel.should_receive(:gem).with('rspec', '=1.3.0')
27
+ Require.should_receive(:require!).with('spec')
28
+ Require.send :require_gem!, :rspec
29
+ end
30
+
31
+ it "should provide a require_gem! method with optional overwrite methods" do
32
+ Kernel.should_receive(:gem).with('rspec', '>1.2.9')
33
+ Require.should_receive(:require!).with('spec/rake/spectask')
34
+ dsl = Require.get(:rakefile).get(:gem, :rspec).last
35
+ Require.send :require_gem!, :rspec, '>1.2.9', dsl
36
+ end
37
+
38
+ it "should provide a require! method" do
39
+ Kernel.should_receive(:require).with('spec')
40
+ Require.send :require!, 'spec'
41
+ end
42
+
43
+ it "should require gems through the bang shortcut" do
44
+ Require.should_receive(:require_gem!).with(:rspec)
45
+ Require.rspec!
46
+ end
47
+
48
+ it "should require profiles through the bang shortcut" do
49
+ Require.should_receive(:require!).with('test')
50
+ Require.should_receive(:require_gem!).with(:rake, nil, [[:require, "rake/gempackagetask"]])
51
+ Require.should_receive(:require_gem!).with(:rspec, '>1.2.9', [[:require, "spec/rake/spectask"]])
52
+ Require.should_receive(:load_path!).with(@fixture)
53
+ Require.rakefile!
54
+ end
55
+ end
@@ -0,0 +1,16 @@
1
+ $testing = true
2
+ SPEC = File.dirname(__FILE__)
3
+ $:.unshift File.expand_path("#{SPEC}/../lib")
4
+
5
+ require 'require'
6
+ require 'pp'
7
+
8
+ # For use with rspec textmate bundle
9
+ def debug(object)
10
+ puts "<pre>"
11
+ puts object.pretty_inspect.gsub('<', '&lt;').gsub('>', '&gt;')
12
+ puts "</pre>"
13
+ end
14
+
15
+ Spec::Runner.configure do |config|
16
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: require
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Winton Welsh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-28 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: mail@wintoni.us
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - lib/require/dsl.rb
26
+ - lib/require/gemspec.rb
27
+ - lib/require/spec_helper.rb
28
+ - lib/require/tasks.rb
29
+ - lib/require.rb
30
+ - MIT-LICENSE
31
+ - pkg/require
32
+ - Rakefile
33
+ - README.markdown
34
+ - require.rb
35
+ - spec/fixture/bin/bin
36
+ - spec/fixture/lib/lib.rb
37
+ - spec/fixture/README.markdown
38
+ - spec/require/dsl_spec.rb
39
+ - spec/require/gemspec_spec.rb
40
+ - spec/require_spec.rb
41
+ - spec/spec_helper.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/winton/require
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Manage your project's dependencies with a pretty DSL
70
+ test_files: []
71
+