Class: RepoMate::Category
- Inherits:
-
Object
- Object
- RepoMate::Category
- Defined in:
- lib/repomate/category.rb
Overview
Class for the category layer of the directory structure
Class Method Summary collapse
-
.all ⇒ Object
Returns all directories.
-
.dataset(category = nil) ⇒ Object
Returns a dataset including the name of the category and the fullpath.
Instance Method Summary collapse
-
#create ⇒ Object
Creates the directory strcuture of the category.
-
#destroy ⇒ Object
Deletes a categories directory.
-
#directory ⇒ Object
Returns the full path of the categories directory.
-
#exist? ⇒ Boolean
Checks if the category directory exists.
-
#initialize(category) ⇒ Category
constructor
Init.
-
#name ⇒ Object
Returns the name of the category (eg. pool, dists).
Constructor Details
#initialize(category) ⇒ Category
Init
8 9 10 |
# File 'lib/repomate/category.rb', line 8 def initialize(category) @category = category end |
Class Method Details
.all ⇒ Object
Returns all directories
53 54 55 56 |
# File 'lib/repomate/category.rb', line 53 def self.all dirs = Dir.glob(File.join(Cfg.rootdir, "*")) dirs.map{ |dir| File.basename(dir) unless dirs.include?(File.basename(dir)) } end |
.dataset(category = nil) ⇒ Object
Returns a dataset including the name of the category and the fullpath
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/repomate/category.rb', line 38 def self.dataset(category=nil) data = [] self.all.each do |entry| unless entry.nil? next unless entry.eql?(category) || category.eql?("all") data << { :category => entry, :fullpath => File.join(Cfg.rootdir, entry) } end end data end |
Instance Method Details
#create ⇒ Object
Creates the directory strcuture of the category
28 29 30 |
# File 'lib/repomate/category.rb', line 28 def create FileUtils.mkdir_p(directory) unless exist? end |
#destroy ⇒ Object
Deletes a categories directory
33 34 35 |
# File 'lib/repomate/category.rb', line 33 def destroy FileUtils.rm_r(directory) if exist? end |
#directory ⇒ Object
Returns the full path of the categories directory
18 19 20 |
# File 'lib/repomate/category.rb', line 18 def directory File.join(Cfg.rootdir, @category) end |
#exist? ⇒ Boolean
Checks if the category directory exists
23 24 25 |
# File 'lib/repomate/category.rb', line 23 def exist? Dir.exist?(directory) end |
#name ⇒ Object
Returns the name of the category (eg. pool, dists)
13 14 15 |
# File 'lib/repomate/category.rb', line 13 def name @category end |