class Architecture::Entity
Constants
- DEFAULT_ENGINE
- DIRECTORY_MIMETYPE
Public Class Methods
new(id:, prefix:)
click to toggle source
# File lib/architecture/entity.rb, line 6 def initialize(id:, prefix:) @id = id @prefix = prefix @path = ::File.join(@prefix, @id) end
Public Instance Methods
content(engine: DEFAULT_ENGINE)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/architecture/entity.rb, line 44 def create(engine: DEFAULT_ENGINE) system("mkdir -p #{location(engine: engine)}") end
delete(engine: DEFAULT_ENGINE)
click to toggle source
# File lib/architecture/entity.rb, line 40 def delete(engine: DEFAULT_ENGINE) system("rm -rf #{location(engine: engine)}") end
directory?(engine: DEFAULT_ENGINE)
click to toggle source
# File lib/architecture/entity.rb, line 52 def directory?(engine: DEFAULT_ENGINE) type(engine: engine) == DIRECTORY_MIMETYPE end
file?(engine: DEFAULT_ENGINE)
click to toggle source
# File lib/architecture/entity.rb, line 48 def file?(engine: DEFAULT_ENGINE) !directory?(engine: engine) end
location(engine: DEFAULT_ENGINE)
click to toggle source
# File lib/architecture/entity.rb, line 12 def location(engine: DEFAULT_ENGINE) if engine.respond_to?("expand_path") engine.expand_path(path) else path end end
move(entity:, engine: DEFAULT_ENGINE)
click to toggle source
# 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()
click to toggle source
# File lib/architecture/entity.rb, line 56 def to_s path end
write(text:, engine: DEFAULT_ENGINE)
click to toggle source
# File lib/architecture/entity.rb, line 28 def write(text:, engine: DEFAULT_ENGINE) engine.write(location(engine: engine), text) end
Private Instance Methods
path()
click to toggle source
# File lib/architecture/entity.rb, line 60 def path @path end
system(command)
click to toggle source
# File lib/architecture/entity.rb, line 68 def system(command) Kernel.system("#{command}", :out => "/dev/null").tap do |succeeded| raise "\n`#{command}` failed to work." unless succeeded end end
type(engine: DEFAULT_ENGINE)
click to toggle source
# File lib/architecture/entity.rb, line 64 def type(engine: DEFAULT_ENGINE) system("file --mime-type --brief #{location(engine: engine)}") end