Class: Architecture::Entity
- Inherits:
-
Object
- Object
- Architecture::Entity
- Defined in:
- lib/architecture/entity.rb
Constant Summary collapse
- DIRECTORY_MIMETYPE =
"application/x-directory"
- DEFAULT_ENGINE =
::File
Instance Method Summary collapse
- #content(engine: DEFAULT_ENGINE) ⇒ Object
- #copy(entity:, engine: DEFAULT_ENGINE) ⇒ Object
- #create(engine: DEFAULT_ENGINE) ⇒ Object
- #delete(engine: DEFAULT_ENGINE) ⇒ Object
- #directory?(engine: DEFAULT_ENGINE) ⇒ Boolean
- #file?(engine: DEFAULT_ENGINE) ⇒ Boolean
-
#initialize(id:, prefix:) ⇒ Entity
constructor
A new instance of Entity.
- #location(engine: DEFAULT_ENGINE) ⇒ Object
- #move(entity:, engine: DEFAULT_ENGINE) ⇒ Object
- #to_s ⇒ Object
- #write(text:, engine: DEFAULT_ENGINE) ⇒ Object
Constructor Details
#initialize(id:, prefix:) ⇒ Entity
Returns a new instance of Entity.
6 7 8 9 10 |
# File 'lib/architecture/entity.rb', line 6 def initialize(id:, prefix:) @id = id @prefix = prefix @path = ::File.join(@prefix, @id) end |
Instance Method Details
#content(engine: DEFAULT_ENGINE) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/architecture/entity.rb', line 20 def content(engine: DEFAULT_ENGINE) if file?(engine: engine) engine.read(location(engine: engine)) else "" end end |
#copy(entity:, engine: DEFAULT_ENGINE) ⇒ Object
32 33 34 |
# File 'lib/architecture/entity.rb', line 32 def copy(entity:, engine: DEFAULT_ENGINE) system("cp #{location(engine: engine)} #{entity.location(engine: engine)}") end |
#create(engine: DEFAULT_ENGINE) ⇒ Object
44 45 46 |
# File 'lib/architecture/entity.rb', line 44 def create(engine: DEFAULT_ENGINE) system("mkdir -p #{location(engine: engine)}") end |
#delete(engine: DEFAULT_ENGINE) ⇒ Object
40 41 42 |
# File 'lib/architecture/entity.rb', line 40 def delete(engine: DEFAULT_ENGINE) system("rm -rf #{location(engine: engine)}") end |
#directory?(engine: DEFAULT_ENGINE) ⇒ Boolean
52 53 54 |
# File 'lib/architecture/entity.rb', line 52 def directory?(engine: DEFAULT_ENGINE) type(engine: engine) == DIRECTORY_MIMETYPE end |
#file?(engine: DEFAULT_ENGINE) ⇒ Boolean
48 49 50 |
# File 'lib/architecture/entity.rb', line 48 def file?(engine: DEFAULT_ENGINE) !directory?(engine: engine) end |
#location(engine: DEFAULT_ENGINE) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/architecture/entity.rb', line 12 def location(engine: DEFAULT_ENGINE) if engine.respond_to?("expand_path") engine.(path) else path end end |
#move(entity:, engine: DEFAULT_ENGINE) ⇒ Object
36 37 38 |
# File 'lib/architecture/entity.rb', line 36 def move(entity:, engine: DEFAULT_ENGINE) system("mv #{location(engine: engine)} #{entity.location(engine: engine)}") end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/architecture/entity.rb', line 56 def to_s path end |
#write(text:, engine: DEFAULT_ENGINE) ⇒ Object
28 29 30 |
# File 'lib/architecture/entity.rb', line 28 def write(text:, engine: DEFAULT_ENGINE) engine.write(location(engine: engine), text) end |