Class: CodeStock::CdstkYaml

Inherits:
Object
  • Object
show all
Defined in:
lib/cdstk/cdstk_yaml.rb

Defined Under Namespace

Classes: YAMLAlreadyExist, YAMLNotExist

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(path = ".") ⇒ Object

Raises:



19
20
21
22
23
24
25
# File 'lib/cdstk/cdstk_yaml.rb', line 19

def self.create(path = ".")
  yf = yaml_file(path)
  raise YAMLAlreadyExist.new if FileTest.exist? yf
  obj = CdstkYaml.new(yf, {'contents' => [], 'version' => 0.1})
  obj.save
  return obj
end

.load(path = ".") ⇒ Object

Raises:



27
28
29
30
31
32
33
# File 'lib/cdstk/cdstk_yaml.rb', line 27

def self.load(path = ".")
  yf = yaml_file(path)
  raise YAMLNotExist.new unless FileTest.exist? yf
  open(yf) do |f|
    return CdstkYaml.new(yf, YAML.load(f.read()))
  end
end

.yaml_file(path) ⇒ Object



64
65
66
# File 'lib/cdstk/cdstk_yaml.rb', line 64

def self.yaml_file(path)
  (Pathname.new(path) + 'grendb.yaml').to_s
end

Instance Method Details

#add(*dirs) ⇒ Object



35
36
37
38
# File 'lib/cdstk/cdstk_yaml.rb', line 35

def add(*dirs)
  contents.push(*dirs.map{|v|{"directory" => v}})
  contents.uniq!
end

#contentsObject



48
49
50
# File 'lib/cdstk/cdstk_yaml.rb', line 48

def contents
  @data['contents']
end

#directorysObject



52
53
54
# File 'lib/cdstk/cdstk_yaml.rb', line 52

def directorys
  contents.map{|v|v["directory"]}
end

#listObject



60
61
62
# File 'lib/cdstk/cdstk_yaml.rb', line 60

def list
  directorys
end

#remove(*dirs) ⇒ Object



40
41
42
# File 'lib/cdstk/cdstk_yaml.rb', line 40

def remove(*dirs)
  dirs.each {|f| contents.delete( {"directory" => f} ) }
end

#saveObject



44
45
46
# File 'lib/cdstk/cdstk_yaml.rb', line 44

def save
  open(@yaml_file, "w") { |f| YAML.dump(@data, f) }
end

#versionObject



56
57
58
# File 'lib/cdstk/cdstk_yaml.rb', line 56

def version
  @data['version']
end