architecture 5.2.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/architecture.rb +4 -0
- data/lib/architecture/append.rb +3 -3
- data/lib/architecture/copy.rb +3 -3
- data/lib/architecture/create.rb +2 -2
- data/lib/architecture/delete.rb +1 -1
- data/lib/architecture/dsl.rb +96 -25
- data/lib/architecture/entity.rb +4 -2
- data/lib/architecture/move.rb +2 -2
- data/lib/architecture/overwrite.rb +3 -3
- data/lib/architecture/prepend.rb +3 -3
- data/lib/architecture/replace.rb +3 -3
- data/lib/architecture/version.rb +1 -1
- data/spec/lib/architecture/entity_spec.rb +20 -4
- data/spec/lib/architecture/version_spec.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0018a5e560bdab42d3233c1787f1f7d5deedb46
|
4
|
+
data.tar.gz: 110444d0a95fc6474f87213028fa3b1d3756c569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85f72b3371d8640b7bb2b864cec8c918ff63351abd309e4952a8cfd771d62dc4d1fe326526234c99ac523fd2e096a1b99a2934d1f426fc61558b632701daab8e
|
7
|
+
data.tar.gz: 1d5fa573a11c11fdf6d0556f2c8ae0e6b3a6ccb43691ebe2a5ba597ddb972d031388241bdabdd619e8e942c06a8911c6d6830523fb43612a9dd1931055165f96
|
data/lib/architecture.rb
CHANGED
@@ -15,6 +15,10 @@ module Architecture
|
|
15
15
|
require_relative "architecture/replace"
|
16
16
|
require_relative "architecture/version"
|
17
17
|
|
18
|
+
EMPTY_CONTEXT = {}
|
19
|
+
EMPTY_PATTERN = ""
|
20
|
+
EMPTY_CONTENT = ""
|
21
|
+
|
18
22
|
private def architecture(source:, destination:, &block)
|
19
23
|
::Architecture::DSL.new(source: source, destination: destination, &block)
|
20
24
|
end
|
data/lib/architecture/append.rb
CHANGED
@@ -3,8 +3,8 @@ module Architecture
|
|
3
3
|
include Entityable
|
4
4
|
include Contentable
|
5
5
|
|
6
|
-
def initialize(source:, content:
|
7
|
-
@entity =
|
6
|
+
def initialize(source:, content: Architecture::EMPTY_CONTENT, context: Architecture::EMPTY_CONTEXT)
|
7
|
+
@entity = source
|
8
8
|
@content = content
|
9
9
|
@context = context
|
10
10
|
end
|
@@ -13,7 +13,7 @@ module Architecture
|
|
13
13
|
if entity.file?
|
14
14
|
entity.write(text: data)
|
15
15
|
else
|
16
|
-
raise
|
16
|
+
raise(ArgumentError, "Source wasn't a file")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/architecture/copy.rb
CHANGED
@@ -3,9 +3,9 @@ module Architecture
|
|
3
3
|
include Replicatable
|
4
4
|
include Contentable
|
5
5
|
|
6
|
-
def initialize(source:, destination:, context:
|
7
|
-
@origin =
|
8
|
-
@clone =
|
6
|
+
def initialize(source:, destination:, context: Architecture::EMPTY_CONTEXT)
|
7
|
+
@origin = source
|
8
|
+
@clone = destination
|
9
9
|
@context = context
|
10
10
|
end
|
11
11
|
|
data/lib/architecture/create.rb
CHANGED
@@ -3,8 +3,8 @@ module Architecture
|
|
3
3
|
include Entityable
|
4
4
|
include Contentable
|
5
5
|
|
6
|
-
def initialize(source:, content
|
7
|
-
@entity =
|
6
|
+
def initialize(source:, content: Architecture::EMPTY_CONTENT, context: Architecture::EMPTY_CONTEXT)
|
7
|
+
@entity = source
|
8
8
|
@content = content
|
9
9
|
@context = context
|
10
10
|
end
|
data/lib/architecture/delete.rb
CHANGED
data/lib/architecture/dsl.rb
CHANGED
@@ -2,59 +2,130 @@ require "architecture"
|
|
2
2
|
|
3
3
|
module Architecture
|
4
4
|
class DSL
|
5
|
-
def initialize(source:, destination:)
|
5
|
+
def initialize(source:, destination:, output: STDOUT, level: 0)
|
6
6
|
@source = source
|
7
7
|
@destination = destination
|
8
|
+
@output = output
|
9
|
+
@level = level
|
8
10
|
|
9
11
|
yield(self)
|
10
12
|
end
|
11
13
|
|
12
|
-
def copy(file: nil, directory: nil, as: nil, context:
|
13
|
-
|
14
|
+
def copy(file: nil, directory: nil, as: nil, context: EMPTY_CONTEXT, &block)
|
15
|
+
a = Entity.new(id: directory || file, prefix: @source)
|
16
|
+
b = Entity.new(id: as || directory || file, prefix: @destination)
|
17
|
+
|
18
|
+
@output.print("#{indentention}Copying #{a} to #{b}")
|
19
|
+
|
20
|
+
Copy.new(source: a, destination: b, context: context)
|
21
|
+
|
22
|
+
@output.puts(" succeeded.")
|
23
|
+
|
24
|
+
if block_given? && directory
|
25
|
+
within(directory: directory)
|
26
|
+
end
|
14
27
|
end
|
15
28
|
|
16
|
-
def move(file: nil, directory: nil, as
|
17
|
-
|
29
|
+
def move(file: nil, directory: nil, as:, &block)
|
30
|
+
a = Entity.new(id: directory || file, prefix: @source)
|
31
|
+
b = Entity.new(id: as, prefix: @destination)
|
32
|
+
|
33
|
+
@output.print("#{indentention}Moving #{a} to #{b}")
|
34
|
+
|
35
|
+
Move.new(source: a, destination: b)
|
36
|
+
|
37
|
+
@output.puts(" succeeded.")
|
38
|
+
|
39
|
+
if block_given? && directory
|
40
|
+
within(directory: directory)
|
41
|
+
end
|
18
42
|
end
|
19
43
|
|
20
|
-
def create(
|
21
|
-
|
44
|
+
def create(file: nil, directory: nil, content: nil, context: EMPTY_CONTEXT, location: nil, &block)
|
45
|
+
a = Entity.new(id: directory || file, prefix: location || @destination)
|
46
|
+
|
47
|
+
@output.print("#{indentention}Creating #{a}")
|
48
|
+
|
49
|
+
Create.new(source: a, content: content, context: context)
|
50
|
+
|
51
|
+
@output.puts(" succeeded.")
|
52
|
+
|
53
|
+
if block_given? && directory
|
54
|
+
within(directory: directory)
|
55
|
+
end
|
22
56
|
end
|
23
57
|
|
24
|
-
def delete(directory: nil, file: nil)
|
25
|
-
|
58
|
+
def delete(directory: nil, file: nil, location: nil)
|
59
|
+
a = Entity.new(id: directory || file, prefix: location || @destination)
|
60
|
+
|
61
|
+
@output.print("#{indentention}Deleting #{a}")
|
62
|
+
|
63
|
+
Delete.new(source: a)
|
64
|
+
|
65
|
+
@output.puts(" succeeded.")
|
26
66
|
end
|
27
67
|
|
28
|
-
def replace(file
|
29
|
-
|
68
|
+
def replace(file:, search:, content:, location: nil)
|
69
|
+
a = Entity.new(id: directory || file, prefix: location || @destination)
|
70
|
+
|
71
|
+
@output.print("#{indentention}Replacing content in #{a}")
|
72
|
+
|
73
|
+
Replace.new(source: a, search: search, content: content)
|
74
|
+
|
75
|
+
@output.puts(" succeeded.")
|
30
76
|
end
|
31
77
|
|
32
|
-
def prepend(file
|
33
|
-
|
78
|
+
def prepend(file:, content:, context: Architecture::EMPTY_CONTEXT, location: nil)
|
79
|
+
a = Entity.new(id: directory || file, prefix: location || @destination)
|
80
|
+
|
81
|
+
@output.print("#{indentention}Prepending #{a} with content")
|
82
|
+
|
83
|
+
|
84
|
+
Prepend.new(source: a, content: content, context: context)
|
85
|
+
|
86
|
+
@output.puts(" succeeded.")
|
34
87
|
end
|
35
88
|
|
36
|
-
def append(file
|
37
|
-
|
89
|
+
def append(file:, content:, context: Architecture::EMPTY_CONTEXT, location: nil)
|
90
|
+
a = Entity.new(id: directory || file, prefix: location || @destination)
|
91
|
+
|
92
|
+
@output.print("#{indentention}Appending #{a}")
|
93
|
+
|
94
|
+
Append.new(source: a, content: content, context: context)
|
95
|
+
|
96
|
+
@output.puts(" succeeded.")
|
38
97
|
end
|
39
98
|
|
40
|
-
def overwrite(file
|
41
|
-
|
99
|
+
def overwrite(file:, content:, context: Architecture::EMPTY_CONTEXT, location: nil)
|
100
|
+
a = Entity.new(id: directory || file, prefix: location || @destination)
|
101
|
+
|
102
|
+
@output.print("#{indentention}Appending #{a}")
|
103
|
+
|
104
|
+
Overwrite.new(source: a, content: content, context: context)
|
105
|
+
|
106
|
+
@output.puts(" succeeded.")
|
107
|
+
end
|
108
|
+
|
109
|
+
def within(directory: nil, source: join(@source, directory), destination: join(@destination, directory), &block)
|
110
|
+
@output.print "#{indentention}Within #{destination}"
|
111
|
+
|
112
|
+
self.class.new(source: source, destination: destination, output: @output, level: @level + 1, &block)
|
42
113
|
end
|
43
114
|
|
44
|
-
def
|
45
|
-
|
115
|
+
private def source
|
116
|
+
@source
|
46
117
|
end
|
47
118
|
|
48
|
-
def
|
49
|
-
|
119
|
+
private def destination
|
120
|
+
@destination
|
50
121
|
end
|
51
122
|
|
52
|
-
def
|
53
|
-
join(
|
123
|
+
private def join(*ids)
|
124
|
+
File.join(*ids)
|
54
125
|
end
|
55
126
|
|
56
|
-
private def
|
57
|
-
|
127
|
+
private def indentention
|
128
|
+
"\t" * @level
|
58
129
|
end
|
59
130
|
end
|
60
131
|
end
|
data/lib/architecture/entity.rb
CHANGED
@@ -3,8 +3,10 @@ module Architecture
|
|
3
3
|
DIRECTORY_MIMETYPE = "application/x-directory"
|
4
4
|
DEFAULT_ENGINE = ::File
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(id:, prefix:)
|
7
|
+
@id = id
|
8
|
+
@prefix = prefix
|
9
|
+
@path = ::File.join(@prefix, @id)
|
8
10
|
end
|
9
11
|
|
10
12
|
def location(engine: DEFAULT_ENGINE)
|
data/lib/architecture/move.rb
CHANGED
@@ -3,8 +3,8 @@ module Architecture
|
|
3
3
|
include Entityable
|
4
4
|
include Contentable
|
5
5
|
|
6
|
-
def initialize(source:, content:
|
7
|
-
@entity =
|
6
|
+
def initialize(source:, content: Architecture::EMPTY_CONTENT, context: Architecture::EMPTY_CONTEXT)
|
7
|
+
@entity = source
|
8
8
|
@content = content
|
9
9
|
@context = context
|
10
10
|
end
|
@@ -13,7 +13,7 @@ module Architecture
|
|
13
13
|
if entity.file?
|
14
14
|
entity.write(text: data)
|
15
15
|
else
|
16
|
-
raise
|
16
|
+
raise(ArgumentError, "Source wasn't a file")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/architecture/prepend.rb
CHANGED
@@ -3,8 +3,8 @@ module Architecture
|
|
3
3
|
include Entityable
|
4
4
|
include Contentable
|
5
5
|
|
6
|
-
def initialize(source:, content:
|
7
|
-
@entity =
|
6
|
+
def initialize(source:, content: Architecture::EMPTY_CONTENT, context: Architecture::EMPTY_CONTEXT)
|
7
|
+
@entity = source
|
8
8
|
@content = content
|
9
9
|
@context = context
|
10
10
|
end
|
@@ -13,7 +13,7 @@ module Architecture
|
|
13
13
|
if entity.file?
|
14
14
|
entity.write(text: data)
|
15
15
|
else
|
16
|
-
raise
|
16
|
+
raise(ArgumentError, "Source wasn't a file")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/architecture/replace.rb
CHANGED
@@ -2,8 +2,8 @@ module Architecture
|
|
2
2
|
class Replace
|
3
3
|
include Entityable
|
4
4
|
|
5
|
-
def initialize(source:, search:
|
6
|
-
@entity =
|
5
|
+
def initialize(source:, search: Architecture::EMPTY_PATTERN, content: Architecture::EMPTY_CONTENT)
|
6
|
+
@entity = source
|
7
7
|
@search = search
|
8
8
|
@content = content
|
9
9
|
end
|
@@ -12,7 +12,7 @@ module Architecture
|
|
12
12
|
if entity.file?
|
13
13
|
entity.write(text: content)
|
14
14
|
else
|
15
|
-
raise
|
15
|
+
raise(ArgumentError, "Source wasn't a file")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/lib/architecture/version.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
RSpec.describe Architecture::Entity do
|
4
|
+
let("id") do
|
5
|
+
"baz.rb"
|
6
|
+
end
|
7
|
+
|
8
|
+
let("prefix") do
|
9
|
+
"foo/bar"
|
10
|
+
end
|
11
|
+
|
4
12
|
let("path") do
|
5
|
-
"foo/bar/baz"
|
13
|
+
"foo/bar/baz.rb"
|
6
14
|
end
|
7
15
|
|
8
16
|
let("entity") do
|
9
|
-
described_class.new(
|
17
|
+
described_class.new(id: id, prefix: prefix)
|
10
18
|
end
|
11
19
|
|
12
20
|
let("engine") do
|
@@ -42,16 +50,24 @@ RSpec.describe Architecture::Entity do
|
|
42
50
|
entity.file?
|
43
51
|
end
|
44
52
|
|
53
|
+
before(:each) do
|
54
|
+
allow(entity).to receive("type").and_return(type)
|
55
|
+
end
|
56
|
+
|
45
57
|
context "when path points to a file" do
|
58
|
+
let("type") do
|
59
|
+
"application/x-file"
|
60
|
+
end
|
46
61
|
it "returns true" do
|
47
|
-
allow(entity).to receive("type").and_return("application/x-file")
|
48
62
|
expect(file?).to be(true)
|
49
63
|
end
|
50
64
|
end
|
51
65
|
|
52
66
|
context "when path points to a directory" do
|
67
|
+
let("type") do
|
68
|
+
"application/x-directory"
|
69
|
+
end
|
53
70
|
it "returns false" do
|
54
|
-
allow(entity).to receive("type").and_return("application/x-directory")
|
55
71
|
expect(file?).to be(false)
|
56
72
|
end
|
57
73
|
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:
|
4
|
+
version: 6.0.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-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mustache
|
@@ -142,7 +142,7 @@ files:
|
|
142
142
|
- spec/lib/architecture/version_spec.rb
|
143
143
|
- spec/lib/architecture_spec.rb
|
144
144
|
- spec/spec_helper.rb
|
145
|
-
homepage: http://krainboltgreene.github.io/architecture
|
145
|
+
homepage: http://krainboltgreene.github.io/architecture.gem
|
146
146
|
licenses:
|
147
147
|
- MIT
|
148
148
|
metadata: {}
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
164
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.4.
|
165
|
+
rubygems_version: 2.4.6
|
166
166
|
signing_key:
|
167
167
|
specification_version: 4
|
168
168
|
summary: A DSL and object space for handling scaffolding
|