Class: Garaj::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/garaj/project.rb

Constant Summary collapse

IGNORED_ENTRIES =
%w{. .. .DS_Store .git}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ Project

Initializes a new Garaj::Project object



9
10
11
# File 'lib/garaj/project.rb', line 9

def initialize(root_path)
  @root_path = root_path.chomp('/')
end

Instance Attribute Details

#root_pathObject

Returns the value of attribute root_path.



6
7
8
# File 'lib/garaj/project.rb', line 6

def root_path
  @root_path
end

Instance Method Details

#dirs_at(relative_path) ⇒ Object

Returns a list of the dirs at the given path



55
56
57
58
59
60
61
62
63
# File 'lib/garaj/project.rb', line 55

def dirs_at(relative_path)
  dirs = []
  Dir.foreach(full_path_to(relative_path)) do |entry|
    if path_is_dir?("#{relative_path}/#{entry}") and not_ignored?(entry)
      dirs << entry 
    end
  end
  dirs
end

#file_content_at(relative_path) ⇒ Object

Returns the contents of the file at the given path



39
40
41
# File 'lib/garaj/project.rb', line 39

def file_content_at(relative_path)
  File.read(full_path_to(relative_path))
end

#file_name_at(relative_path) ⇒ Object

Returns the name of the file



34
35
36
# File 'lib/garaj/project.rb', line 34

def file_name_at(relative_path)
  relative_path.split('/').last
end

#files_at(relative_path) ⇒ Object

Returns a list of the files at the given path



44
45
46
47
48
49
50
51
52
# File 'lib/garaj/project.rb', line 44

def files_at(relative_path)
  files = []
  Dir.foreach(full_path_to(relative_path)) do |entry|
    if !path_is_dir?("#{relative_path}/#{entry}") and not_ignored?(entry)
      files << entry 
    end
  end
  files
end

#full_path_to(relative_path) ⇒ Object

Returns full path of the given relative path



19
20
21
# File 'lib/garaj/project.rb', line 19

def full_path_to(relative_path)
  "#{@root_path}/#{relative_path.chomp('/')}"
end

#nameObject

Returns name of the project



14
15
16
# File 'lib/garaj/project.rb', line 14

def name
  @root_path.split('/').last
end

#not_ignored?(entry) ⇒ Boolean

Checks if the given file is ignored

Returns:

  • (Boolean)


24
25
26
# File 'lib/garaj/project.rb', line 24

def not_ignored?(entry)
  true unless IGNORED_ENTRIES.include?(entry)
end

#path_is_dir?(relative_path) ⇒ Boolean

Checks if the given path is a directory

Returns:

  • (Boolean)


29
30
31
# File 'lib/garaj/project.rb', line 29

def path_is_dir?(relative_path)
  true if File.directory?(full_path_to(relative_path))
end