overapp 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/overapp.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'mharris_ext'
2
+
3
+ %w(files template_file thor_file project from_command).each do |f|
4
+ load File.dirname(__FILE__) + "/overapp/#{f}.rb"
5
+ end
6
+
7
+ module Overapp
8
+ class << self
9
+ def with_repo_path(url)
10
+ dir = "/tmp/#{rand(100000000000000000000)}"
11
+ `mkdir #{dir}`
12
+ Dir.chdir(dir) do
13
+ `git clone #{url} .`
14
+ end
15
+ yield dir
16
+ ensure
17
+ `rm -rf #{dir}`
18
+ end
19
+ def with_local_path(overapp_path,&b)
20
+ if overapp_path =~ /git/
21
+ with_repo_path(overapp_path) do |dir|
22
+ b[dir]
23
+ end
24
+ else
25
+ yield overapp_path
26
+ end
27
+ end
28
+ def write_project(overapp_path,output_path)
29
+ with_local_path(overapp_path) do |dir|
30
+ Overapp::Project.new(:path => dir).write_to!(output_path)
31
+ end
32
+ end
33
+
34
+ def ec(cmd,ops={})
35
+ `#{cmd}`
36
+ end
37
+ end
38
+ end
data/overapp.gemspec ADDED
@@ -0,0 +1,104 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "overapp"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mike Harris"]
12
+ s.date = "2013-11-07"
13
+ s.description = "overapp"
14
+ s.email = "mharris717@gmail.com"
15
+ s.executables = ["overapp"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "Guardfile",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bin/overapp",
31
+ "lib/overapp.rb",
32
+ "lib/overapp/files.rb",
33
+ "lib/overapp/from_command.rb",
34
+ "lib/overapp/project.rb",
35
+ "lib/overapp/template_file.rb",
36
+ "lib/overapp/thor_file.rb",
37
+ "overapp.gemspec",
38
+ "spec/from_command_spec.rb",
39
+ "spec/input/top/.overlay",
40
+ "spec/input/top/b.txt",
41
+ "spec/input/top/c.txt",
42
+ "spec/input/top/place/d.txt",
43
+ "spec/overapp_spec.rb",
44
+ "spec/project_note_spec.rb",
45
+ "spec/spec_helper.rb",
46
+ "spec/support/output_dir.rb",
47
+ "spec/support/setup.rb",
48
+ "vol/input/base/a.txt",
49
+ "vol/input/base/b.txt",
50
+ "vol/input/top/.fstemplate",
51
+ "vol/input/top/b.txt",
52
+ "vol/input/top/c.txt",
53
+ "vol/input/top/place/d.txt",
54
+ "vol/test_write.rb"
55
+ ]
56
+ s.homepage = "http://github.com/mharris717/overapp"
57
+ s.licenses = ["MIT"]
58
+ s.require_paths = ["lib"]
59
+ s.rubygems_version = "2.0.7"
60
+ s.summary = "overapp"
61
+
62
+ if s.respond_to? :specification_version then
63
+ s.specification_version = 4
64
+
65
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
+ s.add_runtime_dependency(%q<mharris_ext>, [">= 0"])
67
+ s.add_runtime_dependency(%q<andand>, [">= 0"])
68
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
69
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
70
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
71
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
72
+ s.add_development_dependency(%q<guard>, [">= 0"])
73
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
74
+ s.add_development_dependency(%q<guard-spork>, [">= 0"])
75
+ s.add_development_dependency(%q<rb-fsevent>, ["~> 0.9"])
76
+ s.add_development_dependency(%q<lre>, [">= 0"])
77
+ else
78
+ s.add_dependency(%q<mharris_ext>, [">= 0"])
79
+ s.add_dependency(%q<andand>, [">= 0"])
80
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
81
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
82
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
83
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
84
+ s.add_dependency(%q<guard>, [">= 0"])
85
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
86
+ s.add_dependency(%q<guard-spork>, [">= 0"])
87
+ s.add_dependency(%q<rb-fsevent>, ["~> 0.9"])
88
+ s.add_dependency(%q<lre>, [">= 0"])
89
+ end
90
+ else
91
+ s.add_dependency(%q<mharris_ext>, [">= 0"])
92
+ s.add_dependency(%q<andand>, [">= 0"])
93
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
94
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
95
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
96
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
97
+ s.add_dependency(%q<guard>, [">= 0"])
98
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
99
+ s.add_dependency(%q<guard-spork>, [">= 0"])
100
+ s.add_dependency(%q<rb-fsevent>, ["~> 0.9"])
101
+ s.add_dependency(%q<lre>, [">= 0"])
102
+ end
103
+ end
104
+
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'FromCommand' do
4
+ let(:command) do
5
+ "mkdir abc && cd abc && echo stuff > abc.txt"
6
+ end
7
+
8
+ let(:from_command) do
9
+ Overapp::FromCommand.new(:command => command, :path => "abc")
10
+ end
11
+
12
+ it 'files' do
13
+ from_command.files.size.should == 1
14
+ from_command.files.first.path.should == 'abc.txt'
15
+ from_command.files.first.full_body.strip.should == 'stuff'
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ c.base "file:///code/orig/fs_template/spec/input/repo/.git"
@@ -0,0 +1,6 @@
1
+ <overlay>
2
+ action: insert
3
+ after: a
4
+ </overlay>
5
+ 1
6
+ 2
@@ -0,0 +1 @@
1
+ C Stuff
@@ -0,0 +1 @@
1
+ Hello
@@ -0,0 +1,183 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Overapp" do
4
+ include_context "setup"
5
+
6
+ it 'smoke' do
7
+ 2.should == 2
8
+ end
9
+
10
+ base_file "a.txt","stuff"
11
+ on_top_file "b.txt","other"
12
+
13
+ it 'base files' do
14
+ base.files.size.should == 1
15
+ end
16
+
17
+ it 'top files' do
18
+ on_top.files.size.should == 1
19
+ end
20
+
21
+ it 'combined' do
22
+ combined.size.should == 2
23
+ end
24
+ end
25
+
26
+ describe "combine" do
27
+ include_context "setup"
28
+
29
+ base_file "a.txt","stuff"
30
+ base_file "b.txt","here"
31
+ on_top_file "b.txt","other"
32
+
33
+ it 'combined size' do
34
+ combined.size.should == 2
35
+ end
36
+
37
+ it 'combined file should overwrite' do
38
+ f = combined.files.find { |x| x.path == "b.txt" }
39
+ f.body.should == 'other'
40
+ end
41
+ end
42
+
43
+ describe "dotfile" do
44
+ include_context "setup"
45
+
46
+ base_file ".abc","stuff"
47
+ base_file "b.txt","here"
48
+ on_top_file "c.txt","other"
49
+
50
+ it 'combined size' do
51
+ combined.size.should == 3
52
+ end
53
+
54
+ it 'dotfile there' do
55
+ f = combined.files.find { |x| x.path == ".abc" }
56
+ f.body.should == 'stuff'
57
+ end
58
+ end
59
+
60
+ describe "combine - append" do
61
+ include_context "setup"
62
+
63
+ base_file "a.txt","stuff"
64
+ base_file "b.txt","here"
65
+ on_top_file "b.txt","FSTMODE:append\nother"
66
+
67
+ it 'combined size' do
68
+ combined.size.should == 2
69
+ end
70
+
71
+ it 'combined file should overwrite' do
72
+ f = combined.files.find { |x| x.path == "b.txt" }
73
+ f.body.should == "here\nother"
74
+ end
75
+ end
76
+
77
+ describe "combine - append format2" do
78
+ include_context "setup"
79
+
80
+ base_file "a.txt","stuff"
81
+ base_file "b.txt","here"
82
+ on_top_file "b.txt","<overapp>append</overapp>\nother"
83
+
84
+ it 'combined size' do
85
+ combined.size.should == 2
86
+ end
87
+
88
+ it 'combined file should overwrite' do
89
+ f = combined.files.find { |x| x.path == "b.txt" }
90
+ f.body.should == "here\nother"
91
+ end
92
+ end
93
+
94
+ describe "combine - insert" do
95
+ include_context "setup"
96
+
97
+ base_file "a.txt","stuff"
98
+ base_file "b.txt","a\nb\nc\nd"
99
+ on_top_file "b.txt","FSTMODE:insert:line:2\nother\n"
100
+
101
+ it 'combined size' do
102
+ combined.size.should == 2
103
+ end
104
+
105
+ it 'combined file should overwrite' do
106
+ f = combined.files.find { |x| x.path == "b.txt" }
107
+ f.body.should == "a\nother\nb\nc\nd"
108
+ end
109
+ end
110
+
111
+ describe "combine - insert after" do
112
+ include_context "setup"
113
+
114
+ base_file "a.txt","stuff"
115
+ base_file "b.txt","123\n456\n789"
116
+ on_top_file "b.txt","<overapp>action: insert\nafter: 456</overapp>\nabc"
117
+
118
+ it 'combined size' do
119
+ combined.size.should == 2
120
+ end
121
+
122
+ it 'combined file should overwrite' do
123
+ f = combined.files.find { |x| x.path == "b.txt" }
124
+ f.body.should == "123\n456\nabc\n789"
125
+ end
126
+ end
127
+
128
+ describe "combine - insert before" do
129
+ include_context "setup"
130
+
131
+ base_file "a.txt","stuff"
132
+ base_file "b.txt","123\n456\n789"
133
+ on_top_file "b.txt","<overapp>action: insert\nbefore: 456</overapp>abc\n"
134
+
135
+ it 'combined size' do
136
+ combined.size.should == 2
137
+ end
138
+
139
+ it 'combined file should overwrite' do
140
+ f = combined.files.find { |x| x.path == "b.txt" }
141
+ f.body.should == "123\nabc\n456\n789"
142
+ end
143
+ end
144
+
145
+ describe "combine - replace" do
146
+ include_context "setup"
147
+
148
+ base_file "a.txt","stuff"
149
+ base_file "b.txt","123\n456\n789"
150
+ on_top_file "b.txt","<overapp>action: replace\nbase: 456</overapp>abc"
151
+
152
+ it 'combined size' do
153
+ combined.size.should == 2
154
+ end
155
+
156
+ it 'combined file should overwrite' do
157
+ f = combined.files.find { |x| x.path == "b.txt" }
158
+ f.body.should == "123\nabc\n789"
159
+ end
160
+ end
161
+
162
+
163
+ describe "combine - top file in new dir" do
164
+ include_context "setup"
165
+
166
+ base_file "a.txt","stuff"
167
+ on_top_file "place/b.txt","Hello"
168
+
169
+ it 'combined size' do
170
+ combined.size.should == 2
171
+ end
172
+ end
173
+
174
+ describe "combine - error" do
175
+ include_context "setup"
176
+
177
+ base_file "a.txt","stuff"
178
+ on_top_file "a.txt","FSTMODE:fgdfgdfg\nstuff"
179
+
180
+ it 'combined size' do
181
+ lambda { combined.size }.should raise_error
182
+ end
183
+ end
@@ -0,0 +1,200 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "ProjectConfig" do
4
+ let(:config) do
5
+ res = Overapp::ProjectConfig.new
6
+ res.body = config_body
7
+ res
8
+ end
9
+
10
+ describe "one base" do
11
+ let(:config_body) do
12
+ "c.base :foo"
13
+ end
14
+
15
+ it 'smoke' do
16
+ config.should be
17
+ end
18
+
19
+ it 'eval' do
20
+ config.load!
21
+ config.base.should == :foo
22
+ end
23
+ end
24
+
25
+ describe "base and overapp" do
26
+ let(:config_body) do
27
+ "c.base :foo
28
+ c.overapp :bar"
29
+ end
30
+
31
+ it 'eval' do
32
+ config.load!
33
+ config.base.should == :foo
34
+ config.overapps.should == [:bar]
35
+ end
36
+ end
37
+
38
+ it 'project no config' do
39
+ lambda { Overapp::Project.new.config }.should raise_error
40
+ end
41
+ end
42
+
43
+ describe 'Project' do
44
+ let(:config_body) do
45
+ "c.base :foo
46
+ c.overapp :bar"
47
+ end
48
+
49
+ let(:project) do
50
+ res = Overapp::Project.new(:path => "/fun")
51
+ res.stub(:config_body) { config_body }
52
+ res
53
+ end
54
+
55
+ before do
56
+ Overapp::Files.stub(:load) { Overapp::Files.new }
57
+ end
58
+
59
+ it 'overapps' do
60
+ project.overapps.size.should == 2
61
+ project.overapp_paths.last.should == "/fun"
62
+ end
63
+ end
64
+
65
+ describe 'Project with command' do
66
+ let(:config_body) do
67
+ "c.base :foo
68
+ c.overapp :bar
69
+ c.command 'ls'"
70
+ end
71
+
72
+ let(:project) do
73
+ res = Overapp::Project.new(:path => "/fun")
74
+ res.stub(:config_body) { config_body }
75
+ res
76
+ end
77
+
78
+ before do
79
+ Overapp::Files.stub(:load) { Overapp::Files.new }
80
+ end
81
+
82
+ it 'commands' do
83
+ project.commands(:after).should == ["ls"]
84
+ end
85
+ end
86
+
87
+ describe 'Project order' do
88
+ let(:config_body) do
89
+ "c.base :foo
90
+ c.overapp :bar
91
+ c.command 'ls'"
92
+ end
93
+
94
+ let(:project) do
95
+ res = Overapp::Project.new(:path => "/tmp/a/b/c/fun")
96
+ res.stub(:config_body) { config_body }
97
+ res
98
+ end
99
+
100
+ before do
101
+ Overapp::Files.stub(:load) { Overapp::Files.new }
102
+ end
103
+
104
+ it 'write' do
105
+ output_path = "/tmp/f/t/r/r"
106
+
107
+ Overapp.should_receive(:ec).with("cd #{output_path} && ls", :silent => true)
108
+ project.stub(:git_commit)
109
+ project.combined_files.stub("write_to!")
110
+
111
+ project.write_to! output_path
112
+ end
113
+ end
114
+
115
+ describe 'Project with no base' do
116
+ let(:config_body) do
117
+ "c.base 'mkdir foo && echo stuff > foo/abc.txt', :type => :command, :path => :foo"
118
+ end
119
+
120
+ let(:output_path) do
121
+ res = "/tmp/#{rand(1000000000000000)}"
122
+ `mkdir #{res}`
123
+ res
124
+ end
125
+
126
+ after do
127
+ `rm -rf #{output_path}`
128
+ end
129
+
130
+ let(:project) do
131
+ res = Overapp::Project.new(:path => "/tmp/a/b/c/fun")
132
+ res.stub(:config_body) { config_body }
133
+ res
134
+ end
135
+
136
+ it 'write' do
137
+ #Overapp.should_receive(:ec).with("echo stuff > abc.txt", :silent => true)
138
+ project.stub(:git_commit)
139
+ project.stub(:overapp_paths) { [] }
140
+
141
+ project.write_to! output_path
142
+
143
+ File.read("#{output_path}/abc.txt").strip.should == 'stuff'
144
+ end
145
+ end
146
+
147
+
148
+ describe "write project" do
149
+ include_context "output dir"
150
+
151
+ let(:repo_dir) do
152
+ "#{input_dir}/repo"
153
+ end
154
+ let(:input_dir) do
155
+ File.expand_path(File.dirname(__FILE__) + "/input")
156
+ end
157
+ let(:overapp_dir) do
158
+ "#{input_dir}/top"
159
+ end
160
+
161
+ def files_equal(source_dir,target_dir,file)
162
+ source = File.read("#{source_dir}/#{file}")
163
+ target = File.read("#{target_dir}/#{file}")
164
+ FileTest.should be_exist("#{target_dir}/#{file}")
165
+ source.should == target
166
+ end
167
+
168
+ describe "from git" do
169
+ before do
170
+ Overapp.write_project overapp_dir, output_dir
171
+ end
172
+
173
+ it 'has README' do
174
+ files_equal repo_dir, output_dir, "README.md"
175
+ end
176
+
177
+ it 'c.txt' do
178
+ files_equal overapp_dir, output_dir, "c.txt"
179
+ end
180
+
181
+ it 'b.txt insert' do
182
+ File.read("#{output_dir}/b.txt").should == %w(a 1 2 b c d).join("\n") + "\n"
183
+ end
184
+ end
185
+
186
+ describe "from combined" do
187
+ before do
188
+ Overapp::Files.write_combined repo_dir,overapp_dir,output_dir
189
+ end
190
+
191
+ it 'has README' do
192
+ files_equal repo_dir, output_dir, "README.md"
193
+ end
194
+
195
+ it 'has .abc' do
196
+ files_equal repo_dir, output_dir, ".abc"
197
+ end
198
+
199
+ end
200
+ end
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+
4
+
5
+ Spork.prefork do
6
+ unless ENV['DRB']
7
+ require 'simplecov'
8
+ SimpleCov.start
9
+ end
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
12
+
13
+ require 'rspec'
14
+
15
+
16
+ # Requires supporting files with custom matchers and macros, etc,
17
+ # in ./support/ and its subdirectories.
18
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
19
+
20
+ RSpec.configure do |config|
21
+ #config.filter_run :focus => true
22
+ config.fail_fast = false
23
+ end
24
+ end
25
+
26
+ Spork.each_run do
27
+ if ENV['DRB']
28
+ require 'simplecov'
29
+ SimpleCov.start
30
+ end
31
+ load File.dirname(__FILE__) + "/../lib/overapp.rb"
32
+ #Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| load f}
33
+ end
@@ -0,0 +1,14 @@
1
+ shared_context "output dir" do
2
+ def make_fresh_output_dir
3
+ `mkdir /tmp/fresh_output` unless FileTest.exist?("/tmp/fresh_output")
4
+ dir = "/tmp/fresh_output/#{rand(10000000000000)}"
5
+ `mkdir #{dir}`
6
+ dir
7
+ end
8
+
9
+ let(:output_dir) { make_fresh_output_dir }
10
+
11
+ after do
12
+ `rm -rf #{output_dir}`
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ shared_context "setup" do
2
+ class << self
3
+ fattr(:files) { [] }
4
+ def base_file(file,body)
5
+ self.files << {:loc => :base, :file => file, :body => body}
6
+ end
7
+ def on_top_file(file,body)
8
+ self.files << {:loc => :on_top, :file => file, :body => body}
9
+ end
10
+ end
11
+
12
+ let(:file_class) { Overapp::TemplateFile }
13
+
14
+ let(:base) do
15
+ res = Overapp::Files.new(:file_class => file_class)
16
+ self.class.files.select { |x| x[:loc] == :base }.each do |f|
17
+ res.add f
18
+ end
19
+ res
20
+ end
21
+
22
+ let(:on_top) do
23
+ res = Overapp::Files.new(:file_class => file_class)
24
+ self.class.files.select { |x| x[:loc] == :on_top }.each do |f|
25
+ res.add f
26
+ end
27
+ res
28
+ end
29
+
30
+ let(:combined) do
31
+ base.apply(on_top)
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ Stuff goes herezzz
@@ -0,0 +1,7 @@
1
+ More Stuff
2
+ a
3
+ b
4
+ c
5
+ d
6
+ e
7
+ f
@@ -0,0 +1 @@
1
+ c.base "https://github.com/mharris717/lre.git"
@@ -0,0 +1,3 @@
1
+ FSTMODE:insert:line:2
2
+ I don't belong here
3
+ Neither do I
@@ -0,0 +1 @@
1
+ C Stuff
@@ -0,0 +1 @@
1
+ Hello
data/vol/test_write.rb ADDED
@@ -0,0 +1,10 @@
1
+ load "lib/overapp.rb"
2
+
3
+ dir = File.expand_path(File.dirname(__FILE__))
4
+
5
+ Dir["#{dir}/output/**/*.*"].each do |f|
6
+ `rm #{f}`
7
+ end
8
+
9
+ #Overapp::Files.write_combined "#{dir}/input/base","#{dir}/input/top","#{dir}/output"
10
+ Overapp.write_project "#{dir}/input/top","#{dir}/output"