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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ce3b7713d38479cedf2733145b9cb8b8566ceab
4
- data.tar.gz: 30282201b865ca1894be94b9cfc6830c6054edce
3
+ metadata.gz: d0018a5e560bdab42d3233c1787f1f7d5deedb46
4
+ data.tar.gz: 110444d0a95fc6474f87213028fa3b1d3756c569
5
5
  SHA512:
6
- metadata.gz: 3e6a9f662e52e99478fab258d94ad63a7f66b95627926a0adc857dce07b48dd2f0244a0149476872fe38a78d9dbb19ea5dbb6a59c5af8fb5fa0b7f4978ea74f1
7
- data.tar.gz: 409299288b04bc99d4d99057aab1f81638f5b2a5af96afc3c7dace0aa4f154e866d6eacc2f9b3a096ce2f38844fac69bdf7c2c8ab9a3e63c46997c838cd6fed2
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
@@ -3,8 +3,8 @@ module Architecture
3
3
  include Entityable
4
4
  include Contentable
5
5
 
6
- def initialize(source:, content: "", context: {})
7
- @entity = Entity.new(path: source)
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 ArgumentError, "Source wasn't a file"
16
+ raise(ArgumentError, "Source wasn't a file")
17
17
  end
18
18
  end
19
19
 
@@ -3,9 +3,9 @@ module Architecture
3
3
  include Replicatable
4
4
  include Contentable
5
5
 
6
- def initialize(source:, destination:, context: {})
7
- @origin = Entity.new(path: source)
8
- @clone = Entity.new(path: destination)
6
+ def initialize(source:, destination:, context: Architecture::EMPTY_CONTEXT)
7
+ @origin = source
8
+ @clone = destination
9
9
  @context = context
10
10
  end
11
11
 
@@ -3,8 +3,8 @@ module Architecture
3
3
  include Entityable
4
4
  include Contentable
5
5
 
6
- def initialize(source:, content:, context:)
7
- @entity = Entity.new(path: source)
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
@@ -3,7 +3,7 @@ module Architecture
3
3
  include Entityable
4
4
 
5
5
  def initialize(source:)
6
- @entity = Entity.new(path: source)
6
+ @entity = source
7
7
  end
8
8
 
9
9
  def call
@@ -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
- ::Architecture::Copy.new(source: source(directory || file), destination: destination(as || directory || file), context: context).call
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
- ::Architecture::Move.new(source: directory || file, destination: as).call
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(directory: nil, file: nil, content: nil, context: {})
21
- ::Architecture::Create.new(source: directory || file, content: content, context: context).call
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
- ::Architecture::Delete.new(source: directory || file).call
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: nil, search:, content:)
29
- ::Architecture::Replace.new(source: file, search: search, content: content).call
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: nil, content:, context: {})
33
- ::Architecture::Prepend.new(source: file, content: content, context: context).call
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: nil, content:, context: {})
37
- ::Architecture::Append.new(source: file, content: content, context: context).call
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: nil, content:, context: {})
41
- ::Architecture::Overwrite.new(source: file, content: content, context: context).call
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 within(source: nil, destination: nil, &block)
45
- ::Architecture::DSL.new(source: source(source), destination: destination(destination), &block)
115
+ private def source
116
+ @source
46
117
  end
47
118
 
48
- def source(path)
49
- join(@source, path)
119
+ private def destination
120
+ @destination
50
121
  end
51
122
 
52
- def destination(path)
53
- join(@destination, path)
123
+ private def join(*ids)
124
+ File.join(*ids)
54
125
  end
55
126
 
56
- private def join(*paths)
57
- ::File.join(*paths)
127
+ private def indentention
128
+ "\t" * @level
58
129
  end
59
130
  end
60
131
  end
@@ -3,8 +3,10 @@ module Architecture
3
3
  DIRECTORY_MIMETYPE = "application/x-directory"
4
4
  DEFAULT_ENGINE = ::File
5
5
 
6
- def initialize(path:)
7
- @path = path
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)
@@ -3,8 +3,8 @@ module Architecture
3
3
  include Replicatable
4
4
 
5
5
  def initialize(source:, destination:)
6
- @origin = Entity.new(path: source)
7
- @clone = Entity.new(path: destination)
6
+ @origin = source
7
+ @clone = destination
8
8
  end
9
9
 
10
10
  def call
@@ -3,8 +3,8 @@ module Architecture
3
3
  include Entityable
4
4
  include Contentable
5
5
 
6
- def initialize(source:, content: "", context: {})
7
- @entity = Entity.new(path: source)
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 ArgumentError, "Source wasn't a file"
16
+ raise(ArgumentError, "Source wasn't a file")
17
17
  end
18
18
  end
19
19
  end
@@ -3,8 +3,8 @@ module Architecture
3
3
  include Entityable
4
4
  include Contentable
5
5
 
6
- def initialize(source:, content: "", context: {})
7
- @entity = Entity.new(path: source)
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 ArgumentError, "Source wasn't a file"
16
+ raise(ArgumentError, "Source wasn't a file")
17
17
  end
18
18
  end
19
19
 
@@ -2,8 +2,8 @@ module Architecture
2
2
  class Replace
3
3
  include Entityable
4
4
 
5
- def initialize(source:, search: "", content: "")
6
- @entity = Entity.new(path: source)
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 ArgumentError, "Source wasn't a file"
15
+ raise(ArgumentError, "Source wasn't a file")
16
16
  end
17
17
  end
18
18
 
@@ -1,3 +1,3 @@
1
1
  module Architecture
2
- VERSION = "5.2.1"
2
+ VERSION = "6.0.0"
3
3
  end
@@ -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(path: path)
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
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Architecture::VERSION do
4
- it "should be a string" do
3
+ RSpec.describe Architecture::VERSION do
4
+ it "is a string" do
5
5
  expect(Architecture::VERSION).to be_kind_of(String)
6
6
  end
7
7
  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: 5.2.1
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-01-19 00:00:00.000000000 Z
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.3
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