architecture 5.1.2 → 5.2.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: f2579d12571fc9abcc07ee0f2f55e4532cb86290
4
- data.tar.gz: b4f7f62facfffadf4c699ac37b0a58b46b4d3163
3
+ metadata.gz: a13b0b16285c40a8e6fb806cf4082d6ea08d133b
4
+ data.tar.gz: 72f0c6f723ec8da993edb4441a455e1f62897e20
5
5
  SHA512:
6
- metadata.gz: 3485d2600735bad99951178114b5a7bbaafdbef28e85c015eb2fead5cb1b202adb1921dc314d8f5057ff8f4e583b8492d075a68f6bad6e55389740d111df62f1
7
- data.tar.gz: f11b461d512e03f6afa209e5a994009aedd9c7521f269ce53f8276cf005619ddab708ed5b56cd970154475f956511ec61073285f650fac6799a4e8daecbd33d5
6
+ metadata.gz: 4236e2fd2df8210845951609e8a08a4c86bf99c43a63a2676e5f6d57ea131b39e0c17066497304f3f4a6aa4d803d8afb99345db8b71b01aa868ab35f85d8f95b
7
+ data.tar.gz: b685ed7eeec274978d3f419e75a9f4a4075d1dab5efe537df7b8857b25e4a608affb8e33dc1a9f5d8e946737bdd7392991e421247fdfe3e71432b8d0e76b57e2
@@ -1,55 +1,62 @@
1
1
  module Architecture
2
2
  class Entity
3
+ DIRECTORY_MIMETYPE = "application/x-directory"
4
+ DEFAULT_ENGINE = ::File
5
+
3
6
  def initialize(path:)
4
7
  @path = path
5
8
  end
6
9
 
7
- def location
8
- ::File.expand_path(location)
10
+ def location(engine: DEFAULT_ENGINE)
11
+ if engine.respond_to?("expand_path")
12
+ engine.expand_path(path)
13
+ else
14
+ path
15
+ end
9
16
  end
10
17
 
11
- def content
12
- if file?
13
- ::File.read(location)
18
+ def content(engine: DEFAULT_ENGINE)
19
+ if file?(engine: engine)
20
+ engine.read(location(engine: engine))
14
21
  else
15
22
  ""
16
23
  end
17
24
  end
18
25
 
19
- def write(text:)
20
- ::File.write(location, text)
26
+ def write(text:, engine: DEFAULT_ENGINE)
27
+ engine.write(location(engine: engine), text)
21
28
  end
22
29
 
23
- def copy(entity:)
24
- system("cp #{location} #{entity.location}")
30
+ def copy(entity:, engine: DEFAULT_ENGINE)
31
+ system("cp #{location(engine: engine)} #{entity.location(engine: engine)}")
25
32
  end
26
33
 
27
- def move(entity:)
28
- system("mv #{location} #{entity.location}")
34
+ def move(entity:, engine: DEFAULT_ENGINE)
35
+ system("mv #{location(engine: engine)} #{entity.location(engine: engine)}")
29
36
  end
30
37
 
31
- def delete
32
- system("rm -rf #{location}")
38
+ def delete(engine: DEFAULT_ENGINE)
39
+ system("rm -rf #{location(engine: engine)}")
33
40
  end
34
41
 
35
- def create
36
- system("mkdir -p #{location}")
42
+ def create(engine: DEFAULT_ENGINE)
43
+ system("mkdir -p #{location(engine: engine)}")
37
44
  end
38
45
 
39
- private def path
40
- @path
46
+ def file?(engine: DEFAULT_ENGINE)
47
+ !directory?(engine: engine)
41
48
  end
42
49
 
43
- def file?
44
- !directory?
50
+ def directory?(engine: DEFAULT_ENGINE)
51
+ type(engine: engine) == DIRECTORY_MIMETYPE
45
52
  end
46
53
 
47
- def directory?
48
- type == "application/x-directory"
54
+ private def path
55
+ @path
49
56
  end
50
57
 
51
- private def type
52
- system("file --mime-type --brief #{location}")
58
+ private def type(engine: DEFAULT_ENGINE)
59
+ system("file --mime-type --brief #{location(engine: engine)}")
53
60
  end
54
61
 
55
62
  private def system(command)
@@ -1,3 +1,3 @@
1
1
  module Architecture
2
- VERSION = "5.1.2"
2
+ VERSION = "5.2.0"
3
3
  end
@@ -0,0 +1,160 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Architecture::Entity do
4
+ let("path") do
5
+ "foo/bar/baz"
6
+ end
7
+
8
+ let("entity") do
9
+ described_class.new(path: path)
10
+ end
11
+
12
+ let("engine") do
13
+ double(File)
14
+ end
15
+
16
+ before("each") do
17
+ allow(entity).to receive("system")
18
+ end
19
+
20
+ describe "#directory?" do
21
+ let("directory?") do
22
+ entity.directory?
23
+ end
24
+
25
+ context "when path points to a directory" do
26
+ it "returns true" do
27
+ allow(entity).to receive("type").and_return("application/x-directory")
28
+ expect(directory?).to be(true)
29
+ end
30
+ end
31
+
32
+ context "when path points to a file" do
33
+ it "returns false" do
34
+ allow(entity).to receive("type").and_return("application/x-file")
35
+ expect(directory?).to be(false)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#file?" do
41
+ let("file?") do
42
+ entity.file?
43
+ end
44
+
45
+ context "when path points to a file" do
46
+ it "returns true" do
47
+ allow(entity).to receive("type").and_return("application/x-file")
48
+ expect(file?).to be(true)
49
+ end
50
+ end
51
+
52
+ context "when path points to a directory" do
53
+ it "returns false" do
54
+ allow(entity).to receive("type").and_return("application/x-directory")
55
+ expect(file?).to be(false)
56
+ end
57
+ end
58
+ end
59
+
60
+ describe "#create" do
61
+ let("create") do
62
+ entity.create(engine: engine)
63
+ end
64
+
65
+ it "calls the system" do
66
+ allow(engine).to receive("expand_path").and_return(path)
67
+ expect(entity).to receive("system")
68
+ create
69
+ end
70
+ end
71
+
72
+ describe "#delete" do
73
+ let("delete") do
74
+ entity.delete
75
+ end
76
+
77
+ it "calls the system" do
78
+ allow(engine).to receive("expand_path").and_return(path)
79
+ expect(entity).to receive("system")
80
+ delete
81
+ end
82
+ end
83
+
84
+ describe "#move" do
85
+ let("move") do
86
+ entity.move(entity: entity)
87
+ end
88
+
89
+ it "calls the system" do
90
+ allow(engine).to receive("expand_path").and_return(path)
91
+ expect(entity).to receive("system")
92
+ move
93
+ end
94
+ end
95
+
96
+ describe "#copy" do
97
+ let("copy") do
98
+ entity.copy(entity: entity)
99
+ end
100
+
101
+ it "calls the system" do
102
+ allow(engine).to receive("expand_path").and_return(path)
103
+ expect(entity).to receive("system")
104
+ copy
105
+ end
106
+ end
107
+
108
+ describe "#write" do
109
+ let("write") do
110
+ entity.write(text: "foo", engine: engine)
111
+ end
112
+
113
+ it "writes to the engine" do
114
+ allow(engine).to receive("expand_path").and_return(path)
115
+ expect(engine).to receive("write")
116
+ write
117
+ end
118
+ end
119
+
120
+ describe "#content" do
121
+ let("content") do
122
+ entity.content(engine: engine)
123
+ end
124
+
125
+ context "with a path that points to a file" do
126
+ it "reads from the engine" do
127
+ allow(entity).to receive("type").and_return("application/x-file")
128
+ allow(engine).to receive("expand_path").and_return(path)
129
+ expect(engine).to receive("read")
130
+ content
131
+ end
132
+ end
133
+
134
+ context "with a path that points to a directory" do
135
+ it "returns a empty string" do
136
+ allow(entity).to receive("type").and_return("application/x-directory")
137
+ expect(content).to eq("")
138
+ end
139
+ end
140
+ end
141
+
142
+ describe "#location" do
143
+ let("location") do
144
+ entity.location(engine: engine)
145
+ end
146
+
147
+ context "if engine responds to expand_path" do
148
+ it "calls expand_path on the engine" do
149
+ expect(engine).to receive("expand_path")
150
+ location
151
+ end
152
+ end
153
+
154
+ context "if engine doesn't respond to expand_path" do
155
+ it "returns the path" do
156
+ expect(location).to eq(path)
157
+ end
158
+ end
159
+ end
160
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: architecture
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.2
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurtis Rainbolt-Greene
@@ -134,6 +134,7 @@ files:
134
134
  - spec/lib/architecture/copy_spec.rb
135
135
  - spec/lib/architecture/create_spec.rb
136
136
  - spec/lib/architecture/delete_spec.rb
137
+ - spec/lib/architecture/entity_spec.rb
137
138
  - spec/lib/architecture/move_spec.rb
138
139
  - spec/lib/architecture/overwrite_spec.rb
139
140
  - spec/lib/architecture/prepend_spec.rb
@@ -170,6 +171,7 @@ test_files:
170
171
  - spec/lib/architecture/copy_spec.rb
171
172
  - spec/lib/architecture/create_spec.rb
172
173
  - spec/lib/architecture/delete_spec.rb
174
+ - spec/lib/architecture/entity_spec.rb
173
175
  - spec/lib/architecture/move_spec.rb
174
176
  - spec/lib/architecture/overwrite_spec.rb
175
177
  - spec/lib/architecture/prepend_spec.rb