Class: Architecture::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/architecture/entity.rb

Instance Method Summary collapse

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

#contentObject



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

#createObject



35
36
37
# File 'lib/architecture/entity.rb', line 35

def create
  system("mkdir -p #{location}")
end

#deleteObject



31
32
33
# File 'lib/architecture/entity.rb', line 31

def delete
  system("rm -rf #{location}")
end

#directory?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/architecture/entity.rb', line 47

def directory?
  type == "application/x-directory"
end

#file?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/architecture/entity.rb', line 43

def file?
  !directory?
end

#locationObject



7
8
9
# File 'lib/architecture/entity.rb', line 7

def location
  ::File.expand_path(@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