Class: Reflection::Directory::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/reflection/directory/base.rb

Direct Known Subclasses

Stash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_path) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/reflection/directory/base.rb', line 7

def initialize(new_path)
  self.path = new_path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/reflection/directory/base.rb', line 5

def path
  @path
end

Instance Method Details

#clean!Object



19
20
21
22
# File 'lib/reflection/directory/base.rb', line 19

def clean!
  Reflection.log.debug "Cleaning #{self.path}/.."
  %x(rm -r #{self.path}/*)
end

#copy_git_index_to(target_path) ⇒ Object



36
37
38
39
# File 'lib/reflection/directory/base.rb', line 36

def copy_git_index_to(target_path)
  Reflection.log.debug "Copying git-index '#{self.git_index}' to #{target_path}"
  %x(cp -R #{self.git_index} #{target_path})
end

#exists?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/reflection/directory/base.rb', line 15

def exists?
  File.exist?(self.path)
end

#get_git_index_from(target_path) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/reflection/directory/base.rb', line 41

def get_git_index_from(target_path)
  Reflection.log.debug "Getting git-index from #{target_path}"
  
  %x(rm -rf #{self.git_index}) if File.exists?(self.git_index)
  %x(mkdir -p #{self.path})
  %x(mv -f #{File.join(target_path, '/.git')} #{File.join(self.path, "/")})
end

#git_indexObject



32
33
34
# File 'lib/reflection/directory/base.rb', line 32

def git_index
  File.expand_path(File.join(self.path, '.git'))
end

#move_content_to(target_path) ⇒ Object



49
50
51
52
53
# File 'lib/reflection/directory/base.rb', line 49

def move_content_to(target_path)
  Reflection.log.debug "Moving content to '#{target_path}'.."
  %x(cp -R #{File.join(self.path, '/.')} #{target_path})
  %x(rm -rf #{self.path})
end

#nameObject



28
29
30
# File 'lib/reflection/directory/base.rb', line 28

def name
  self.path.split('/').last
end

#parentObject



24
25
26
# File 'lib/reflection/directory/base.rb', line 24

def parent
  Base.new(File.expand_path(self.path.split('/')[0..-2].join('/')))
end

#to_sObject



11
12
13
# File 'lib/reflection/directory/base.rb', line 11

def to_s
  self.path
end