overapp 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,8 @@ module Overapp
5
5
  File.expand_path(File.dirname(__FILE__) + "/../../../tmp")
6
6
  end
7
7
  def with(ops={})
8
- dir = "#{base_dir}/#{rand(1000000000000000000)}"
8
+ d = Time.now.strftime("%Y%m%d%H%M%S%L")
9
+ dir = "#{base_dir}/td_#{d}_#{rand(10000000)}"
9
10
  `mkdir #{dir}`
10
11
  if block_given?
11
12
  Dir.chdir(dir) do
@@ -16,7 +17,10 @@ module Overapp
16
17
  end
17
18
  ensure
18
19
  if block_given?
19
- ec "rm -rf #{dir}", :silent => true
20
+ delete = lambda do
21
+ ec "rm -rf #{dir}", :silent => false
22
+ end
23
+ #ObjectSpace.define_finalizer(self, delete)
20
24
  end
21
25
  end
22
26
 
@@ -0,0 +1,18 @@
1
+ module Overapp
2
+ class Var
3
+ fattr(:vars) { {} }
4
+ def set(k,v)
5
+ vars[k.to_s] = v
6
+ end
7
+ def clear!
8
+ self.vars!
9
+ end
10
+
11
+ class << self
12
+ fattr(:instance) { new }
13
+ def method_missing(sym,*args,&b)
14
+ instance.send(sym,*args,&b)
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/overapp.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'mharris_ext'
2
2
  require 'ptools'
3
+ require 'ostruct'
3
4
 
4
5
  class Object
5
6
  def klass
@@ -9,7 +10,7 @@ end
9
10
 
10
11
  module Overapp
11
12
  def self.load_files!
12
- %w(files template_file project from_command).each do |f|
13
+ %w(files template_file project from_command var).each do |f|
13
14
  load File.dirname(__FILE__) + "/overapp/#{f}.rb"
14
15
  end
15
16
 
@@ -28,6 +29,10 @@ module Overapp
28
29
  %w(tmp_dir git dir cmd write).each do |f|
29
30
  load File.dirname(__FILE__) + "/overapp/util/#{f}.rb"
30
31
  end
32
+
33
+ %w(params body_mod var_obj).each do |f|
34
+ load File.dirname(__FILE__) + "/overapp/template_file/#{f}.rb"
35
+ end
31
36
  end
32
37
  end
33
38
 
data/overapp.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "overapp"
8
- s.version = "0.4.2"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mike Harris"]
12
- s.date = "2013-11-16"
12
+ s.date = "2013-11-22"
13
13
  s.description = "overapp"
14
14
  s.email = "mharris717@gmail.com"
15
15
  s.executables = ["overapp"]
@@ -45,13 +45,19 @@ Gem::Specification.new do |s|
45
45
  "lib/overapp/project/config_entry.rb",
46
46
  "lib/overapp/project/write.rb",
47
47
  "lib/overapp/template_file.rb",
48
+ "lib/overapp/template_file/body_mod.rb",
49
+ "lib/overapp/template_file/params.rb",
50
+ "lib/overapp/template_file/var_obj.rb",
48
51
  "lib/overapp/util/cmd.rb",
49
52
  "lib/overapp/util/dir.rb",
50
53
  "lib/overapp/util/git.rb",
51
54
  "lib/overapp/util/tmp_dir.rb",
52
55
  "lib/overapp/util/write.rb",
56
+ "lib/overapp/var.rb",
53
57
  "overapp.gemspec",
58
+ "spec/command_replacement_spec.rb",
54
59
  "spec/from_command_spec.rb",
60
+ "spec/git_spec.rb",
55
61
  "spec/input/rails_post_overlay/.overapp",
56
62
  "spec/input/rails_post_overlay/app/models/post.rb",
57
63
  "spec/input/rails_widget_overlay/.overapp",
@@ -93,11 +99,14 @@ Gem::Specification.new do |s|
93
99
  "spec/input/top/place/d.txt",
94
100
  "spec/nesting_spec.rb",
95
101
  "spec/overapp_spec.rb",
102
+ "spec/project_context_spec.rb",
96
103
  "spec/project_note_spec.rb",
97
104
  "spec/spec_helper.rb",
98
105
  "spec/support/output_dir.rb",
106
+ "spec/support/project.rb",
99
107
  "spec/support/setup.rb",
100
108
  "spec/support/tmp_dir.rb",
109
+ "spec/template_spec.rb",
101
110
  "tmp/.gitkeep",
102
111
  "vol/input/base/a.txt",
103
112
  "vol/input/base/b.txt",
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ class MockLoadFactory
4
+ include FromHash
5
+ attr_accessor :descriptor, :type, :entry_ops
6
+ def loader
7
+ OpenStruct.new(:foo => :bar)
8
+ end
9
+ end
10
+
11
+
12
+ describe "Command Replacement" do
13
+ describe 'Basic' do
14
+ let(:config_body) do
15
+ "c.overapp :bar"
16
+ end
17
+
18
+ let(:project) do
19
+ res = Overapp::Project.new(:path => "/fun")
20
+ res.stub(:config_body) { config_body }
21
+ res.load_factory_class = MockLoadFactory
22
+ res
23
+ end
24
+
25
+ it 'size' do
26
+ project.overapps.size.should == 2
27
+ end
28
+
29
+ it 'foo' do
30
+ project.overapps.first.foo.should == :bar
31
+ end
32
+ end
33
+ end
@@ -27,3 +27,32 @@ describe 'FromCommand' do
27
27
  Dir["#{output_dir}/**/*.*"].sort.should == ['abc.txt','place.txt'].sort.map { |x| "#{output_dir}/#{x}" }
28
28
  end
29
29
  end
30
+
31
+ describe 'FromCommand2' do
32
+ include_context "tmp dir"
33
+ include_context "output dir"
34
+
35
+ let(:command) do
36
+ "echo stuff > abc.txt"
37
+ end
38
+
39
+ let(:config_body) do
40
+ "c.command '#{command}'"
41
+ end
42
+
43
+ before do
44
+ File.create "#{tmp_dir}/place.txt","fun"
45
+ end
46
+
47
+ let(:project) do
48
+ res = Overapp::Project.new(:path => tmp_dir)
49
+ res.stub(:config_body) { config_body }
50
+ res
51
+ end
52
+
53
+ it 'runs' do
54
+ project.write_to! output_dir
55
+ Dir["#{output_dir}/**/*.*"].sort.should == ['abc.txt','place.txt'].sort.map { |x| "#{output_dir}/#{x}" }
56
+ end
57
+ end
58
+
data/spec/git_spec.rb ADDED
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'Git' do
4
+ it 'smoke' do
5
+ Overapp::TmpDir.with do |dir|
6
+ Overapp::Git.commit(dir,"stuff") do
7
+ File.create "#{dir}/abc.txt","hello"
8
+ end
9
+ end
10
+ 2.should == 2
11
+ end
12
+ end
data/spec/nesting_spec.rb CHANGED
@@ -1,44 +0,0 @@
1
- if true
2
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
-
4
- describe 'Nesting' do
5
- include_context "tmp dir"
6
-
7
- let(:widget_overlay_dir) do
8
- File.expand_path(File.dirname(__FILE__) + "/input/rails_widget_overlay")
9
- end
10
-
11
- let(:post_overlay_dir) do
12
- File.expand_path(File.dirname(__FILE__) + "/input/rails_post_overlay")
13
- end
14
-
15
- describe 'basic' do
16
- before do
17
- Overapp.write_project widget_overlay_dir,tmp_dir
18
- end
19
-
20
- it 'wrote' do
21
- File.read("#{tmp_dir}/app/models/widget.rb").should == "class Widget < ActiveRecord::Base\nend"
22
- File.read("#{tmp_dir}/config/routes.rb").should == "route stuff\n"
23
- end
24
- end
25
-
26
- describe 'runs base overlay commands' do
27
- before do
28
- Overapp.write_project post_overlay_dir,tmp_dir
29
- end
30
-
31
- it 'has post model' do
32
- FileTest.should be_exist("#{tmp_dir}/app/models/post.rb")
33
- end
34
-
35
- it 'has widget model' do
36
- FileTest.should be_exist("#{tmp_dir}/app/models/widget.rb")
37
- end
38
-
39
- it 'has routes file' do
40
- FileTest.should be_exist("#{tmp_dir}/config/routes.rb")
41
- end
42
- end
43
- end
44
- end
@@ -0,0 +1,131 @@
1
+ describe "projects" do
2
+ include_context "projects"
3
+ include_context "output dir"
4
+
5
+ describe "basic file loading" do
6
+ project do |p|
7
+ p.file "abc.txt","hello"
8
+ end
9
+
10
+ has_files 1
11
+ has_file "abc.txt","hello"
12
+ end
13
+
14
+ describe "multiple projects" do
15
+ project "main" do |p|
16
+ p.config "c.overlay 'widget'"
17
+ p.file "README","hello"
18
+ end
19
+
20
+ project "widget" do |p|
21
+ p.file "widget.rb","class Widget; end"
22
+ end
23
+
24
+ has_files 2
25
+ end
26
+
27
+ describe "multiple projects" do
28
+ project "auth" do |p|
29
+ p.config "c.overlay 'base'"
30
+ p.file "README","\nauth stuff", :action => :append
31
+ end
32
+
33
+ project "base" do |p|
34
+ p.file "README","hello"
35
+ end
36
+
37
+ has_files 1
38
+ has_file "README","hello\nauth stuff"
39
+ end
40
+
41
+ describe "project nesting" do
42
+ project "auth" do |p|
43
+ p.config "c.overlay 'widget'"
44
+ p.file "auth.coffee","auth setup"
45
+ p.file "app.js","\nauth = true", :action => :append
46
+ end
47
+
48
+ project "widget" do |p|
49
+ p.config "c.overlay 'base'"
50
+ p.file "widget.coffee","Widget = Em.Object.extend()"
51
+ end
52
+
53
+ project "base" do |p|
54
+ p.file "app.js","App = Em.Application.create()"
55
+ p.file "README","Hello"
56
+ end
57
+
58
+ has_files 4
59
+ has_file "README"
60
+ has_file "app.js","App = Em.Application.create()\nauth = true"
61
+ end
62
+
63
+ describe "missing base file" do
64
+ project do |p|
65
+ p.file "README","Hello",action: :append
66
+ end
67
+
68
+ it 'errors' do
69
+ lambda { combined.size }.should raise_error(Overapp::MissingBaseFileError,/./)
70
+ end
71
+ end
72
+
73
+ describe "template file with project var" do
74
+ project do |p|
75
+ p.file "README","Hello <%= foo %>", :template => "erb"
76
+ p.var "foo","bar"
77
+ end
78
+
79
+ has_files 1
80
+ has_file "README","Hello bar"
81
+ end
82
+
83
+ describe "template file with global var" do
84
+ project do |p|
85
+ p.file "README","Hello <%= foo %>", :template => "erb"
86
+ end
87
+
88
+ var "foo","bar"
89
+
90
+ has_files 1
91
+ has_file "README","Hello bar"
92
+ end
93
+
94
+ describe "template file with global var in config" do
95
+ project do |p|
96
+ p.file "README","Hello <%= foo %>", :template => "erb"
97
+ p.config "c.var 'foo','bar'"
98
+ end
99
+
100
+ has_files 1
101
+ has_file "README","Hello bar"
102
+ end
103
+
104
+ describe "template file with global var and local var" do
105
+ project do |p|
106
+ p.file "README","Hello <%= foo %>", :template => "erb"
107
+ p.var "foo","baz"
108
+ end
109
+
110
+ var "foo","bar"
111
+
112
+ has_files 1
113
+ has_file "README","Hello baz"
114
+ end
115
+
116
+ describe "refs self", :pending => true do
117
+ project "base" do |p|
118
+ p.config "c.overlay :self; c.overlay 'auth'"
119
+ p.file "README","hello"
120
+ end
121
+
122
+ project "auth" do |p|
123
+ p.file "README"," auth stuff", :action => :append
124
+ end
125
+
126
+ has_files 1
127
+ has_file "README","hello auth stuff"
128
+ end
129
+ end
130
+
131
+
@@ -1,23 +1,33 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "ProjectConfig" do
3
+ shared_context "p1" do
4
4
  let(:config) do
5
5
  res = Overapp::ProjectConfig.new
6
6
  res.body = config_body
7
+ res.load!
7
8
  res
8
9
  end
9
10
 
11
+ let(:project) do
12
+ res = Overapp::Project.new(:path => "/fun")
13
+ res.stub(:config_body) { config_body }
14
+ res
15
+ end
16
+
17
+ before do
18
+ Overapp::Files.stub(:load) { Overapp::Files.new }
19
+ end
20
+ end
21
+
22
+ describe "ProjectConfig" do
23
+ include_context "p1"
24
+
10
25
  describe "one base" do
11
26
  let(:config_body) do
12
27
  "c.base :foo"
13
28
  end
14
29
 
15
- it 'smoke' do
16
- config.should be
17
- end
18
-
19
30
  it 'eval' do
20
- config.load!
21
31
  config.overapps.first.descriptor.should == :foo
22
32
  end
23
33
  end
@@ -29,7 +39,6 @@ describe "ProjectConfig" do
29
39
  end
30
40
 
31
41
  it 'eval' do
32
- config.load!
33
42
  config.overapps.map { |x| x.descriptor }.should == [:foo,:bar]
34
43
  end
35
44
  end
@@ -40,66 +49,49 @@ describe "ProjectConfig" do
40
49
  end
41
50
 
42
51
  describe 'Project' do
52
+ include_context "p1"
43
53
  let(:config_body) do
44
54
  "c.base :foo
45
55
  c.overapp :bar"
46
56
  end
47
57
 
48
- let(:project) do
49
- res = Overapp::Project.new(:path => "/fun")
50
- res.stub(:config_body) { config_body }
51
- res
52
- end
53
-
54
- before do
55
- Overapp::Files.stub(:load) { Overapp::Files.new }
56
- end
57
-
58
58
  it 'overapps' do
59
59
  project.overapps.size.should == 3
60
60
  project.overapp_entries.last.descriptor.should == "/fun"
61
61
  end
62
62
  end
63
63
 
64
- describe 'Project with command' do
65
- let(:config_body) do
66
- "c.base :foo
67
- c.overapp :bar
68
- c.command 'ls'"
64
+ describe 'Project2' do
65
+ include_context "projects"
66
+ project do |p|
67
+ p.config "c.base :foo; c.overapp :bar"
69
68
  end
70
69
 
71
- let(:project) do
72
- res = Overapp::Project.new(:path => "/fun")
73
- res.stub(:config_body) { config_body }
74
- res
70
+ it 'overapps' do
71
+ project.overapps.size.should == 3
72
+ project.overapp_entries.last.descriptor.should == project.path
75
73
  end
74
+ end
76
75
 
77
- before do
78
- Overapp::Files.stub(:load) { Overapp::Files.new }
76
+ describe 'Project with command' do
77
+ include_context "projects"
78
+ project do |p|
79
+ p.config "c.base :foo; c.overapp :bar; c.command 'ls'"
79
80
  end
80
81
 
81
82
  it 'commands' do
82
- #project.commands(:after).should == ["ls"]
83
+ project.overapps.size.should == 4
83
84
  end
84
85
  end
85
86
 
86
87
  describe 'Project order' do
88
+ include_context "p1"
87
89
  let(:config_body) do
88
90
  "c.base :foo
89
91
  c.overapp :bar
90
92
  c.command 'ls'"
91
93
  end
92
94
 
93
- let(:project) do
94
- res = Overapp::Project.new(:path => "/tmp/a/b/c/fun")
95
- res.stub(:config_body) { config_body }
96
- res
97
- end
98
-
99
- before do
100
- Overapp::Files.stub(:load) { Overapp::Files.new }
101
- end
102
-
103
95
  if false
104
96
  it 'write' do
105
97
  output_path = "/tmp/f/t/r/r"
@@ -117,62 +109,18 @@ describe 'Project order' do
117
109
  end
118
110
 
119
111
  describe 'Project order' do
112
+ include_context "p1"
120
113
  let(:config_body) do
121
114
  "c.base :foo
122
115
  c.overapp '.'
123
116
  c.overapp :bar"
124
117
  end
125
118
 
126
- let(:project) do
127
- res = Overapp::Project.new(:path => "/tmp/a/b/c/fun")
128
- res.stub(:config_body) { config_body }
129
- res
130
- end
131
-
132
- before do
133
- Overapp::Files.stub(:load) { Overapp::Files.new }
134
- end
135
-
136
119
  it "doesn't have self twice" do
137
120
  project.overapp_entries.size.should == 3
138
- project.overapp_entries[1].descriptor.should == "/tmp/a/b/c/fun"
139
- end
140
- end
141
-
142
- if false
143
- describe 'Project with no base' do
144
- let(:config_body) do
145
- "c.base 'mkdir foo && echo stuff > foo/abc.txt', :type => :command, :path => :foo"
146
- end
147
-
148
- let(:output_path) do
149
- res = "/tmp/#{rand(1000000000000000)}"
150
- `mkdir #{res}`
151
- res
152
- end
153
-
154
- after do
155
- #`rm -rf #{output_path}`
156
- end
157
-
158
- let(:project) do
159
- res = Overapp::Project.new(:path => "/tmp/a/b/c/fun")
160
- res.stub(:config_body) { config_body }
161
- res
162
- end
163
-
164
- it 'write' do
165
- #Overapp.should_receive(:ec).with("echo stuff > abc.txt", :silent => true)
166
- project.stub(:git_commit)
167
- project.stub(:overapp_paths) { [] }
168
-
169
- project.write_to! output_path
170
-
171
- File.read("#{output_path}/abc.txt").strip.should == 'stuff'
121
+ project.overapp_entries[1].descriptor.should == "/fun"
172
122
  end
173
123
  end
174
- end
175
-
176
124
 
177
125
  describe "write project" do
178
126
  include_context "output dir"
@@ -211,20 +159,4 @@ describe "write project" do
211
159
  File.read("#{output_dir}/b.txt").should == %w(a 1 2 b c d).join("\n") + "\n"
212
160
  end
213
161
  end
214
-
215
- if false
216
- describe "from combined" do
217
- before do
218
- Overapp::Files.write_combined repo_dir,overapp_dir,output_dir
219
- end
220
-
221
- it 'has README' do
222
- files_equal repo_dir, output_dir, "README.md"
223
- end
224
-
225
- it 'has .abc' do
226
- files_equal repo_dir, output_dir, ".abc"
227
- end
228
- end
229
- end
230
162
  end
data/spec/spec_helper.rb CHANGED
@@ -40,7 +40,7 @@ Spork.prefork do
40
40
 
41
41
  RSpec.configure do |config|
42
42
  #config.filter_run :focus => true
43
- config.fail_fast = false
43
+ config.fail_fast = true
44
44
 
45
45
  repo_dirs = %w(repo)
46
46