overapp 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGVjNDY1MjViY2YwMGE5MzQ1ZGViODNkZGU5YWMwNWZlZjAzYTJhZA==
4
+ OGFjY2IyZTI1NDcxZDcxMjM4ZjQ4MTM1NzUwYTkwM2VkM2RiNjc2Mg==
5
5
  data.tar.gz: !binary |-
6
- Njg5MWYwNGY0Yzk0ODFlYWE5OGFlMDIxNjI2NWRlZjU0MThmMTAxYg==
6
+ MWQ1NWM5MjA4MDIyYWE3MTIxODcyZTYzZmYzNWZlZDNiMmZiMjQ5MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YTgwNjQ0OTI3Y2VjMGVjMWUxZWM1NTVmNDJjMzBhMTYyNGQ2MjIxYTlmOGEw
10
- MDExYTM1OWI5YTA0ZWI0ZDJmODExOTYxMjM3NGIzZTAxYzFhZWU4Yzg0YTY2
11
- NDVmMzAyMGM0MTg0MGY3MDU4ODIzNzliYjFhZWE0MTA3ZWQzYmE=
9
+ NDAyMzNlNTMyZWFjODIyOTllNTI4ZjQxOWNlMjdhMjczMzBlM2I5OWU0Njky
10
+ NzQ4MTY4MzZhOTQzMDNjMTcyNjExMTFhY2VmYzAwZWI0Y2Y3ODA5N2NiNDJj
11
+ ZmJjZTNkZWZlOTIzOWM0ZTNlNDgxOWM2OWJjMjVkZTk2NDRmNzQ=
12
12
  data.tar.gz: !binary |-
13
- ZDg2NTIyNTM1N2UxMTZlOGRkYjQ1OWQwNTE3MzU2MWVjZWRhNTk1YmRhYmVh
14
- YzE3ZDViYmZjMjhmZDZlMmM3ODNiY2ZjMGE1ZjYzMjZmNzczMTgxNTQzNjMz
15
- YzQ0OGEzNDU3NzliYzc1NjdjNTI5ODg5MmY1YWE4NjU0OTFlM2Y=
13
+ ZjJmMWU4Y2Y3ZDQ3NjY1Y2QzYjc2ZGQ0NDdlNDA4NzQ3NzFmOGZhMDNiZWZi
14
+ MzgyZWE5YmVmN2NhYTc0Y2QwMDMyZTQ2MWQ5ODdlMmU4ZTliNDg2YjUyYzdk
15
+ MDhlY2IwZTFlM2I3NzI5MmYxNjEwOTJlNjFhMmQ1NTE0YTMxNTY=
File without changes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -1,6 +1,7 @@
1
1
  require 'mharris_ext'
2
2
  require 'ptools'
3
3
  require 'ostruct'
4
+ require 'andand'
4
5
 
5
6
  class Object
6
7
  def klass
@@ -26,7 +27,7 @@ module Overapp
26
27
  load File.dirname(__FILE__) + "/overapp/project/#{f}.rb"
27
28
  end
28
29
 
29
- %w(tmp_dir git dir cmd write).each do |f|
30
+ %w(tmp_dir git dir cmd write file).each do |f|
30
31
  load File.dirname(__FILE__) + "/overapp/util/#{f}.rb"
31
32
  end
32
33
 
@@ -11,36 +11,45 @@ module Overapp
11
11
  class Files
12
12
  include FromHash
13
13
  include Enumerable
14
- fattr(:files) { [] }
14
+ fattr(:files) { {} }
15
15
  fattr(:file_class) { TemplateFile }
16
16
  def add(ops)
17
- files << file_class.new(:path => ops[:file], :full_body => ops[:body])
17
+ ops = file_class.new(:path => ops[:file], :full_body => ops[:body]) if ops.kind_of?(Hash)
18
+ self.files[ops.path] = ops
18
19
  end
20
+ def delete(path)
21
+ self.files.delete(path)
22
+ end
23
+
19
24
  def size
20
25
  files.size
21
26
  end
27
+
22
28
  def apply(on_top,ops={})
23
- res = files.clone
29
+ res = self.class.new(:files => files.clone)
24
30
  on_top.each do |top_file|
25
- if ops[:vars] && ops[:vars].size > 0
26
- #raise ops[:vars].inspect
27
- top_file.vars = ops[:vars]
28
- end
29
- existing = res.find { |x| x.path == top_file.path }
30
- if existing
31
- res -= [existing]
32
- new_file = top_file.combined(existing)
33
- res << new_file if new_file
34
- elsif top_file.has_note?
35
- raise MissingBaseFileError.new(:top_file => top_file, :base => self)
36
- else
37
- res << top_file.parsed
38
- end
31
+ res.apply_file(top_file,ops)
32
+ end
33
+ res
34
+ end
35
+
36
+ def apply_file(top_file,ops={})
37
+ if ops[:vars] && ops[:vars].size > 0
38
+ top_file.vars = ops[:vars]
39
+ end
40
+ existing = files[top_file.path]
41
+ raise MissingBaseFileError.new(:top_file => top_file, :base => self) if !existing && top_file.has_note?
42
+ new_file = top_file.combined(existing)
43
+ if new_file
44
+ add new_file
45
+ else
46
+ delete top_file.path
39
47
  end
40
- self.class.new(:files => res)
41
48
  end
49
+
50
+
42
51
  def each(&b)
43
- files.each(&b)
52
+ files.values.each(&b)
44
53
  end
45
54
 
46
55
  def write_to!(dir)
@@ -37,7 +37,7 @@ module Overapp
37
37
 
38
38
  def overapp_entries
39
39
  res = config.overapps
40
- local = config.overapps.find { |x| x.descriptor == "." || x.descriptor == :self }
40
+ local = config.overapps.find { |x| ['.',:self,path].include?(x.descriptor) }
41
41
  if local
42
42
  local.descriptor = path
43
43
  res
@@ -9,12 +9,12 @@ module Overapp
9
9
  overapp(*args)
10
10
  end
11
11
 
12
- def overapp(name)
12
+ def overapp(name,ops={})
13
13
  self.overapps << ConfigEntry.new(:descriptor => name, :type => :overapp)
14
14
  end
15
15
 
16
- def overlay(name)
17
- overapp(name)
16
+ def overlay(*args)
17
+ overapp(*args)
18
18
  end
19
19
 
20
20
  def command(cmd,ops={})
@@ -14,7 +14,9 @@ module Overapp
14
14
 
15
15
  def write!
16
16
  raise "no combined files" unless combined_files
17
- combined_files.write_to!(output_path)
17
+ Overapp::Git.commit(output_path,"Overlay Created") do
18
+ combined_files.write_to!(output_path)
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -4,7 +4,7 @@ module Overapp
4
4
  attr_accessor :path, :full_body
5
5
 
6
6
  fattr(:params_obj) do
7
- Params.new(:full_body => full_body)
7
+ Params.new(:full_body => full_body, :path => path)
8
8
  end
9
9
 
10
10
  def has_note?
@@ -41,8 +41,8 @@ module Overapp
41
41
  full_body
42
42
  end
43
43
 
44
- def combined(base)
45
- b = apply_body_to(base.full_body)
44
+ def combined(base=nil)
45
+ b = apply_body_to(base ? base.full_body : "")
46
46
  if b == :delete
47
47
  nil
48
48
  else
@@ -53,14 +53,11 @@ module Overapp
53
53
  def write_to!(dir)
54
54
  raise "bad path" if path.blank?
55
55
  d = File.dirname("#{dir}/#{path}")
56
- `mkdir -p #{d}`
57
- File.create "#{dir}/#{path}",body
56
+ Overapp.ec "mkdir -p #{d}", :silent => true
57
+ Overapp.file_create "#{dir}/#{path}",body
58
58
  end
59
59
 
60
60
  fattr(:vars) { {} }
61
- def parsed
62
- combined(OpenStruct.new(:full_body => ""))
63
- end
64
61
  end
65
62
 
66
63
  class BasicFile < TemplateFile
@@ -2,7 +2,7 @@ module Overapp
2
2
  class TemplateFile
3
3
  class Params
4
4
  include FromHash
5
- attr_accessor :full_body
5
+ attr_accessor :full_body, :path
6
6
  def body; full_body; end
7
7
  include Enumerable
8
8
  def each(&b)
@@ -30,11 +30,9 @@ module Overapp
30
30
  end
31
31
  res
32
32
  rescue => exp
33
- puts "Error in split_note_and_body #{path}"
34
- raise exp
33
+ raise "split_note_and_body #{path} #{exp.message}"
35
34
  end
36
35
 
37
-
38
36
  def note_params_single(one)
39
37
  res = {}
40
38
  note = one[:note]
@@ -3,18 +3,28 @@ module Overapp
3
3
  def dir_files(dir)
4
4
  res = Dir["#{dir}/**/*"] + Dir["#{dir}/**/.*"]
5
5
  res = res - [".","..",".git"]
6
- res.reject { |x| FileTest.file?(x) && File.binary?(x) && !(x =~ /\.txt/) }
7
- res.select { |x| FileTest.file?(x) }
6
+ res = res.select { |x| FileTest.file?(x) }
8
7
  end
9
8
  def dir_files_full(dir)
10
9
  raise "Dir not there #{dir}" unless FileTest.exist?(dir)
11
10
  dir_files(dir).map do |full_file|
12
11
  f = full_file.gsub("#{dir}/","")
13
12
  raise "bad #{f}" if f == full_file
14
- {:file => f, :body => File.read(full_file)}
13
+ {:file => f, :body => read(full_file)}
15
14
  end
16
15
  end
17
16
 
17
+ def read(file)
18
+ if File.binary?(file)
19
+ File.open(file,"rb") do |f|
20
+ f.read
21
+ end
22
+ else
23
+ File.read(file)
24
+ end
25
+ end
26
+
27
+
18
28
  def with_local_path(overapp_path,&b)
19
29
  if Git.repo?(overapp_path)
20
30
  TmpDir.with_repo_path(overapp_path) do |dir|
@@ -0,0 +1,7 @@
1
+ module Overapp
2
+ class << self
3
+ def file_create(*args)
4
+ File.create(*args)
5
+ end
6
+ end
7
+ end
@@ -5,17 +5,17 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "overapp"
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
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-22"
12
+ s.date = "2013-11-27"
13
13
  s.description = "overapp"
14
14
  s.email = "mharris717@gmail.com"
15
15
  s.executables = ["overapp"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE.txt",
18
- "README.rdoc"
18
+ "README.md"
19
19
  ]
20
20
  s.files = [
21
21
  ".document",
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  "Gemfile.lock",
25
25
  "Guardfile",
26
26
  "LICENSE.txt",
27
- "README.rdoc",
27
+ "README.md",
28
28
  "Rakefile",
29
29
  "VERSION",
30
30
  "bin/overapp",
@@ -50,14 +50,17 @@ Gem::Specification.new do |s|
50
50
  "lib/overapp/template_file/var_obj.rb",
51
51
  "lib/overapp/util/cmd.rb",
52
52
  "lib/overapp/util/dir.rb",
53
+ "lib/overapp/util/file.rb",
53
54
  "lib/overapp/util/git.rb",
54
55
  "lib/overapp/util/tmp_dir.rb",
55
56
  "lib/overapp/util/write.rb",
56
57
  "lib/overapp/var.rb",
57
58
  "overapp.gemspec",
59
+ "spec/binary_copy_spec.rb",
58
60
  "spec/command_replacement_spec.rb",
59
61
  "spec/from_command_spec.rb",
60
62
  "spec/git_spec.rb",
63
+ "spec/input/rails.png",
61
64
  "spec/input/rails_post_overlay/.overapp",
62
65
  "spec/input/rails_post_overlay/app/models/post.rb",
63
66
  "spec/input/rails_widget_overlay/.overapp",
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe 'binary' do
4
+ it 'smoke' do
5
+ path = File.dirname(__FILE__) + "/input/rails.png"
6
+ body = Overapp.read(path)
7
+ template_file = Overapp::TemplateFile.new(:path => path, :full_body => body)
8
+ template_file.should_not be_has_note
9
+ end
10
+
11
+ describe 'manual' do
12
+ include_context "projects"
13
+ include_context "output dir"
14
+
15
+ let(:mock_file_methods) { false }
16
+
17
+ project "main" do |p|
18
+ p.config :overlay,:widget
19
+ p.file "README","hello"
20
+ p.file "rails.png",Overapp.read(File.dirname(__FILE__) + "/input/rails.png")
21
+ end
22
+
23
+ project "widget" do |p|
24
+ p.file "widget.rb","widget"
25
+ end
26
+
27
+ def fix_overlay_path
28
+ path = project("main").path + "/.overlay"
29
+ body = File.read(path)
30
+
31
+ body = body.gsub("widget",project("widget").path)
32
+ File.create path, body
33
+ project("main").tap do |p|
34
+ p.config_body!
35
+ p.config!
36
+ end
37
+ end
38
+
39
+ before do
40
+ fix_overlay_path
41
+ end
42
+
43
+ has_file "README"
44
+ has_file "rails.png"
45
+ has_files 4
46
+
47
+ it 'thing' do
48
+ project('main').write_to! output_dir
49
+ 2.should == 2
50
+ end
51
+ end
52
+ end
@@ -30,4 +30,32 @@ describe "Command Replacement" do
30
30
  project.overapps.first.foo.should == :bar
31
31
  end
32
32
  end
33
- end
33
+ end
34
+
35
+ describe 'thing' do
36
+ include_context "projects"
37
+
38
+ project "auth" do |p|
39
+ p.config :overlay, :basic_app
40
+ p.file "auth.coffee","auth = true"
41
+ end
42
+
43
+ project :basic_app do |p|
44
+ p.config :overlay, :widget, :name => :sample
45
+ p.file "main.coffee","stuff"
46
+ end
47
+
48
+ project :widget do |p|
49
+ p.file "widget.rb","widget"
50
+ end
51
+
52
+ has_files 3
53
+
54
+ it 'has name' do
55
+ project(:basic_app).overapps.first
56
+ end
57
+ end
58
+
59
+
60
+
61
+
@@ -4,55 +4,46 @@ describe 'FromCommand' do
4
4
  include_context "tmp dir"
5
5
  include_context "output dir"
6
6
 
7
- let(:command) do
8
- "mkdir abc && cd abc && echo stuff > abc.txt"
9
- end
10
-
11
- let(:config_body) do
12
- "c.command '#{command}', :path => 'abc'"
13
- end
14
-
15
- before do
16
- File.create "#{tmp_dir}/place.txt","fun"
17
- end
18
-
19
7
  let(:project) do
20
8
  res = Overapp::Project.new(:path => tmp_dir)
21
9
  res.stub(:config_body) { config_body }
22
10
  res
23
11
  end
24
12
 
25
- it 'runs' do
13
+ before do
14
+ File.create "#{tmp_dir}/place.txt","fun"
26
15
  project.write_to! output_dir
27
- Dir["#{output_dir}/**/*.*"].sort.should == ['abc.txt','place.txt'].sort.map { |x| "#{output_dir}/#{x}" }
28
16
  end
29
- end
30
-
31
- describe 'FromCommand2' do
32
- include_context "tmp dir"
33
- include_context "output dir"
34
17
 
35
- let(:command) do
36
- "echo stuff > abc.txt"
18
+ def files_should_equal(files)
19
+ Dir["#{output_dir}/**/*.*"].sort.should == files.sort.map { |x| "#{output_dir}/#{x}" }
37
20
  end
38
21
 
39
- let(:config_body) do
40
- "c.command '#{command}'"
41
- end
22
+ describe "with subdir" do
23
+ let(:command) do
24
+ "mkdir abc && cd abc && echo stuff > abc.txt"
25
+ end
42
26
 
43
- before do
44
- File.create "#{tmp_dir}/place.txt","fun"
45
- end
27
+ let(:config_body) do
28
+ "c.command '#{command}', :path => 'abc'"
29
+ end
46
30
 
47
- let(:project) do
48
- res = Overapp::Project.new(:path => tmp_dir)
49
- res.stub(:config_body) { config_body }
50
- res
31
+ it 'has files' do
32
+ files_should_equal ['abc.txt','place.txt']
33
+ end
51
34
  end
52
35
 
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}" }
36
+ describe "at root" do
37
+ let(:command) do
38
+ "echo stuff > abc.txt"
39
+ end
40
+
41
+ let(:config_body) do
42
+ "c.command '#{command}'"
43
+ end
44
+
45
+ it 'has files' do
46
+ files_should_equal ['abc.txt','place.txt']
47
+ end
56
48
  end
57
49
  end
58
-
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe 'Git' do
3
+ describe 'Git Coverage' do
4
4
  it 'smoke' do
5
5
  Overapp::TmpDir.with do |dir|
6
6
  Overapp::Git.commit(dir,"stuff") do
@@ -10,3 +10,25 @@ describe 'Git' do
10
10
  2.should == 2
11
11
  end
12
12
  end
13
+
14
+ describe 'overapp output is checked into git' do
15
+ before do
16
+ Overapp.stub(:file_create) { |*args| }
17
+ Overapp.stub(:ec) { |*args| }
18
+ end
19
+
20
+ include_context "projects"
21
+
22
+ project do |p|
23
+ p.file "README","Hello"
24
+ end
25
+
26
+ let(:output_path) do
27
+ "/tmp/asdfsfwefwef/fgdfgeefgefgefge#{rand(100000000000000)}"
28
+ end
29
+
30
+ it 'write' do
31
+ Overapp::Git.should_receive(:commit_inner).with(output_path,"Overlay Created",true)
32
+ project.write_to! output_path
33
+ end
34
+ end
Binary file
@@ -35,7 +35,7 @@ describe "combine" do
35
35
  end
36
36
 
37
37
  it 'combined file should overwrite' do
38
- f = combined.files.find { |x| x.path == "b.txt" }
38
+ f = combined.find { |x| x.path == "b.txt" }
39
39
  f.body.should == 'other'
40
40
  end
41
41
  end
@@ -52,7 +52,7 @@ describe "dotfile" do
52
52
  end
53
53
 
54
54
  it 'dotfile there' do
55
- f = combined.files.find { |x| x.path == ".abc" }
55
+ f = combined.find { |x| x.path == ".abc" }
56
56
  f.body.should == 'stuff'
57
57
  end
58
58
  end
@@ -71,7 +71,7 @@ describe "combine - append format2" do
71
71
  end
72
72
 
73
73
  it 'combined file should overwrite' do
74
- f = combined.files.find { |x| x.path == "b.txt" }
74
+ f = combined.find { |x| x.path == "b.txt" }
75
75
  f.body.should == "here\nother"
76
76
  end
77
77
  end
@@ -88,7 +88,7 @@ describe "combine - insert after" do
88
88
  end
89
89
 
90
90
  it 'combined file should overwrite' do
91
- f = combined.files.find { |x| x.path == "b.txt" }
91
+ f = combined.find { |x| x.path == "b.txt" }
92
92
  f.body.should == "123\n456\nabc\n789"
93
93
  end
94
94
  end
@@ -105,7 +105,7 @@ describe "combine - insert after with colon" do
105
105
  end
106
106
 
107
107
  it 'combined file should overwrite' do
108
- f = combined.files.find { |x| x.path == "b.txt" }
108
+ f = combined.find { |x| x.path == "b.txt" }
109
109
  f.body.should == "123\n45: 6\nabc\n789"
110
110
  end
111
111
  end
@@ -122,7 +122,7 @@ describe "combine - insert before" do
122
122
  end
123
123
 
124
124
  it 'combined file should overwrite' do
125
- f = combined.files.find { |x| x.path == "b.txt" }
125
+ f = combined.find { |x| x.path == "b.txt" }
126
126
  f.body.should == "123\nabc\n456\n789"
127
127
  end
128
128
  end
@@ -151,7 +151,7 @@ describe "combine - multiple directives" do
151
151
  end
152
152
 
153
153
  it 'combined file should overwrite' do
154
- f = combined.files.find { |x| x.path == "b.txt" }
154
+ f = combined.find { |x| x.path == "b.txt" }
155
155
  f.body.should == "abc\ndef\n789"
156
156
  end
157
157
  end
@@ -168,7 +168,7 @@ describe "combine - replace" do
168
168
  end
169
169
 
170
170
  it 'combined file should overwrite' do
171
- f = combined.files.find { |x| x.path == "b.txt" }
171
+ f = combined.find { |x| x.path == "b.txt" }
172
172
  f.body.should == "123\nabc\n789"
173
173
  end
174
174
  end
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
1
3
  describe "projects" do
2
4
  include_context "projects"
3
5
  include_context "output dir"
@@ -13,7 +15,7 @@ describe "projects" do
13
15
 
14
16
  describe "multiple projects" do
15
17
  project "main" do |p|
16
- p.config "c.overlay 'widget'"
18
+ p.config :overlay, :widget
17
19
  p.file "README","hello"
18
20
  end
19
21
 
@@ -113,9 +115,10 @@ describe "projects" do
113
115
  has_file "README","Hello baz"
114
116
  end
115
117
 
116
- describe "refs self", :pending => true do
118
+ describe "refs self", :pending => false do
117
119
  project "base" do |p|
118
- p.config "c.overlay :self; c.overlay 'auth'"
120
+ p.config :overlay, "."
121
+ p.config :overlay,:auth
119
122
  p.file "README","hello"
120
123
  end
121
124
 
@@ -126,6 +129,10 @@ describe "projects" do
126
129
  has_files 1
127
130
  has_file "README","hello auth stuff"
128
131
  end
132
+
133
+
129
134
  end
130
135
 
131
136
 
137
+
138
+
@@ -143,7 +143,7 @@ describe "write project" do
143
143
  end
144
144
 
145
145
  describe "from git" do
146
- before do
146
+ before(:all) do
147
147
  Overapp.write_project overapp_dir, output_dir
148
148
  end
149
149
 
@@ -6,6 +6,6 @@ shared_context "output dir" do
6
6
  output_dir
7
7
  end
8
8
  after do
9
- ec "rm -rf #{output_dir}", :silent => true
9
+ #ec "rm -rf #{output_dir}", :silent => true
10
10
  end
11
11
  end
@@ -14,21 +14,53 @@ class Object
14
14
  end
15
15
 
16
16
  class ProjectDSL
17
- dsl_method :config
18
17
  dsl_method :path
18
+ attr_accessor :main
19
19
 
20
20
  attr_accessor :name
21
21
  include FromHash
22
22
 
23
+ def config_hash(method,arg,ops={})
24
+ res = "c.#{method} '#{arg}'"
25
+ ops.each do |k,v|
26
+ res << ", :#{k} => '#{v}'"
27
+ end
28
+ config res
29
+ end
30
+ def config(*args)
31
+ if args.length >= 2
32
+ config_hash(*args)
33
+ elsif args.first.kind_of?(Hash)
34
+ raise "first hash arg"
35
+ elsif args.size == 1
36
+ self.configs << args.first
37
+ else
38
+ raise "bad"
39
+ end
40
+ end
41
+ def config_body
42
+ configs.join("\n")
43
+ end
44
+ fattr(:configs) { [] }
45
+
23
46
  fattr(:project) do
24
47
  res = Overapp::Project.new
25
- res.config_body = config || ""
48
+ res.config_body = config_body
26
49
  res.path = path || "/tmp/#{rand(100000000000000000)}"
27
50
 
28
51
  res.vars = res.vars.merge(vars)
29
52
  res
30
53
  end
31
54
 
55
+ def write_to_tmp!
56
+ Overapp.ec "rm -rf #{project.path}", :silent => true if FileTest.exist?(project.path)
57
+ Overapp.ec "mkdir #{project.path}", :silent => true
58
+ File.create "#{project.path}/.overlay",config_body
59
+ files.each do |f|
60
+ File.create "#{project.path}/#{f.path}",f.body
61
+ end
62
+ end
63
+
32
64
  def file(path,body,overlay_ops={})
33
65
  if overlay_ops.size > 0
34
66
  inner = []
@@ -52,8 +84,9 @@ end
52
84
 
53
85
  shared_context "projects" do
54
86
  class << self
55
- def project(name="default",&b)
56
- dsl = ProjectDSL.new(:name => name)
87
+ def project(name="default",ops={},&b)
88
+ ops = {:name => name}.merge(ops)
89
+ dsl = ProjectDSL.new(ops)
57
90
  b[dsl]
58
91
  raise "project #{name} already exists" if project_dsls[name]
59
92
  self.project_dsls[name] = dsl
@@ -83,42 +116,55 @@ shared_context "projects" do
83
116
  end
84
117
  end
85
118
 
86
- let(:project) do
87
- self.class.project_dsls.values.first.project
119
+ def dsls
120
+ self.class.project_dsls.values
121
+ end
122
+
123
+ def main_project
124
+ mains = dsls.select { |x| x.main }
125
+ raise "bad" if mains.size > 1
126
+ (mains.first || dsls.first).project
127
+ end
128
+
129
+ def project(name=nil)
130
+ if name
131
+ self.class.project_dsls[name].project
132
+ else
133
+ main_project
134
+ end
88
135
  end
89
136
 
90
137
  let(:combined) do
91
138
  project.combined_files
92
139
  end
93
140
 
141
+ def find_dsl(dir)
142
+ dsl = self.class.project_dsls.values.find { |x| x.project.path == dir || x.name.to_s == dir.to_s }
143
+ raise "no dir #{dir}, possible: \n" + self.class.project_dsls.values.map { |x| x.project.path }.join("\n") unless dsl
144
+ dsl
145
+ end
146
+
147
+ let(:mock_file_methods) { true }
148
+
94
149
  before do
95
- Overapp.stub(:dir_files_full) do |dir|
96
- dsl = self.class.project_dsls.values.find { |x| x.project.path == dir || x.name.to_s == dir.to_s }
97
- if dsl
98
- dsl.files.map do |f|
150
+ if mock_file_methods
151
+ Overapp.stub(:dir_files_full) do |dir|
152
+ find_dsl(dir).files.map do |f|
99
153
  {:file => f.path, :body => f.body}
100
154
  end
101
- else
102
- raise "no dir #{dir}, possible: \n" + self.class.project_dsls.values.map { |x| x.project.path }.join("\n")
103
155
  end
104
- end
105
156
 
106
- Overapp::Project.stub("project?") do |dir|
107
- dsl = self.class.project_dsls.values.find { |x| x.project.path == dir || x.name.to_s == dir.to_s }
108
- if dsl
109
- dsl.config.present?
110
- else
111
- raise "no dir #{dir}, possible: \n" + self.class.project_dsls.values.map { |x| x.project.path }.join("\n")
157
+ Overapp::Project.stub("project?") do |dir|
158
+ find_dsl(dir).config_body.present?
112
159
  end
113
- end
114
160
 
115
- Overapp::Project.stub("load") do |ops|
116
- dir = ops[:path]
117
- dsl = self.class.project_dsls.values.find { |x| x.project.path == dir || x.name.to_s == dir.to_s }
118
- if dsl
119
- dsl.project
120
- else
121
- raise "no dir #{dir}, possible: \n" + self.class.project_dsls.values.map { |x| x.project.path }.join("\n")
161
+ Overapp::Project.stub("load") do |ops|
162
+ dir = ops[:path]
163
+ find_dsl(dir).project
164
+ end
165
+ else
166
+ self.class.project_dsls.values.each do |dsl|
167
+ dsl.write_to_tmp!
122
168
  end
123
169
  end
124
170
 
@@ -37,7 +37,7 @@ describe 'Template' do
37
37
  end
38
38
 
39
39
  it 'works' do
40
- template_file.parsed.full_body.should == "\n4"
40
+ template_file.combined(nil).full_body.should == "\n4"
41
41
  end
42
42
  end
43
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Harris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-22 00:00:00.000000000 Z
11
+ date: 2013-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mharris_ext
@@ -185,7 +185,7 @@ executables:
185
185
  extensions: []
186
186
  extra_rdoc_files:
187
187
  - LICENSE.txt
188
- - README.rdoc
188
+ - README.md
189
189
  files:
190
190
  - .document
191
191
  - .rspec
@@ -193,7 +193,7 @@ files:
193
193
  - Gemfile.lock
194
194
  - Guardfile
195
195
  - LICENSE.txt
196
- - README.rdoc
196
+ - README.md
197
197
  - Rakefile
198
198
  - VERSION
199
199
  - bin/overapp
@@ -219,14 +219,17 @@ files:
219
219
  - lib/overapp/template_file/var_obj.rb
220
220
  - lib/overapp/util/cmd.rb
221
221
  - lib/overapp/util/dir.rb
222
+ - lib/overapp/util/file.rb
222
223
  - lib/overapp/util/git.rb
223
224
  - lib/overapp/util/tmp_dir.rb
224
225
  - lib/overapp/util/write.rb
225
226
  - lib/overapp/var.rb
226
227
  - overapp.gemspec
228
+ - spec/binary_copy_spec.rb
227
229
  - spec/command_replacement_spec.rb
228
230
  - spec/from_command_spec.rb
229
231
  - spec/git_spec.rb
232
+ - spec/input/rails.png
230
233
  - spec/input/rails_post_overlay/.overapp
231
234
  - spec/input/rails_post_overlay/app/models/post.rb
232
235
  - spec/input/rails_widget_overlay/.overapp