Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[cdstk] rebuild --all すると fav 設定が消えてしまう問題を修正

  • Loading branch information...
commit 6efc5e3d1fb55eeb128d047bb4fd5b3ba5246d54 1 parent 34fd682
@ongaeshi authored
View
19 lib/milkode/cdstk/cdstk.rb
@@ -400,13 +400,30 @@ def fav(args, options)
if (args.empty?)
@out.puts @grndb.packages.favs.map{|r| r.name}
else
+ is_dirty = false
+
args.each do |v|
+ # database
time = options[:delete] ? Time.at(0) : Time.now
- if @grndb.packages.touch_if(v, :favtime, time).nil?
+ if @grndb.packages.touch_if(v, :favtime, time)
+ # milkode_yaml
+ package = @yaml.find_name(v)
+ dst = package.options
+ unless options[:delete]
+ dst[:fav] = true
+ else
+ dst.delete(:fav)
+ end
+ package.set_options(dst)
+ @yaml.update(package)
+ is_dirty = true
+ else
@out.puts "Not found package '#{v}'"
end
end
+
+ @yaml.save if is_dirty
end
end
View
2  lib/milkode/database/groonga_database.rb
@@ -51,7 +51,7 @@ def open_file(filename)
# あらかじめ GroongaDatabase#open しておく必要がある
def yaml_sync(yaml_contents)
yaml_contents.each do |yp|
- packages.add(yp.name, yp.directory) if packages[yp.name].nil?
+ packages.add(yp.name, yp.directory, yp.options) if packages[yp.name].nil?
end
end
View
5 lib/milkode/database/package_table.rb
@@ -30,11 +30,12 @@ def size
@table.size
end
- def add(name, directory)
+ def add(name, directory, options)
@table.add(name,
:name => name,
:directory => directory,
- :addtime => Time.now)
+ :addtime => Time.now,
+ :favtime => options[:fav] ? Time.now : Time.at(0))
end
def remove(name)
View
31 test/test_package_table.rb
@@ -22,6 +22,7 @@ def test_database
t_touch
t_favs
t_touch_if
+ t_add_fav
ensure
t_cleanup
end
@@ -54,7 +55,7 @@ def t_packages
packages = @obj.packages
assert_equal 0, packages.size
- packages.add("milkode", "")
+ packages.add("milkode", "", {})
assert_equal 1, packages.size
r = packages["milkode"]
@@ -70,10 +71,10 @@ def t_packages
def t_packages_viewtime
packages = @obj.packages
- packages.add("add", "")
- packages.add("update", "")
- packages.add("view", "")
- packages.add("favorite", "")
+ packages.add("add", "", {})
+ packages.add("update", "", {})
+ packages.add("view", "", {})
+ packages.add("favorite", "", {})
assert_equal 4, packages.size
packages.each do |r|
@@ -104,17 +105,17 @@ def t_sort
t = Time.now
- r = packages.add("r1", "")
+ r = packages.add("r1", "", {})
r.updatetime = t + 1
r.viewtime = t + 2
r.favtime = t + 3
- r = packages.add("r2", "")
+ r = packages.add("r2", "", {})
r.updatetime = t + 3
r.viewtime = t + 1
# r.favtime
- r = packages.add("r3", "")
+ r = packages.add("r3", "", {})
r.updatetime = t + 2
r.viewtime = t + 3
r.favtime = t + 2
@@ -163,7 +164,7 @@ def t_yaml_sync
end
def t_touch
- r = @packages.add("r1", "")
+ r = @packages.add("r1", "", {})
t = Time.now
assert_not_equal t, r.updatetime
@@ -183,9 +184,9 @@ def t_touch
end
def t_favs
- @packages.add("r1", "")
- @packages.add("r2", "")
- @packages.add("r3", "")
+ @packages.add("r1", "", {})
+ @packages.add("r2", "", {})
+ @packages.add("r3", "", {})
assert_equal [], @packages.favs.map{|r| r.name}
@@ -204,5 +205,11 @@ def t_touch_if
assert_raise(NoMethodError) { @packages.touch("not_found", :favtime) }
assert_equal nil, @packages.touch_if("not_found", :favtime)
end
+
+ def t_add_fav
+ r = @packages.add("r1", "", {:fav => true})
+ assert r.favtime.to_i > 0
+ @packages.remove_all
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.