Class: Milkode::MilkodeYaml
- Inherits:
-
Object
- Object
- Milkode::MilkodeYaml
- Defined in:
- lib/milkode/cdstk/milkode_yaml.rb
Constant Summary collapse
- MILKODE_YAML_VERSION =
'0.2'
- EMPTY_YAML =
<<EOF --- version: '#{MILKODE_YAML_VERSION}' contents: [] EOF
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
Instance Method Summary collapse
-
#add(package) ⇒ Object
パッケージを追加.
- #dump ⇒ Object
-
#find_dir(directory) ⇒ Object
ディレクトリ名が同じパッケージを検索.
-
#find_name(name) ⇒ Object
名前が同じパッケージを検索.
- #global_gitignore ⇒ Object
-
#initialize(str = nil) ⇒ MilkodeYaml
constructor
A new instance of MilkodeYaml.
-
#match_all(keyword) ⇒ Object
指定キーワードにマッチする全てのパッケージを返す.
-
#migrate ⇒ Object
マイグレーション.
-
#package_root(dir) ⇒ Object
指定ディレクトリの所属するパッケージのルートディレクトリを得る。 見つからない場合はnilを返す。.
-
#remove(package) ⇒ Object
パッケージを削除.
-
#remove_all ⇒ Object
全てのパッケージを削除.
- #set_global_gitignore(filename) ⇒ Object
-
#update(package) ⇒ Object
同名パッケージの内容を置き換え.
- #version ⇒ Object
Constructor Details
#initialize(str = nil) ⇒ MilkodeYaml
Returns a new instance of MilkodeYaml.
24 25 26 27 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 24 def initialize(str = nil) @data = YAML.load(str || EMPTY_YAML) @contents = parse_contents end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
22 23 24 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 22 def contents @contents end |
Instance Method Details
#add(package) ⇒ Object
パッケージを追加
38 39 40 41 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 38 def add(package) @contents.push package update_contents end |
#dump ⇒ Object
29 30 31 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 29 def dump YAML.dump(@data) end |
#find_dir(directory) ⇒ Object
ディレクトリ名が同じパッケージを検索
74 75 76 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 74 def find_dir(directory) @contents.find {|v| v.directory == directory} end |
#find_name(name) ⇒ Object
名前が同じパッケージを検索
64 65 66 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 64 def find_name(name) @contents.find {|v| v.same_name?(name)} end |
#global_gitignore ⇒ Object
106 107 108 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 106 def global_gitignore @data['global_gitignore'] end |
#match_all(keyword) ⇒ Object
指定キーワードにマッチする全てのパッケージを返す
69 70 71 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 69 def match_all(keyword) @contents.find_all {|p| p.name.include? keyword } end |
#migrate ⇒ Object
マイグレーション
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 91 def migrate if (version != MILKODE_YAML_VERSION) # バージョン番号 @data['version'] = MILKODE_YAML_VERSION # パッケージ contents.each{|v| v.migrate} # migrateが起きた true else false end end |
#package_root(dir) ⇒ Object
指定ディレクトリの所属するパッケージのルートディレクトリを得る。 見つからない場合はnilを返す。
80 81 82 83 84 85 86 87 88 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 80 def package_root(dir) nd = Util.normalize_filename(dir) @contents.find_all {|v| nd =~ /^#{Regexp.escape(v.directory)}(:?\/|\Z)/ }.max_by {|v| v.directory.length } end |
#remove(package) ⇒ Object
パッケージを削除
52 53 54 55 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 52 def remove(package) @contents.delete(package) update_contents end |
#remove_all ⇒ Object
全てのパッケージを削除
58 59 60 61 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 58 def remove_all @contents = [] update_contents end |
#set_global_gitignore(filename) ⇒ Object
110 111 112 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 110 def set_global_gitignore(filename) @data['global_gitignore'] = filename end |
#update(package) ⇒ Object
同名パッケージの内容を置き換え
44 45 46 47 48 49 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 44 def update(package) i = @contents.find_index {|v| v.same_name?(package.name) } raise unless i @contents[i] = package update_contents end |
#version ⇒ Object
33 34 35 |
# File 'lib/milkode/cdstk/milkode_yaml.rb', line 33 def version @data['version'] end |