architecture 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abd87b7135ee8dfdb645b2a611c57b3962b78d04
4
- data.tar.gz: 2ea7d41cd060d2fbb1f0a2a5598edf6c8ba61fd5
3
+ metadata.gz: ae26d00c4b207690ecbbccddc3625597714a600b
4
+ data.tar.gz: f07a6b80dee45ebdd2eda912157d750fb687adae
5
5
  SHA512:
6
- metadata.gz: a13127394c2fafe79f77f0c5774b6fdc79ee0b5048200a2fe010b787bd8fc52e7d4a4c538325e818369b35e3ffb6fb7e5da28905d23880393c5d116575edc37a
7
- data.tar.gz: 736bc77ed665561a7b4244d01f3f60aea3156fed2c37a9c25745bae790fd1b52fddd02938372d3a247594d07d30856ad029b52c51c6cdacfb9e7fb52ad8673b5
6
+ metadata.gz: 77134944335f22ce47bc92e0f7bbde380dead39d83ac63fdc31e4345a1d0037d31c66da5a396ca9607349a993aba63bde4c0e07ab687bdbc0d42e9d032587b7d
7
+ data.tar.gz: 5e184bfd40e3da9c8986ec788ee8beb72bfbacfb31e739cf1e9a54ddd2642277c2ebcb94d148a49a7d11df3a04125336635cb8fb6fd66210f20def67fabae212
@@ -0,0 +1,20 @@
1
+ module Architecture
2
+ class Create
3
+ include Entityable
4
+ include Contentable
5
+
6
+ def initialize(source:, content:, context:)
7
+ @entity = Entity.new(path: source)
8
+ @content = content
9
+ @context = context
10
+ end
11
+
12
+ def call
13
+ if content.nil? || context.empty?
14
+ entity.create
15
+ else
16
+ entity.write(text: data)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -17,7 +17,7 @@ module Architecture
17
17
  ::Architecture::Move.new(source: path, destination: as).call
18
18
  end
19
19
 
20
- private def create(path:, content:, context: {})
20
+ private def create(path:, content: nil, context: {})
21
21
  ::Architecture::Create.new(source: path, content: content, context: context).call
22
22
  end
23
23
 
@@ -24,12 +24,16 @@ module Architecture
24
24
  system("cp #{location} #{entity.location}")
25
25
  end
26
26
 
27
+ def move(entity:)
28
+ system("mv #{location} #{entity.location}")
29
+ end
30
+
27
31
  def delete
28
32
  system("rm -rf #{location}")
29
33
  end
30
34
 
31
- def move(entity:)
32
- system("mv #{location} #{entity.location}")
35
+ def create
36
+ system("mkdir -p #{location}")
33
37
  end
34
38
 
35
39
  private def path
@@ -1,3 +1,3 @@
1
1
  module Architecture
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/architecture.rb CHANGED
@@ -4,10 +4,11 @@ module Architecture
4
4
  require_relative "architecture/contentable"
5
5
  require_relative "architecture/entityable"
6
6
  require_relative "architecture/replicatable"
7
+ require_relative "architecture/entity"
7
8
  require_relative "architecture/append"
8
9
  require_relative "architecture/copy"
9
10
  require_relative "architecture/delete"
10
- require_relative "architecture/entity"
11
+ require_relative "architecture/create"
11
12
  require_relative "architecture/move"
12
13
  require_relative "architecture/overwrite"
13
14
  require_relative "architecture/prepend"
@@ -64,7 +64,7 @@ RSpec.describe Architecture::Copy do
64
64
  }
65
65
  end
66
66
 
67
- it "creates a file with the rendered content" do
67
+ it "copies and renders the file" do
68
68
  expect(clone).to receive("write").with(text: "bar")
69
69
  end
70
70
  end
@@ -0,0 +1,72 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Architecture::Create do
4
+ let("entity") do
5
+ instance_double(Architecture::Entity)
6
+ end
7
+
8
+ let("source") do
9
+ "old"
10
+ end
11
+
12
+ let("content") do
13
+ "{{foo}}"
14
+ end
15
+
16
+ let("contexts") do
17
+ {}
18
+ end
19
+
20
+ let("create") do
21
+ described_class.new(source: source, content: content, context: contexts)
22
+ end
23
+
24
+ describe "#call" do
25
+ let("call") do
26
+ create.call
27
+ end
28
+
29
+ before("each") do
30
+ allow(create).to receive("entity").and_return(entity)
31
+ allow(entity).to receive("location").and_return(source)
32
+ end
33
+
34
+ after("each") do
35
+ call
36
+ end
37
+
38
+ context "with a file as source" do
39
+ before("each") do
40
+ allow(entity).to receive("file?").and_return(true)
41
+ end
42
+
43
+ context "with a context" do
44
+ let("contexts") do
45
+ {
46
+ "foo" => "bar"
47
+ }
48
+ end
49
+
50
+ it "creates a file with the rendered content" do
51
+ expect(entity).to receive("write").with(text: "bar")
52
+ end
53
+ end
54
+
55
+ context "without a context" do
56
+ it "copies the file" do
57
+ expect(entity).to receive("create")
58
+ end
59
+ end
60
+ end
61
+
62
+ context "with a directory as source" do
63
+ let("content") do
64
+ nil
65
+ end
66
+
67
+ it "creates the directory" do
68
+ expect(entity).to receive("create")
69
+ end
70
+ end
71
+ end
72
+ end
@@ -27,7 +27,7 @@ RSpec.describe Architecture::Delete do
27
27
  call
28
28
  end
29
29
 
30
- it "moves the file" do
30
+ it "deletes the file" do
31
31
  expect(entity).to receive("delete")
32
32
  end
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: architecture
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurtis Rainbolt-Greene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-02 00:00:00.000000000 Z
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mustache
@@ -119,6 +119,7 @@ files:
119
119
  - lib/architecture/append.rb
120
120
  - lib/architecture/contentable.rb
121
121
  - lib/architecture/copy.rb
122
+ - lib/architecture/create.rb
122
123
  - lib/architecture/delete.rb
123
124
  - lib/architecture/dsl.rb
124
125
  - lib/architecture/entity.rb
@@ -131,6 +132,7 @@ files:
131
132
  - lib/architecture/version.rb
132
133
  - spec/lib/architecture/append_spec.rb
133
134
  - spec/lib/architecture/copy_spec.rb
135
+ - spec/lib/architecture/create_spec.rb
134
136
  - spec/lib/architecture/delete_spec.rb
135
137
  - spec/lib/architecture/move_spec.rb
136
138
  - spec/lib/architecture/overwrite_spec.rb
@@ -166,6 +168,7 @@ summary: A DSL and object space for handling scaffolding
166
168
  test_files:
167
169
  - spec/lib/architecture/append_spec.rb
168
170
  - spec/lib/architecture/copy_spec.rb
171
+ - spec/lib/architecture/create_spec.rb
169
172
  - spec/lib/architecture/delete_spec.rb
170
173
  - spec/lib/architecture/move_spec.rb
171
174
  - spec/lib/architecture/overwrite_spec.rb