mergit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +6 -0
- data/bin/mergit +95 -0
- data/lib/mergit.rb +48 -0
- data/lib/mergit/errors.rb +5 -0
- data/lib/mergit/processor.rb +86 -0
- data/lib/mergit/version.rb +3 -0
- data/mergit.gemspec +32 -0
- data/spec/examples/loop/a.rb +1 -0
- data/spec/examples/loop/b.rb +1 -0
- data/spec/examples/loop/c.rb +1 -0
- data/spec/mergit/processor_spec.rb +162 -0
- data/spec/mergit_spec.rb +60 -0
- data/spec/spec_helper.rb +19 -0
- metadata +256 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Christian Höltje
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Mergit
|
2
|
+
|
3
|
+
* [![Build Status](https://secure.travis-ci.org/docwhat/mergit.png)](http://travis-ci.org/docwhat/mergit)
|
4
|
+
* [![Dependencies](https://gemnasium.com/docwhat/mergit.png)](https://gemnasium.com/docwhat/mergit)
|
5
|
+
* [![Coverage Status](https://coveralls.io/repos/docwhat/mergit/badge.png?branch=master)](https://coveralls.io/r/docwhat/mergit)
|
6
|
+
|
7
|
+
Mergit is a way to merge a bunch of `require`d files into one file.
|
8
|
+
|
9
|
+
This is useful to distribute single-file ruby executables, such as administration scripts, simple tools, etc. Yet allows you to break
|
10
|
+
files out for easy design, programming and testing.
|
11
|
+
|
12
|
+
## Limitations
|
13
|
+
|
14
|
+
Mergit uses simple text processing, therefore it can be tripped up. Some known problems include:
|
15
|
+
|
16
|
+
* `require` statements nested in code instead of at outermost scope of a file.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
gem 'mergit'
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install mergit
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### Command Line Tool
|
35
|
+
|
36
|
+
The command line tool, `mergit`, is pretty self-explanatory.
|
37
|
+
|
38
|
+
You specify the ruby file you want `require`s merged into on the command line (via standard in, if you specify `-`) and any library directories
|
39
|
+
you want `require`d from.
|
40
|
+
|
41
|
+
You can specify the `--lib` flag multiple times.
|
42
|
+
|
43
|
+
Use the `--output` flag to send the resulting output to someplace other than stdout.
|
44
|
+
|
45
|
+
### Library API
|
46
|
+
|
47
|
+
Simple usage:
|
48
|
+
|
49
|
+
```
|
50
|
+
search_path = [ '/path/to/lib', '/path/to/other/lib' ]
|
51
|
+
mergit = Mergit.new(:search_path => search_path)
|
52
|
+
|
53
|
+
string_of_merged_file = mergit.process_file('/path/to/file')
|
54
|
+
# or
|
55
|
+
string_of_merged_string = mergit.process(some_string)
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/mergit
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
$: << File.expand_path('../../lib/', __FILE__) if File.directory?(File.expand_path('../../lib/', __FILE__))
|
5
|
+
require 'mergit'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
class MergitProgram
|
9
|
+
attr_accessor :output
|
10
|
+
attr_reader :input
|
11
|
+
|
12
|
+
def err msg
|
13
|
+
$stderr.puts "* error: #{msg}"
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def debug msg
|
18
|
+
$stderr.puts "* debug: #{msg}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def mergit
|
22
|
+
@mergit ||= Mergit.new()
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_options
|
26
|
+
# Defaults
|
27
|
+
@output = $stdout
|
28
|
+
|
29
|
+
# Parser
|
30
|
+
optparse = OptionParser.new do |opts|
|
31
|
+
opts.banner = "Usage: #{opts.program_name} [OPTIONS] ruby-file"
|
32
|
+
opts.define_head "Merges all require's found in the specified lib directories into one ruby file."
|
33
|
+
opts.separator ''
|
34
|
+
|
35
|
+
opts.on('-l', '--lib DIR', String,
|
36
|
+
"Adds DIR to the list of directories to look for require'd files. Can be specified multiple times.") do |d|
|
37
|
+
d = Pathname.new(d)
|
38
|
+
if d.directory?
|
39
|
+
mergit.search_path.unshift d.realpath.to_s
|
40
|
+
else
|
41
|
+
err "'#{d}' is not a directory."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on('-d', '--debug', "Turn on debugging.") do
|
46
|
+
@debug = true
|
47
|
+
end
|
48
|
+
opts.on('-o', '--output FILE', String,
|
49
|
+
"Where to output the merged ruby script.") do |f|
|
50
|
+
@output = File.open(f, 'w') unless '-' == f
|
51
|
+
end
|
52
|
+
|
53
|
+
opts.on_tail('-V', '--version', 'Show the version.') do
|
54
|
+
$stderr.puts "#{opts.program_name} version: #{Mergit::VERSION}"
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
opts.on_tail('-h', '--help', 'This Help.') do
|
59
|
+
$stderr.puts opts
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
arguments = optparse.parse!
|
65
|
+
|
66
|
+
if arguments.size == 0
|
67
|
+
err "You need to specify the ruby file to merge."
|
68
|
+
elsif arguments.size > 1
|
69
|
+
err "You can only specify one ruby file to merge at a time."
|
70
|
+
end
|
71
|
+
|
72
|
+
if '-' == arguments.first
|
73
|
+
@input = $stdin
|
74
|
+
else
|
75
|
+
@input = File.open(arguments.first, 'r')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def run
|
80
|
+
parse_options
|
81
|
+
debug "Search Path: #{mergit.search_path.inspect}"
|
82
|
+
debug "Input: #{input.inspect}"
|
83
|
+
debug "Output: #{output.inspect}"
|
84
|
+
input_string = @input.read
|
85
|
+
@input.close
|
86
|
+
output_string = mergit.process(input_string)
|
87
|
+
@output.write output_string
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if __FILE__ == $0
|
92
|
+
MergitProgram.new.run
|
93
|
+
end
|
94
|
+
|
95
|
+
# EOF
|
data/lib/mergit.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'mergit/version'
|
2
|
+
require 'mergit/processor'
|
3
|
+
require 'mergit/errors'
|
4
|
+
|
5
|
+
class Mergit
|
6
|
+
ATTRIBUTES = {
|
7
|
+
:search_path => [Dir.pwd],
|
8
|
+
:replacements => {},
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
ATTRIBUTES.each_key do |attr|
|
12
|
+
attr_accessor attr
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize options=nil
|
16
|
+
final_options = options ? ATTRIBUTES.merge(options) : ATTRIBUTES
|
17
|
+
|
18
|
+
ATTRIBUTES.each_key do |attr|
|
19
|
+
instance_variable_set("@#{attr}", final_options[attr])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_file filename
|
24
|
+
if File.file? filename
|
25
|
+
create_file_processor(filename).output
|
26
|
+
else
|
27
|
+
raise MergitError.new "No such file: #{filename}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def process string
|
32
|
+
create_string_processor(string).output
|
33
|
+
end
|
34
|
+
|
35
|
+
# add file to visited list
|
36
|
+
# scan file
|
37
|
+
# for all requires, process files
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def create_string_processor string
|
42
|
+
Processor.new(search_path, replacements, :string => string)
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_file_processor filename
|
46
|
+
Processor.new(search_path, replacements, :filename => filename)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'mergit/errors'
|
2
|
+
require 'pathname'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
class Mergit
|
6
|
+
class Processor
|
7
|
+
def initialize search_path, replacements, options
|
8
|
+
@search_path = search_path.map{|p| Pathname.new p}
|
9
|
+
@replacements = replacements
|
10
|
+
@visited_files = []
|
11
|
+
|
12
|
+
@output = StringIO.new
|
13
|
+
begin
|
14
|
+
if options.key?(:filename)
|
15
|
+
scan_file(Pathname.new(options[:filename]).realpath)
|
16
|
+
elsif options.key?(:string)
|
17
|
+
scan(options[:string])
|
18
|
+
end
|
19
|
+
ensure
|
20
|
+
@output.close unless options[:do_not_close]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_requirement lib_name
|
25
|
+
@search_path.each do |directory|
|
26
|
+
possible_path = directory + "#{lib_name}.rb"
|
27
|
+
return possible_path.realpath if possible_path.file?
|
28
|
+
end
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_requirement! lib_name
|
33
|
+
find_requirement(lib_name).tap do |retval|
|
34
|
+
raise Mergit::RequirementNotFound.new("Unabled to find require'd file: #{lib_name}") if retval.nil?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def scan_line line
|
39
|
+
line.chomp!
|
40
|
+
if line =~ /^\s*require\s+'([^']+)'\s*$/ or line =~ /^\s*require\s+"([^"]+)"\s*$/
|
41
|
+
requirement = find_requirement($1)
|
42
|
+
if requirement.nil?
|
43
|
+
emit line
|
44
|
+
else
|
45
|
+
scan_file requirement
|
46
|
+
end
|
47
|
+
else
|
48
|
+
emit line
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def scan_file filename
|
53
|
+
relative_filename = if filename.relative?
|
54
|
+
filename
|
55
|
+
else
|
56
|
+
filename.relative_path_from(Pathname.pwd)
|
57
|
+
end
|
58
|
+
if @visited_files.include? relative_filename
|
59
|
+
return
|
60
|
+
else
|
61
|
+
@visited_files << relative_filename
|
62
|
+
end
|
63
|
+
emit "### MERGIT: Start of '#{relative_filename}'"
|
64
|
+
filename.readlines.each { |line| scan_line line }
|
65
|
+
emit "### MERGIT: End of '#{relative_filename}'"
|
66
|
+
end
|
67
|
+
|
68
|
+
def scan string
|
69
|
+
string_split(string).each { |line| scan_line line }
|
70
|
+
end
|
71
|
+
|
72
|
+
def string_split string
|
73
|
+
string.split(/\n|\r\n/)
|
74
|
+
end
|
75
|
+
|
76
|
+
def output
|
77
|
+
@output.close unless @output.closed?
|
78
|
+
@final_output ||= @output.string
|
79
|
+
end
|
80
|
+
|
81
|
+
def emit string
|
82
|
+
@output.puts string
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
data/mergit.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mergit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mergit"
|
8
|
+
spec.version = Mergit::VERSION
|
9
|
+
spec.authors = ["Christian Höltje"]
|
10
|
+
spec.email = ["docwhat@gerf.org"]
|
11
|
+
spec.description = %q{Merge 'require'd files into one file.}
|
12
|
+
spec.summary = %q{Ever wanted to merge all your 'require'd files into one file for easy distribution? Mergit is your friend!}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.13"
|
24
|
+
spec.add_development_dependency "coveralls", "~> 0.6"
|
25
|
+
spec.add_development_dependency "guard-rspec", "~> 2.5"
|
26
|
+
spec.add_development_dependency "guard-bundler", "~> 1.0"
|
27
|
+
spec.add_development_dependency "rb-inotify", "~> 0.9"
|
28
|
+
spec.add_development_dependency "rb-fsevent", "~> 0.9"
|
29
|
+
spec.add_development_dependency "growl", "~> 1.0"
|
30
|
+
spec.add_development_dependency "libnotify", "~> 0.8"
|
31
|
+
spec.add_development_dependency "terminal-notifier-guard", "~> 1.5"
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'b'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'c'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'a'
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mergit/processor'
|
3
|
+
|
4
|
+
describe Mergit::Processor do
|
5
|
+
let(:search_path) { [LIB_PATH] }
|
6
|
+
let(:replacements) { {} }
|
7
|
+
|
8
|
+
describe "find_requirement" do
|
9
|
+
subject { Mergit::Processor.new(search_path, replacements, :string => '') }
|
10
|
+
|
11
|
+
context "with a known lib-file" do
|
12
|
+
let(:lib_file) { Pathname.new File.expand_path('../../../lib/mergit.rb', __FILE__) }
|
13
|
+
let(:lib_name) { lib_file.basename '.rb' }
|
14
|
+
|
15
|
+
it "should find mergit.rb" do
|
16
|
+
subject.find_requirement(lib_name).should eq(lib_file)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return nil if it doesn't exist" do
|
21
|
+
subject.find_requirement('does-not-exist').should be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "find_requirement!" do
|
26
|
+
subject { Mergit::Processor.new(search_path, replacements, :string => '') }
|
27
|
+
|
28
|
+
context "with a known lib-file" do
|
29
|
+
let(:lib_file) { Pathname.new File.expand_path('../../../lib/mergit.rb', __FILE__) }
|
30
|
+
let(:lib_name) { lib_file.basename '.rb' }
|
31
|
+
|
32
|
+
it "should find mergit.rb" do
|
33
|
+
subject.find_requirement!(lib_name).should eq(lib_file)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should raise an exception when it doesn't exist" do
|
38
|
+
expect { subject.find_requirement!('does-not-exist') }.
|
39
|
+
to raise_error(Mergit::RequirementNotFound)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "scan_file" do
|
44
|
+
subject { Mergit::Processor.new(search_path, replacements, :string => '', :do_not_close => true) }
|
45
|
+
|
46
|
+
context "of an existing lib_file" do
|
47
|
+
let(:lib_file) { Pathname.new('../../../lib/mergit/version.rb').expand_path(__FILE__) }
|
48
|
+
let(:relative_lib_file) { 'lib/mergit/version.rb' }
|
49
|
+
let(:lib_name) { lib_file.basename '.rb' }
|
50
|
+
|
51
|
+
it "should call .scan_line multiple times" do
|
52
|
+
subject.should_receive(:scan_line).at_least(3).times
|
53
|
+
subject.scan_file(lib_file)
|
54
|
+
end
|
55
|
+
|
56
|
+
context "then the output" do
|
57
|
+
before { subject.scan_file(lib_file) }
|
58
|
+
it "should start with the merget header" do
|
59
|
+
subject.output.should =~ /\A### MERGIT: Start of '#{relative_lib_file}'$/
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should end with the merget header" do
|
63
|
+
subject.output.should =~ /^### MERGIT: End of '#{relative_lib_file}'\Z/
|
64
|
+
end
|
65
|
+
|
66
|
+
it "contain the contents of lib_file" do
|
67
|
+
subject.output.should include(lib_file.read)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "with a lib_file that has a requires" do
|
73
|
+
let(:required_content) { Pathname.new('../../../lib/mergit/version.rb').expand_path(__FILE__).read }
|
74
|
+
let(:lib_file) { Pathname.new('../../../lib/mergit.rb').expand_path(__FILE__) }
|
75
|
+
subject { Mergit::Processor.new(search_path, replacements, :string => '', :do_not_close => true) }
|
76
|
+
before { subject.scan_file(lib_file) }
|
77
|
+
|
78
|
+
it "should contain the required file" do
|
79
|
+
subject.output.should include(required_content)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "scan" do
|
85
|
+
subject { Mergit::Processor.new(search_path, replacements, :string => '', :do_not_close => true) }
|
86
|
+
|
87
|
+
context "with a string" do
|
88
|
+
let(:ruby_string) { "puts 'hello'\nrequire 'pathname'\n\nputs 'goodbye'\n" }
|
89
|
+
|
90
|
+
context "should call .scan_line" do
|
91
|
+
after { subject.scan(ruby_string) }
|
92
|
+
|
93
|
+
it "multiple times" do
|
94
|
+
subject.should_receive(:scan_line).at_least(3).times
|
95
|
+
end
|
96
|
+
|
97
|
+
it "with the contents of the contents of ruby_string" do
|
98
|
+
ruby_string.split("\n").each do |line|
|
99
|
+
subject.should_receive(:scan_line).with(line).once.ordered
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "then the output" do
|
105
|
+
before { subject.scan(ruby_string) }
|
106
|
+
|
107
|
+
it "contain the contents of lib_file" do
|
108
|
+
subject.output.should include(ruby_string)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "scan_line" do
|
115
|
+
subject { Mergit::Processor.new(search_path, replacements, :string => '', :do_not_close => true) }
|
116
|
+
|
117
|
+
context "given a single requires" do
|
118
|
+
let(:ruby_string) { "require 'mergit/version'" }
|
119
|
+
after { subject.scan_line ruby_string }
|
120
|
+
|
121
|
+
it "should call scan_file()" do
|
122
|
+
subject.should_receive(:scan_file).with(Pathname.new('../../../lib/mergit/version.rb').expand_path(__FILE__)).once
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "string_split" do
|
128
|
+
subject { Mergit::Processor.new(search_path, replacements, :string => '') }
|
129
|
+
let(:example_parts) { [ 'one', '', 'two', 'three' ] }
|
130
|
+
|
131
|
+
context "with unix newlines" do
|
132
|
+
let(:example_string) { example_parts.join("\n") }
|
133
|
+
it "should be correct" do
|
134
|
+
subject.string_split(example_string).should eq(example_parts)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "with windows newlines" do
|
139
|
+
let(:example_string) { example_parts.join("\r\n") }
|
140
|
+
it "should be correct" do
|
141
|
+
subject.string_split(example_string).should eq(example_parts)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "with looping requires" do
|
147
|
+
let(:dir) { EXAMPLE_DIR + 'loop' }
|
148
|
+
subject do
|
149
|
+
Mergit::Processor.new(
|
150
|
+
[ dir ],
|
151
|
+
{},
|
152
|
+
:string => '',
|
153
|
+
:do_not_close => true
|
154
|
+
)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should not go into an infinite loop" do
|
158
|
+
subject.scan_file(dir + 'a.rb')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
data/spec/mergit_spec.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mergit'
|
3
|
+
|
4
|
+
describe Mergit do
|
5
|
+
it 'should have a version number' do
|
6
|
+
Mergit::VERSION.should_not be_nil
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with no initial paramaters" do
|
10
|
+
its(:search_path) { should eq([Dir.pwd]) }
|
11
|
+
its(:replacements) { should eq({}) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "with initial parameters" do
|
15
|
+
let(:search_path) { [LIB_PATH] }
|
16
|
+
let(:replacements) { { 'VERSION' => '1.2.3' } }
|
17
|
+
subject do
|
18
|
+
Mergit.new({
|
19
|
+
:search_path => search_path,
|
20
|
+
:replacements => replacements,
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
its(:search_path) { should eq(search_path) }
|
25
|
+
its(:replacements) { should eq(replacements) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "process" do
|
29
|
+
let(:text) { "require 'something'" }
|
30
|
+
let(:processor) { double(Mergit::Processor, :output => 'output-text') }
|
31
|
+
before { subject.stub(:create_string_processor).and_return(processor) }
|
32
|
+
after { subject.process(text) }
|
33
|
+
|
34
|
+
it "should call create_string_processor" do
|
35
|
+
subject.should_receive(:create_string_processor).with(text)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "process_file" do
|
40
|
+
context "with a bogus libname" do
|
41
|
+
it "should raise MergitError" do
|
42
|
+
expect { subject.process_file('totolly-bogus-filename') }.
|
43
|
+
to raise_error(Mergit::MergitError)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with a legit libname" do
|
48
|
+
let(:libname) { File.join(LIB_PATH, 'mergit.rb') }
|
49
|
+
let(:processor) { double(Mergit::Processor, :output => 'output-text') }
|
50
|
+
before { subject.stub(:create_file_processor).and_return(processor) }
|
51
|
+
after { subject.process_file(libname) }
|
52
|
+
|
53
|
+
it "should call create_file_processor" do
|
54
|
+
subject.should_receive(:create_file_processor).with(libname)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
LIB_PATH = File.expand_path('../../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift LIB_PATH
|
3
|
+
|
4
|
+
require 'pathname'
|
5
|
+
EXAMPLE_DIR = Pathname.new("../examples").expand_path(__FILE__)
|
6
|
+
|
7
|
+
if ENV['TRAVIS'] == 'true'
|
8
|
+
require 'coveralls'
|
9
|
+
Coveralls.wear!
|
10
|
+
else
|
11
|
+
begin
|
12
|
+
require 'simplecov'
|
13
|
+
SimpleCov.start
|
14
|
+
rescue LoadError
|
15
|
+
puts "Not loading simplecov"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# EOF
|
metadata
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mergit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christian Höltje
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '10.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '10.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.13'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.13'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: coveralls
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.6'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.6'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard-rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.5'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.5'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: guard-bundler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rb-inotify
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.9'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0.9'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rb-fsevent
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0.9'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0.9'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: growl
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '1.0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '1.0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: libnotify
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ~>
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0.8'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.8'
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: terminal-notifier-guard
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ~>
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '1.5'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ~>
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '1.5'
|
190
|
+
description: Merge 'require'd files into one file.
|
191
|
+
email:
|
192
|
+
- docwhat@gerf.org
|
193
|
+
executables:
|
194
|
+
- mergit
|
195
|
+
extensions: []
|
196
|
+
extra_rdoc_files: []
|
197
|
+
files:
|
198
|
+
- .gitignore
|
199
|
+
- .rspec
|
200
|
+
- .travis.yml
|
201
|
+
- Gemfile
|
202
|
+
- Guardfile
|
203
|
+
- LICENSE.txt
|
204
|
+
- README.md
|
205
|
+
- Rakefile
|
206
|
+
- bin/mergit
|
207
|
+
- lib/mergit.rb
|
208
|
+
- lib/mergit/errors.rb
|
209
|
+
- lib/mergit/processor.rb
|
210
|
+
- lib/mergit/version.rb
|
211
|
+
- mergit.gemspec
|
212
|
+
- spec/examples/loop/a.rb
|
213
|
+
- spec/examples/loop/b.rb
|
214
|
+
- spec/examples/loop/c.rb
|
215
|
+
- spec/mergit/processor_spec.rb
|
216
|
+
- spec/mergit_spec.rb
|
217
|
+
- spec/spec_helper.rb
|
218
|
+
homepage: ''
|
219
|
+
licenses:
|
220
|
+
- MIT
|
221
|
+
post_install_message:
|
222
|
+
rdoc_options: []
|
223
|
+
require_paths:
|
224
|
+
- lib
|
225
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
226
|
+
none: false
|
227
|
+
requirements:
|
228
|
+
- - ! '>='
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
segments:
|
232
|
+
- 0
|
233
|
+
hash: -2751772494269357839
|
234
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
|
+
none: false
|
236
|
+
requirements:
|
237
|
+
- - ! '>='
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: '0'
|
240
|
+
segments:
|
241
|
+
- 0
|
242
|
+
hash: -2751772494269357839
|
243
|
+
requirements: []
|
244
|
+
rubyforge_project:
|
245
|
+
rubygems_version: 1.8.23
|
246
|
+
signing_key:
|
247
|
+
specification_version: 3
|
248
|
+
summary: Ever wanted to merge all your 'require'd files into one file for easy distribution?
|
249
|
+
Mergit is your friend!
|
250
|
+
test_files:
|
251
|
+
- spec/examples/loop/a.rb
|
252
|
+
- spec/examples/loop/b.rb
|
253
|
+
- spec/examples/loop/c.rb
|
254
|
+
- spec/mergit/processor_spec.rb
|
255
|
+
- spec/mergit_spec.rb
|
256
|
+
- spec/spec_helper.rb
|