Class: RepoMate::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/repomate/category.rb

Overview

Class for the category layer of the directory structure

Class Method Summary collapse

Instance Method Summary collapse

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

.allObject

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

#createObject

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

#destroyObject

Deletes a categories directory



33
34
35
# File 'lib/repomate/category.rb', line 33

def destroy
  FileUtils.rm_r(directory) if exist?
end

#directoryObject

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

Returns:

  • (Boolean)


23
24
25
# File 'lib/repomate/category.rb', line 23

def exist?
  Dir.exist?(directory)
end

#nameObject

Returns the name of the category (eg. pool, dists)



13
14
15
# File 'lib/repomate/category.rb', line 13

def name
  @category
end