Class: Architecture::Entity
- Inherits:
-
Object
- Object
- Architecture::Entity
- Defined in:
- lib/architecture/entity.rb
Instance Method Summary collapse
- #content ⇒ Object
- #copy(entity:) ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
- #directory? ⇒ Boolean
- #file? ⇒ Boolean
-
#initialize(path:) ⇒ Entity
constructor
A new instance of Entity.
- #location ⇒ Object
- #move(entity:) ⇒ Object
- #write(text:) ⇒ Object
Constructor Details
#initialize(path:) ⇒ Entity
Returns a new instance of Entity.
3 4 5 |
# File 'lib/architecture/entity.rb', line 3 def initialize(path:) @path end |
Instance Method Details
#content ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/architecture/entity.rb', line 11 def content if file? ::File.read(location) else "" end end |
#copy(entity:) ⇒ Object
23 24 25 |
# File 'lib/architecture/entity.rb', line 23 def copy(entity:) system("cp #{location} #{entity.location}") end |
#create ⇒ Object
35 36 37 |
# File 'lib/architecture/entity.rb', line 35 def create system("mkdir -p #{location}") end |
#delete ⇒ Object
31 32 33 |
# File 'lib/architecture/entity.rb', line 31 def delete system("rm -rf #{location}") end |
#directory? ⇒ Boolean
47 48 49 |
# File 'lib/architecture/entity.rb', line 47 def directory? type == "application/x-directory" end |
#file? ⇒ Boolean
43 44 45 |
# File 'lib/architecture/entity.rb', line 43 def file? !directory? end |
#location ⇒ Object
7 8 9 |
# File 'lib/architecture/entity.rb', line 7 def location ::File.(@location) end |
#move(entity:) ⇒ Object
27 28 29 |
# File 'lib/architecture/entity.rb', line 27 def move(entity:) system("mv #{location} #{entity.location}") end |
#write(text:) ⇒ Object
19 20 21 |
# File 'lib/architecture/entity.rb', line 19 def write(text:) ::File.write(location, text) end |