Class: Milkode::YamlFileWrapper

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

Defined Under Namespace

Classes: YAMLAlreadyExist, YAMLNotExist

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml_file, data) ⇒ YamlFileWrapper

Returns a new instance of YamlFileWrapper.



45
46
47
48
49
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 45

def initialize(yaml_file, data)
  @yaml_file = yaml_file
  @data = data
  migrate
end

Class Method Details

.create(path = ".") ⇒ Object

Raises:



21
22
23
24
25
26
27
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 21

def self.create(path = ".")
  yf = yaml_file(path)
  raise YAMLAlreadyExist.new if FileTest.exist? yf
  obj = YamlFileWrapper.new(yf, MilkodeYaml.new)
  obj.save
  return obj
end

.load(path = ".") ⇒ Object

Raises:



29
30
31
32
33
34
35
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 29

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

.load_if(path = ".") ⇒ Object



37
38
39
40
41
42
43
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 37

def self.load_if(path = ".")
  begin
    load(path)
  rescue YAMLNotExist
    nil
  end
end

.yaml_file(path) ⇒ Object



17
18
19
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 17

def self.yaml_file(path)
  Dbdir.yaml_path(path)
end

Instance Method Details

#add(package) ⇒ Object



67
68
69
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 67

def add(package)
  @data.add package
end

#contentsObject



51
52
53
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 51

def contents
  @data.contents
end

#find_dir(dir) ⇒ Object



63
64
65
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 63

def find_dir(dir)
  @data.find_dir(dir)
end

#find_name(name) ⇒ Object



55
56
57
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 55

def find_name(name)
  @data.find_name(name)
end

#global_gitignoreObject



102
103
104
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 102

def global_gitignore
  @data.global_gitignore
end

#match_all(keyword) ⇒ Object



59
60
61
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 59

def match_all(keyword)
  @data.match_all(keyword)
end

#migrateObject



95
96
97
98
99
100
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 95

def migrate
  if (@data.migrate)
    puts "milkode.yaml is old '#{version}'. Convert to '#{MilkodeYaml::MILKODE_YAML_VERSION}'."
    save
  end
end

#package_root(dir) ⇒ Object



83
84
85
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 83

def package_root(dir)
  @data.package_root(dir)
end

#remove(package) ⇒ Object



75
76
77
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 75

def remove(package)
  @data.remove package
end

#remove_allObject



79
80
81
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 79

def remove_all
  @data.remove_all
end

#saveObject



87
88
89
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 87

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

#set_global_gitignore(filename) ⇒ Object



106
107
108
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 106

def set_global_gitignore(filename)
  @data.set_global_gitignore(filename)
end

#update(package) ⇒ Object



71
72
73
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 71

def update(package)
  @data.update package
end

#versionObject



91
92
93
# File 'lib/milkode/cdstk/yaml_file_wrapper.rb', line 91

def version
  @data.version
end