architecture 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/architecture.rb +16 -0
- data/lib/architecture/append.rb +24 -0
- data/lib/architecture/contentable.rb +15 -0
- data/lib/architecture/copy.rb +24 -0
- data/lib/architecture/delete.rb +13 -0
- data/lib/architecture/dsl.rb +64 -0
- data/lib/architecture/entity.rb +55 -0
- data/lib/architecture/entityable.rb +7 -0
- data/lib/architecture/move.rb +14 -0
- data/lib/architecture/overwrite.rb +20 -0
- data/lib/architecture/prepend.rb +24 -0
- data/lib/architecture/replace.rb +27 -0
- data/lib/architecture/replicatable.rb +11 -0
- data/lib/architecture/version.rb +3 -0
- data/spec/lib/architecture/append_spec.rb +71 -0
- data/spec/lib/architecture/copy_spec.rb +83 -0
- data/spec/lib/architecture/delete_spec.rb +34 -0
- data/spec/lib/architecture/move_spec.rb +44 -0
- data/spec/lib/architecture/overwrite_spec.rb +71 -0
- data/spec/lib/architecture/prepend_spec.rb +71 -0
- data/spec/lib/architecture/replace_spec.rb +71 -0
- data/spec/lib/architecture/version_spec.rb +7 -0
- data/spec/lib/architecture_spec.rb +5 -0
- data/spec/spec_helper.rb +6 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: abd87b7135ee8dfdb645b2a611c57b3962b78d04
|
4
|
+
data.tar.gz: 2ea7d41cd060d2fbb1f0a2a5598edf6c8ba61fd5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a13127394c2fafe79f77f0c5774b6fdc79ee0b5048200a2fe010b787bd8fc52e7d4a4c538325e818369b35e3ffb6fb7e5da28905d23880393c5d116575edc37a
|
7
|
+
data.tar.gz: 736bc77ed665561a7b4244d01f3f60aea3156fed2c37a9c25745bae790fd1b52fddd02938372d3a247594d07d30856ad029b52c51c6cdacfb9e7fb52ad8673b5
|
data/lib/architecture.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "mustache"
|
2
|
+
|
3
|
+
module Architecture
|
4
|
+
require_relative "architecture/contentable"
|
5
|
+
require_relative "architecture/entityable"
|
6
|
+
require_relative "architecture/replicatable"
|
7
|
+
require_relative "architecture/append"
|
8
|
+
require_relative "architecture/copy"
|
9
|
+
require_relative "architecture/delete"
|
10
|
+
require_relative "architecture/entity"
|
11
|
+
require_relative "architecture/move"
|
12
|
+
require_relative "architecture/overwrite"
|
13
|
+
require_relative "architecture/prepend"
|
14
|
+
require_relative "architecture/replace"
|
15
|
+
require_relative "architecture/version"
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Architecture
|
2
|
+
class Append
|
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 entity.file?
|
14
|
+
entity.write(text: data)
|
15
|
+
else
|
16
|
+
raise ArgumentError, "Source wasn't a file"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private def content
|
21
|
+
entity.content + @content
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Architecture
|
2
|
+
class Copy
|
3
|
+
include Replicatable
|
4
|
+
include Contentable
|
5
|
+
|
6
|
+
def initialize(source:, destination:, context: {})
|
7
|
+
@origin = Entity.new(path: source)
|
8
|
+
@clone = Entity.new(path: destination)
|
9
|
+
@context = context
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
if origin.file? && context.any?
|
14
|
+
clone.write(text: data)
|
15
|
+
else
|
16
|
+
origin.copy(entity: clone)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private def content
|
21
|
+
origin.content
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "architecture"
|
2
|
+
|
3
|
+
module Architecture
|
4
|
+
class DSL
|
5
|
+
def initialize(source:, destination:)
|
6
|
+
@source = source
|
7
|
+
@destination = destination
|
8
|
+
|
9
|
+
yield
|
10
|
+
end
|
11
|
+
|
12
|
+
private def copy(name:, as: name, context: {})
|
13
|
+
::Architecture::Copy.new(source: source(name), destination: destination(as), context: context).call
|
14
|
+
end
|
15
|
+
|
16
|
+
private def move(name:, as:)
|
17
|
+
::Architecture::Move.new(source: path, destination: as).call
|
18
|
+
end
|
19
|
+
|
20
|
+
private def create(path:, content:, context: {})
|
21
|
+
::Architecture::Create.new(source: path, content: content, context: context).call
|
22
|
+
end
|
23
|
+
|
24
|
+
private def delete(path:)
|
25
|
+
::Architecture::Delete.new(source: path).call
|
26
|
+
end
|
27
|
+
|
28
|
+
private def replace(path:, search:, content:)
|
29
|
+
::Architecture::Replace.new(source: path, search: search, content: content).call
|
30
|
+
end
|
31
|
+
|
32
|
+
private def prepend(path:, content:, context: {})
|
33
|
+
::Architecture::Prepend.new(source: path, content: content, context: context).call
|
34
|
+
end
|
35
|
+
|
36
|
+
private def append(path:, content:)
|
37
|
+
::Architecture::Append.new(source: path, content: content, context: context).call
|
38
|
+
end
|
39
|
+
|
40
|
+
private def overwrite(path:, content:, context: {})
|
41
|
+
::Architecture::Overwrite.new(source: path, content: content, context: context).call
|
42
|
+
end
|
43
|
+
|
44
|
+
private def within(path:, &block)
|
45
|
+
::Architecture::DSL.new(source: source(path), destination: destination(path), &block).call
|
46
|
+
end
|
47
|
+
|
48
|
+
private def source(path)
|
49
|
+
join(@source, path)
|
50
|
+
end
|
51
|
+
|
52
|
+
private def destination(path)
|
53
|
+
join(@destination, path)
|
54
|
+
end
|
55
|
+
|
56
|
+
private def join(*paths)
|
57
|
+
::File.join(*paths)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def architecture(source:, destination:, &block)
|
63
|
+
::Architecture::DSL.new(source: source, destination: destination, &block)
|
64
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Architecture
|
2
|
+
class Entity
|
3
|
+
def initialize(path:)
|
4
|
+
@path
|
5
|
+
end
|
6
|
+
|
7
|
+
def location
|
8
|
+
::File.expand_path(@location)
|
9
|
+
end
|
10
|
+
|
11
|
+
def content
|
12
|
+
if file?
|
13
|
+
::File.read(location)
|
14
|
+
else
|
15
|
+
""
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(text:)
|
20
|
+
::File.write(location, text)
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy(entity:)
|
24
|
+
system("cp #{location} #{entity.location}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete
|
28
|
+
system("rm -rf #{location}")
|
29
|
+
end
|
30
|
+
|
31
|
+
def move(entity:)
|
32
|
+
system("mv #{location} #{entity.location}")
|
33
|
+
end
|
34
|
+
|
35
|
+
private def path
|
36
|
+
@path
|
37
|
+
end
|
38
|
+
|
39
|
+
def file?
|
40
|
+
!directory?
|
41
|
+
end
|
42
|
+
|
43
|
+
def directory?
|
44
|
+
type == "application/x-directory"
|
45
|
+
end
|
46
|
+
|
47
|
+
private def type
|
48
|
+
system("file --mime-type --brief #{location}")
|
49
|
+
end
|
50
|
+
|
51
|
+
private def system(command)
|
52
|
+
`#{command}`
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Architecture
|
2
|
+
class Overwrite
|
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 entity.file?
|
14
|
+
entity.write(text: data)
|
15
|
+
else
|
16
|
+
raise ArgumentError, "Source wasn't a file"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Architecture
|
2
|
+
class Prepend
|
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 entity.file?
|
14
|
+
entity.write(text: data)
|
15
|
+
else
|
16
|
+
raise ArgumentError, "Source wasn't a file"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private def content
|
21
|
+
@content + entity.content
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Architecture
|
2
|
+
class Replace
|
3
|
+
include Entityable
|
4
|
+
|
5
|
+
def initialize(source:, search: "", content: "")
|
6
|
+
@entity = Entity.new(path: source)
|
7
|
+
@search = search
|
8
|
+
@content = content
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
if entity.file?
|
13
|
+
entity.write(text: content)
|
14
|
+
else
|
15
|
+
raise ArgumentError, "Source wasn't a file"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private def content
|
20
|
+
entity.content.gsub(search, @content)
|
21
|
+
end
|
22
|
+
|
23
|
+
private def search
|
24
|
+
@search
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Architecture::Append do
|
4
|
+
let("entity") do
|
5
|
+
instance_double(Architecture::Entity)
|
6
|
+
end
|
7
|
+
|
8
|
+
let("source") do
|
9
|
+
"path"
|
10
|
+
end
|
11
|
+
|
12
|
+
let("content") do
|
13
|
+
"end"
|
14
|
+
end
|
15
|
+
|
16
|
+
let("contexts") do
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
|
20
|
+
let("append") do
|
21
|
+
described_class.new(source: source, content: content, context: contexts)
|
22
|
+
end
|
23
|
+
|
24
|
+
let("file") do
|
25
|
+
"start"
|
26
|
+
end
|
27
|
+
|
28
|
+
let("result") do
|
29
|
+
file + content
|
30
|
+
end
|
31
|
+
|
32
|
+
before("each") do
|
33
|
+
allow(entity).to receive("file?").and_return(true)
|
34
|
+
allow(entity).to receive("content").and_return(file)
|
35
|
+
allow(entity).to receive("write").and_return(false)
|
36
|
+
allow(append).to receive("entity").and_return(entity)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#call" do
|
40
|
+
let("call") do
|
41
|
+
append.call
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with a file as source" do
|
45
|
+
before("each") do
|
46
|
+
allow(entity).to receive("file?").and_return(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "copies the file" do
|
50
|
+
expect(entity).to receive("write").with(text: result)
|
51
|
+
call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with a context" do
|
56
|
+
it "renders the context" do
|
57
|
+
# ...
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with a directory as source" do
|
62
|
+
before("each") do
|
63
|
+
allow(entity).to receive("file?").and_return(false)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises an exception" do
|
67
|
+
expect { call }.to raise_exception(ArgumentError, "Source wasn't a file")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Architecture::Copy do
|
4
|
+
let("clone") do
|
5
|
+
instance_double(Architecture::Entity)
|
6
|
+
end
|
7
|
+
|
8
|
+
let("origin") do
|
9
|
+
instance_double(Architecture::Entity)
|
10
|
+
end
|
11
|
+
|
12
|
+
let("source") do
|
13
|
+
"old"
|
14
|
+
end
|
15
|
+
|
16
|
+
let("destination") do
|
17
|
+
"new"
|
18
|
+
end
|
19
|
+
|
20
|
+
let("contexts") do
|
21
|
+
{}
|
22
|
+
end
|
23
|
+
|
24
|
+
let("content") do
|
25
|
+
"{{foo}}"
|
26
|
+
end
|
27
|
+
|
28
|
+
let("copy") do
|
29
|
+
described_class.new(source: source, destination: destination, context: contexts)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#call" do
|
33
|
+
let("call") do
|
34
|
+
copy.call
|
35
|
+
end
|
36
|
+
|
37
|
+
before("each") do
|
38
|
+
allow(copy).to receive("origin").and_return(origin)
|
39
|
+
allow(copy).to receive("clone").and_return(clone)
|
40
|
+
allow(origin).to receive("location").and_return(source)
|
41
|
+
allow(origin).to receive("content").and_return(content)
|
42
|
+
allow(clone).to receive("location").and_return(destination)
|
43
|
+
end
|
44
|
+
|
45
|
+
after("each") do
|
46
|
+
call
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with a file as source" do
|
50
|
+
before("each") do
|
51
|
+
allow(origin).to receive("file?").and_return(true)
|
52
|
+
end
|
53
|
+
|
54
|
+
context "without a context" do
|
55
|
+
it "copies the file" do
|
56
|
+
expect(origin).to receive("copy").with(entity: clone)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with a context" do
|
61
|
+
let("contexts") do
|
62
|
+
{
|
63
|
+
"foo" => "bar"
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
it "creates a file with the rendered content" do
|
68
|
+
expect(clone).to receive("write").with(text: "bar")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "with a directory as source" do
|
74
|
+
before("each") do
|
75
|
+
allow(origin).to receive("file?").and_return(false)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "copies the directory" do
|
79
|
+
expect(origin).to receive("copy").with(entity: clone)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Architecture::Delete do
|
4
|
+
let("entity") do
|
5
|
+
instance_double(Architecture::Entity)
|
6
|
+
end
|
7
|
+
|
8
|
+
let("source") do
|
9
|
+
"old"
|
10
|
+
end
|
11
|
+
|
12
|
+
let("delete") do
|
13
|
+
described_class.new(source: source)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#call" do
|
17
|
+
let("call") do
|
18
|
+
delete.call
|
19
|
+
end
|
20
|
+
|
21
|
+
before("each") do
|
22
|
+
allow(delete).to receive("entity").and_return(entity)
|
23
|
+
allow(entity).to receive("location").and_return(source)
|
24
|
+
end
|
25
|
+
|
26
|
+
after("each") do
|
27
|
+
call
|
28
|
+
end
|
29
|
+
|
30
|
+
it "moves the file" do
|
31
|
+
expect(entity).to receive("delete")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Architecture::Move do
|
4
|
+
let("clone") do
|
5
|
+
instance_double(Architecture::Entity)
|
6
|
+
end
|
7
|
+
|
8
|
+
let("origin") do
|
9
|
+
instance_double(Architecture::Entity)
|
10
|
+
end
|
11
|
+
|
12
|
+
let("source") do
|
13
|
+
"old"
|
14
|
+
end
|
15
|
+
|
16
|
+
let("destination") do
|
17
|
+
"new"
|
18
|
+
end
|
19
|
+
|
20
|
+
let("move") do
|
21
|
+
described_class.new(source: source, destination: destination)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#call" do
|
25
|
+
let("call") do
|
26
|
+
move.call
|
27
|
+
end
|
28
|
+
|
29
|
+
before("each") do
|
30
|
+
allow(move).to receive("origin").and_return(origin)
|
31
|
+
allow(move).to receive("clone").and_return(clone)
|
32
|
+
allow(origin).to receive("location").and_return(source)
|
33
|
+
allow(clone).to receive("location").and_return(destination)
|
34
|
+
end
|
35
|
+
|
36
|
+
after("each") do
|
37
|
+
call
|
38
|
+
end
|
39
|
+
|
40
|
+
it "moves the file" do
|
41
|
+
expect(origin).to receive("move").with(entity: clone)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Architecture::Overwrite do
|
4
|
+
let("entity") do
|
5
|
+
instance_double(Architecture::Entity)
|
6
|
+
end
|
7
|
+
|
8
|
+
let("source") do
|
9
|
+
"path"
|
10
|
+
end
|
11
|
+
|
12
|
+
let("content") do
|
13
|
+
"end"
|
14
|
+
end
|
15
|
+
|
16
|
+
let("contexts") do
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
|
20
|
+
let("overwrite") do
|
21
|
+
described_class.new(source: source, content: content, context: contexts)
|
22
|
+
end
|
23
|
+
|
24
|
+
let("file") do
|
25
|
+
"start"
|
26
|
+
end
|
27
|
+
|
28
|
+
let("result") do
|
29
|
+
content
|
30
|
+
end
|
31
|
+
|
32
|
+
before("each") do
|
33
|
+
allow(entity).to receive("file?").and_return(true)
|
34
|
+
allow(entity).to receive("content").and_return(file)
|
35
|
+
allow(entity).to receive("write").and_return(false)
|
36
|
+
allow(overwrite).to receive("entity").and_return(entity)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#call" do
|
40
|
+
let("call") do
|
41
|
+
overwrite.call
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with a file as source" do
|
45
|
+
before("each") do
|
46
|
+
allow(entity).to receive("file?").and_return(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "copies the file" do
|
50
|
+
expect(entity).to receive("write").with(text: result)
|
51
|
+
call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with a context" do
|
56
|
+
it "renders the context" do
|
57
|
+
# ...
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with a directory as source" do
|
62
|
+
before("each") do
|
63
|
+
allow(entity).to receive("file?").and_return(false)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises an exception" do
|
67
|
+
expect { call }.to raise_exception(ArgumentError, "Source wasn't a file")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Architecture::Prepend do
|
4
|
+
let("entity") do
|
5
|
+
instance_double(Architecture::Entity)
|
6
|
+
end
|
7
|
+
|
8
|
+
let("source") do
|
9
|
+
"path"
|
10
|
+
end
|
11
|
+
|
12
|
+
let("content") do
|
13
|
+
"end"
|
14
|
+
end
|
15
|
+
|
16
|
+
let("contexts") do
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
|
20
|
+
let("prepend") do
|
21
|
+
described_class.new(source: source, content: content, context: contexts)
|
22
|
+
end
|
23
|
+
|
24
|
+
let("file") do
|
25
|
+
"start"
|
26
|
+
end
|
27
|
+
|
28
|
+
let("result") do
|
29
|
+
content + file
|
30
|
+
end
|
31
|
+
|
32
|
+
before("each") do
|
33
|
+
allow(entity).to receive("file?").and_return(true)
|
34
|
+
allow(entity).to receive("content").and_return(file)
|
35
|
+
allow(entity).to receive("write").and_return(false)
|
36
|
+
allow(prepend).to receive("entity").and_return(entity)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#call" do
|
40
|
+
let("call") do
|
41
|
+
prepend.call
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with a file as source" do
|
45
|
+
before("each") do
|
46
|
+
allow(entity).to receive("file?").and_return(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "copies the file" do
|
50
|
+
expect(entity).to receive("write").with(text: result)
|
51
|
+
call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with a context" do
|
56
|
+
it "renders the context" do
|
57
|
+
# ...
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with a directory as source" do
|
62
|
+
before("each") do
|
63
|
+
allow(entity).to receive("file?").and_return(false)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises an exception" do
|
67
|
+
expect { call }.to raise_exception(ArgumentError, "Source wasn't a file")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Architecture::Replace do
|
4
|
+
let("entity") do
|
5
|
+
instance_double(Architecture::Entity)
|
6
|
+
end
|
7
|
+
|
8
|
+
let("source") do
|
9
|
+
"path"
|
10
|
+
end
|
11
|
+
|
12
|
+
let("content") do
|
13
|
+
"tarten"
|
14
|
+
end
|
15
|
+
|
16
|
+
let("file") do
|
17
|
+
"sfood"
|
18
|
+
end
|
19
|
+
|
20
|
+
let("search") do
|
21
|
+
"foo"
|
22
|
+
end
|
23
|
+
|
24
|
+
let("replace") do
|
25
|
+
described_class.new(source: source, search: search, content: content)
|
26
|
+
end
|
27
|
+
|
28
|
+
let("result") do
|
29
|
+
"startend"
|
30
|
+
end
|
31
|
+
|
32
|
+
before("each") do
|
33
|
+
allow(entity).to receive("file?").and_return(true)
|
34
|
+
allow(entity).to receive("content").and_return(file)
|
35
|
+
allow(entity).to receive("write").and_return(false)
|
36
|
+
allow(replace).to receive("entity").and_return(entity)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#call" do
|
40
|
+
let("call") do
|
41
|
+
replace.call
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with a file as source" do
|
45
|
+
before("each") do
|
46
|
+
allow(entity).to receive("file?").and_return(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "copies the file" do
|
50
|
+
expect(entity).to receive("write").with(text: result)
|
51
|
+
call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with a context" do
|
56
|
+
it "renders the context" do
|
57
|
+
# ...
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with a directory as source" do
|
62
|
+
before("each") do
|
63
|
+
allow(entity).to receive("file?").and_return(false)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises an exception" do
|
67
|
+
expect { call }.to raise_exception(ArgumentError, "Source wasn't a file")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: architecture
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kurtis Rainbolt-Greene
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mustache
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.99'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.99'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-doc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.4'
|
111
|
+
description: A DSL and object space for handling scaffolding
|
112
|
+
email:
|
113
|
+
- me@kurtisrainboltgreene.name
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- lib/architecture.rb
|
119
|
+
- lib/architecture/append.rb
|
120
|
+
- lib/architecture/contentable.rb
|
121
|
+
- lib/architecture/copy.rb
|
122
|
+
- lib/architecture/delete.rb
|
123
|
+
- lib/architecture/dsl.rb
|
124
|
+
- lib/architecture/entity.rb
|
125
|
+
- lib/architecture/entityable.rb
|
126
|
+
- lib/architecture/move.rb
|
127
|
+
- lib/architecture/overwrite.rb
|
128
|
+
- lib/architecture/prepend.rb
|
129
|
+
- lib/architecture/replace.rb
|
130
|
+
- lib/architecture/replicatable.rb
|
131
|
+
- lib/architecture/version.rb
|
132
|
+
- spec/lib/architecture/append_spec.rb
|
133
|
+
- spec/lib/architecture/copy_spec.rb
|
134
|
+
- spec/lib/architecture/delete_spec.rb
|
135
|
+
- spec/lib/architecture/move_spec.rb
|
136
|
+
- spec/lib/architecture/overwrite_spec.rb
|
137
|
+
- spec/lib/architecture/prepend_spec.rb
|
138
|
+
- spec/lib/architecture/replace_spec.rb
|
139
|
+
- spec/lib/architecture/version_spec.rb
|
140
|
+
- spec/lib/architecture_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
homepage: http://krainboltgreene.github.io/architecture
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.4.3
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: A DSL and object space for handling scaffolding
|
166
|
+
test_files:
|
167
|
+
- spec/lib/architecture/append_spec.rb
|
168
|
+
- spec/lib/architecture/copy_spec.rb
|
169
|
+
- spec/lib/architecture/delete_spec.rb
|
170
|
+
- spec/lib/architecture/move_spec.rb
|
171
|
+
- spec/lib/architecture/overwrite_spec.rb
|
172
|
+
- spec/lib/architecture/prepend_spec.rb
|
173
|
+
- spec/lib/architecture/replace_spec.rb
|
174
|
+
- spec/lib/architecture/version_spec.rb
|
175
|
+
- spec/lib/architecture_spec.rb
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
has_rdoc:
|