Permalink
Browse files

CliGrepをYamlFileWrapperに置き換え。

CdstkYamlを削除完了。
  • Loading branch information...
ongaeshi committed Feb 29, 2012
1 parent 4ce53b8 commit 615e3442a9d096873842a6ced4374103f8640ec7
Showing with 13 additions and 392 deletions.
  1. +3 −3 lib/milkode/cdstk/cdstk.rb
  2. +0 −177 lib/milkode/cdstk/cdstk_yaml.rb
  3. +10 −9 lib/milkode/grep/cli_grep.rb
  4. +0 −203 test/test_cdstk_yaml.rb
@@ -6,7 +6,6 @@
require 'groonga'
require 'fileutils'
require 'pathname'
-require 'milkode/cdstk/cdstk_yaml'
require 'milkode/common/grenfiletest'
require 'milkode/common/util'
require 'milkode/common/dir'
@@ -20,7 +19,8 @@
require 'milkode/cdweb/lib/database'
require 'open-uri'
-require 'milkode/cdstk/cdstk_command' # @todo 削除予定
+require 'milkode/cdstk/cdstk_command'
+
require 'milkode/cdstk/yaml_file_wrapper'
require 'milkode/cdstk/package'
@@ -515,7 +515,7 @@ def custom_db?
end
def yaml_file
- CdstkYaml.yaml_file @db_dir
+ YamlFileWrapper.yaml_file @db_dir
end
def update_dir_in(dir)
@@ -1,177 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# @file
-# @brief
-# @author ongaeshi
-# @date 2011/02/20
-
-require 'yaml'
-require 'pathname'
-require 'milkode/common/dbdir'
-require 'milkode/common/util.rb'
-
-module Milkode
- class CdstkYaml
- MILKODE_YAML_VERSION = '0.2'
-
- class YAMLAlreadyExist < RuntimeError
- end
-
- class YAMLNotExist < RuntimeError
- end
-
- def self.create(path = ".")
- yf = yaml_file(path)
- raise YAMLAlreadyExist.new if FileTest.exist? yf
- obj = CdstkYaml.new(yf, {'contents' => [], 'version' => MILKODE_YAML_VERSION})
- obj.save
- return obj
- end
-
- 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
-
- def initialize(yaml_file, data)
- @yaml_file = yaml_file
- @data = data
- normalize
- migrate
- end
-
- def normalize
- if (Util::platform_win?)
- contents.each do |v|
- v['directory'] = Util::normalize_filename v['directory']
- end
- end
- end
-
- def add(dirs)
- contents.concat(dirs.map{|v|{'directory' => v, 'ignore' => []}})
- contents.uniq!
- end
-
- def remove(query)
- r = query.select_any?(contents)
- r.each {|v| contents.delete v}
- end
-
- def remove_dir(dir)
- contents.delete_if do |v|
- dir == v['directory']
- end
- end
-
- def save
- open(@yaml_file, "w") { |f| YAML.dump(@data, f) }
- end
-
- def contents
- @data['contents']
- end
-
- def find_content(dir)
- contents.find do |v|
- dir == v['directory']
- end
- end
-
- def package_num
- @data['contents'].size
- end
-
- def directorys
- contents.map{|v|v['directory']}
- end
-
- def version
- @data['version']
- end
-
- def list(query = nil)
- query ? query.select_all?(contents) : contents
- end
-
- def exist?(shortname)
- @data['contents'].find {|v| File.basename(v['directory']) == shortname }
- end
-
- def cant_add_directory?(dir)
- @data['contents'].find {|v|
- v['directory'] != File.expand_path(dir) &&
- File.basename(v['directory']) == File.basename(dir)
- }
- end
-
- def cleanup
- contents.delete_if do |v|
- if (!File.exist? v['directory'])
- yield v if block_given?
- true
- else
- false
- end
- end
- end
-
- def package_root(dir)
- nd = Util::normalize_filename dir
- @data['contents'].find do |v|
- v if nd =~ /^#{v['directory']}/
- end
- end
-
- def package_root_dir(dir)
- package = package_root(dir)
- (package) ? package['directory'] : nil
- end
-
- def self.yaml_file(path)
- Dbdir.yaml_path(path)
- end
-
- class Query
- def initialize(keywords)
- @keywords = keywords
- end
-
- def select_any?(contents)
- contents.find_all do |v|
- @keywords.any? {|s| File.basename(v['directory']).include? s }
- end
- end
-
- def select_all?(contents)
- contents.find_all do |v|
- @keywords.all? {|s| File.basename(v['directory']).include? s }
- end
- end
- end
-
- def migrate
- if (version != MILKODE_YAML_VERSION)
- puts "milkode.yaml is old '#{version}'. Convert to '#{MILKODE_YAML_VERSION}'."
-
- # バージョン更新
- @data['version'] = MILKODE_YAML_VERSION
-
- # データ内容更新
- contents.each do |v|
- v['ignore'] = [] unless v['ignore']
- end
-
- # セーブ
- save
- end
- end
-
- def ignore(dir)
- find_content(dir)['ignore']
- end
- end
-end
@@ -3,8 +3,9 @@
require 'optparse'
require 'milkode/findgrep/findgrep'
require 'milkode/common/dbdir'
-require 'milkode/cdstk/cdstk_yaml'
require 'milkode/cdstk/cdstk'
+require 'milkode/cdstk/yaml_file_wrapper'
+require 'milkode/cdstk/package'
module Milkode
class CLI_Grep
@@ -142,28 +143,28 @@ def self.execute(stdout, arguments=[])
private
def self.setup_package(option, my_option, keyword)
- packages = yaml_load.list( CdstkYaml::Query.new([keyword]) ).map{|v| v['directory']}
- raise NotFoundPackage.new keyword if (packages.empty?)
- option.packages += packages
- my_option[:packages] += packages
+ dirs = yaml_load.contents.find_all {|p| p.name.include? keyword }.map{|p| p.directory}
+ raise NotFoundPackage.new keyword if (dirs.empty?)
+ option.packages += dirs
+ my_option[:packages] += dirs
end
def self.package_dir_in?(dir)
- yaml_load.package_root_dir(dir)
+ yaml_load.package_root(dir)
end
def self.package_root_dir(dir)
- package_root = yaml_load.package_root_dir(dir)
+ package_root = yaml_load.package_root(dir)
if (package_root)
- package_root
+ package_root.directory
else
raise NotFoundPackage.new dir
end
end
def self.yaml_load
- CdstkYaml.load(Dbdir.select_dbdir)
+ YamlFileWrapper.load(Dbdir.select_dbdir)
end
class ArgumentParser
Oops, something went wrong.

0 comments on commit 615e344

Please sign in to comment.