kanamei-keystone 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'keystone'
3
+
4
+ include Keystone::Batch::Base
5
+
6
+ if ARGV[0] == nil
7
+ puts "set mail addr"
8
+ exit
9
+ end
10
+
11
+ # ERROR_MAIL_TOを設定しておけば自動でエラーメールが送信される
12
+ ERROR_MAIL_TO = ARGV[0]
13
+ # ●定数
14
+ # ERROR_MAIL_TO (エラーメール送信先) 設定しておけば自動でエラーメールを送信してくれる
15
+ # ERROR_MAIL_FROM (エラーメール送信元) 設定されてない場合はERROR_MAIL_TOを使用
16
+ # ERROR_MAIL_STMP_ADDR (エラーメール送信SMTPアドレス) 設定されてない場合は"127.0.0.1"
17
+ # ERROR_MAIL_STMP_PORT (エラーメール送信SMTPポート) 設定されてない場合は25
18
+
19
+ execute() do
20
+ info "batch process01"
21
+ raise 'error occur'
22
+ end
data/example/os.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'keystone'
3
+
4
+ puts Keystone::Os.get().dump
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'keystone'
3
+
4
+ st = %|test "test 02" 日本語 ニホンゴハンカク "にほ んご ですが なにか"|
5
+ st2 = Keystone::StringUtil.to_searchtext(st)
6
+
7
+ p Keystone::StringUtil.serach_string_to_array(st)
8
+ p Keystone::StringUtil.serach_string_to_array(st2)
data/lib/keystone/base.rb CHANGED
@@ -14,9 +14,9 @@ module Keystone
14
14
 
15
15
  def error(message)
16
16
  if message.is_a? Exception
17
- log(:ERROR," #{message.message}")
17
+ log(:ERROR,"#{message.message}")
18
18
  message.backtrace.each_with_index {|line, i|
19
- log(:ERROR," #{line})",false)
19
+ log(:ERROR,"#{line})",false)
20
20
  }
21
21
  else
22
22
  log(:ERROR,message.to_s)
@@ -0,0 +1,78 @@
1
+
2
+ require 'digest/md5'
3
+
4
+ module Keystone::Batch
5
+ #
6
+ #
7
+ # ●定数
8
+ # ERROR_MAIL_TO (エラーメール送信先) 設定しておけば自動でエラーメールを送信してくれる
9
+ # ERROR_MAIL_FROM (エラーメール送信元) 設定されてない場合はERROR_MAIL_TOを使用
10
+ # ERROR_MAIL_STMP_ADDR (エラーメール送信SMTPアドレス) 設定されてない場合は"127.0.0.1"
11
+ # ERROR_MAIL_STMP_PORT (エラーメール送信SMTPポート) 設定されてない場合は25
12
+ #
13
+ #
14
+ module Base
15
+ def execute(double_process_check = true,auto_recover = true,&process)
16
+ info "start script(#{File.expand_path($0)})"
17
+ warn "ERROR_MAIL_TO not defined.if you want error mail automatically,set this value." unless Module.constants.include?("ERROR_MAIL_TO")
18
+ script_started_at = Time.now
19
+ begin
20
+ # double process check
21
+ if double_process_check
22
+ pg_path = File.expand_path($0)
23
+ pg_name = File.basename(pg_path)
24
+ hash = Digest::MD5.hexdigest(pg_path)
25
+ pid_file = "/tmp/.#{pg_name}.#{hash}.pid"
26
+ debug pid_file
27
+ if File.exists?(pid_file)
28
+ pid = File.open(pid_file).read.chomp
29
+ pid_list = `ps -e | awk '{print $1}'`
30
+ if pid_list =~ /#{pid}/
31
+ warn "pid:#{pid} still running"
32
+ return nil
33
+ else
34
+ if auto_recover
35
+ warn "pid file still exists,but process does not found.so process continues"
36
+ else
37
+ raise "pid file still exists,but process does not found"
38
+ end
39
+ end
40
+ end
41
+ File.open(pid_file, "w"){|file|
42
+ file.write $$
43
+ }
44
+ end
45
+ return (yield process)
46
+ rescue => e
47
+ error e
48
+ send_error_mail(e)
49
+ ensure
50
+ File.delete(pid_file) if double_process_check
51
+ info "finish script (%1.3fsec)" % (Time.now - script_started_at)
52
+ end
53
+ end
54
+
55
+ def send_error_mail(error)
56
+ if Module.constants.include?("ERROR_MAIL_TO")
57
+ host = Keystone::Os.get()
58
+ title = %|error occur at "#{host.hostname}" [#{error.message}]|
59
+
60
+ mail_to = ERROR_MAIL_TO
61
+ mail_to = [mail_to] if mail_to.is_a?(String)
62
+ mail_from = Module.constants.include?("ERROR_MAIL_FROM") ? ERROR_MAIL_FROM : mail_to[0]
63
+ smtp_addr = Module.constants.include?("ERROR_MAIL_STMP_ADDR") ? ERROR_MAIL_STMP_ADDR : '127.0.0.1'
64
+ smtp_port = Module.constants.include?("ERROR_MAIL_STMP_PORT") ? ERROR_MAIL_STMP_PORT : 25
65
+
66
+ body = <<-BODY
67
+ ==== error message ====
68
+ #{error.message}
69
+ ====== backtrace ======
70
+ #{error.backtrace.join("\n")}
71
+ ===== environment =====
72
+ #{host.dump}
73
+ BODY
74
+ Keystone::Mail::Send.send(mail_from,mail_to,title,body,smtp_addr,smtp_port)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ module Keystone
2
+ module Batch
3
+ autoload :Base , 'keystone/batch/base'
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ class Array
2
+ #
3
+ # TODO
4
+ # active_supportに同様のメソッドが無いかどうかの確認
5
+ #
6
+ def split_by(num)
7
+ ret = [[]]
8
+ counter = 0
9
+ self.each do |val|
10
+ (counter = 0;ret << []) if counter >= num
11
+ ret[-1] << val
12
+ counter += 1
13
+ end
14
+ return ret
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ class Object
2
+ # copy from activesupport
3
+ def blank?
4
+ respond_to?(:empty?) ? empty? : !self
5
+ end
6
+ end
7
+
8
+ class NilClass #:nodoc:
9
+ def blank?
10
+ true
11
+ end
12
+ end
13
+
14
+ class FalseClass #:nodoc:
15
+ def blank?
16
+ true
17
+ end
18
+ end
19
+
20
+ class TrueClass #:nodoc:
21
+ def blank?
22
+ false
23
+ end
24
+ end
25
+
26
+ class Array #:nodoc:
27
+ alias_method :blank?, :empty?
28
+ end
29
+
30
+ class Hash #:nodoc:
31
+ alias_method :blank?, :empty?
32
+ end
33
+
34
+ class String #:nodoc:
35
+ def blank?
36
+ self !~ /\S/
37
+ end
38
+ end
39
+
40
+ class Numeric #:nodoc:
41
+ def blank?
42
+ false
43
+ end
44
+ end
@@ -0,0 +1,12 @@
1
+ class Dir
2
+ def self.mkdir_r(dirPath)
3
+ folders = dirPath.split('/')
4
+ folderToCreate = ''
5
+ folders.each do |folder|
6
+ folderToCreate += folder + '/'
7
+ if !File.directory?(folderToCreate)
8
+ Dir.mkdir(folderToCreate)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ class Object
2
+ # http://www.yohasebe.com/pages/trans-seeing-metaclasses-clearly/
3
+ def metaclass
4
+ class << self
5
+ self
6
+ end
7
+ end
8
+
9
+ # http://www.yohasebe.com/pages/trans-seeing-metaclasses-clearly/
10
+ def meta_eval(&blk)
11
+ metaclass.instance_eval(&blk)
12
+ end
13
+
14
+ # http://www.yohasebe.com/pages/trans-seeing-metaclasses-clearly/
15
+ def meta_def(name, &blk)
16
+ meta_eval { define_method name, &blk }
17
+ end
18
+
19
+ # http://www.yohasebe.com/pages/trans-seeing-metaclasses-clearly/
20
+ def class_def(name, &blk)
21
+ class_eval { define_method name, &blk }
22
+ end
23
+
24
+ # 1.8.7 エミュレート
25
+ def tap
26
+ yield(self)
27
+ self
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ require 'tempfile'
2
+
3
+ class Tempfile
4
+ def self.open_with_block(name = nil, dir = nil)
5
+ name ||= (0..8).map{rand(36).to_s(36)}.join
6
+ args = dir ? [name, dir] : [name]
7
+ tmp = Tempfile.open *args
8
+ begin
9
+ yield tmp
10
+ ensure
11
+ tmp.close true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class Uri
2
+ #
3
+ def self.escape_raw(st)
4
+ st.gsub(/([^a-zA-Z0-9_\-\.~])/) { "%#{$1.unpack('H*')[0].scan(/../).join('%').upcase }" }
5
+ end
6
+
7
+ #
8
+ # usage
9
+ # @search_tag = Uri.unescape_raw(params[:tag]).toutf8
10
+ #
11
+ def self.unescape_raw(st)
12
+ st.tr('+',' ').gsub(/%([A-Fa-f0-9][A-Fa-f0-9])/) { [$1.hex].pack('C') }
13
+ end
14
+ end
@@ -1,76 +1,17 @@
1
-
2
- require 'tempfile'
3
-
4
- class Uri
5
- #
6
- def self.escape_raw(st)
7
- st.gsub(/([^a-zA-Z0-9_\-\.~])/) { "%#{$1.unpack('H*')[0].scan(/../).join('%').upcase }" }
8
- end
9
-
10
- #
11
- # usage
12
- # @search_tag = Uri.unescape_raw(params[:tag]).toutf8
13
- #
14
- #
15
- def self.unescape_raw(st)
16
- st.tr('+',' ').gsub(/%([A-Fa-f0-9][A-Fa-f0-9])/) { [$1.hex].pack('C') }
1
+ module Keystone
2
+ module CoreExt
3
+ require 'keystone/core_ext/blank'
4
+ require 'keystone/core_ext/uri'
5
+ require 'keystone/core_ext/tempfile'
6
+ require 'keystone/core_ext/dir'
7
+ require 'keystone/core_ext/object'
8
+ require 'keystone/core_ext/array'
17
9
  end
18
10
  end
19
11
 
20
- class Tempfile
21
- def self.open_with_block(name = nil, dir = nil)
22
- name ||= (0..8).map{rand(36).to_s(36)}.join
23
- args = dir ? [name, dir] : [name]
24
- tmp = Tempfile.open *args
25
- begin
26
- yield tmp
27
- ensure
28
- tmp.close true
29
- end
30
- end
31
- end
32
12
 
33
- class Dir
34
- def self.mkdir_r(dirPath)
35
- folders = dirPath.split('/')
36
- folderToCreate = ''
37
- folders.each do |folder|
38
- folderToCreate += folder + '/'
39
- if !File.directory?(folderToCreate)
40
- Dir.mkdir(folderToCreate)
41
- end
42
- end
43
- end
44
- end
45
13
 
46
- class Object
47
- # http://www.yohasebe.com/pages/trans-seeing-metaclasses-clearly/
48
- def metaclass
49
- class << self
50
- self
51
- end
52
- end
53
-
54
- # http://www.yohasebe.com/pages/trans-seeing-metaclasses-clearly/
55
- def meta_eval(&blk)
56
- metaclass.instance_eval(&blk)
57
- end
58
-
59
- # http://www.yohasebe.com/pages/trans-seeing-metaclasses-clearly/
60
- def meta_def(name, &blk)
61
- meta_eval { define_method name, &blk }
62
- end
63
-
64
- # http://www.yohasebe.com/pages/trans-seeing-metaclasses-clearly/
65
- def class_def(name, &blk)
66
- class_eval { define_method name, &blk }
67
- end
68
-
69
- # 1.8.7 エミュレート
70
- def tap
71
- yield(self)
72
- self
73
- end
74
- end
14
+
15
+
75
16
 
76
17
 
@@ -14,8 +14,16 @@ module Keystone
14
14
 
15
15
  def self.send(from,to,title,body,smtp_addr="127.0.0.1",smtp_port=25)
16
16
  from_addr,from_addr_4_header = create_addr_and_header(from)
17
- title = Kconv.tojis(title)
18
- title = title.split(//,1).pack('m'); title = title.chomp
17
+ title.gsub!(/(\r|\n)/,"")
18
+
19
+ subject_header = ""
20
+ title.split(//).split_by(10).each do |subject|
21
+ st = subject.join('')
22
+ st = Kconv.tojis(st)
23
+ st = st.split(//,1).pack('m'); st = st.chomp
24
+ subject_header += " =?ISO-2022-JP?B?#{st}?=\n"
25
+ end
26
+
19
27
  if to.class.to_s == 'Array'
20
28
  tomany = to.join(',')
21
29
  else
@@ -23,13 +31,13 @@ module Keystone
23
31
  end
24
32
 
25
33
  head = <<HEAD
26
- Subject: =?ISO-2022-JP?B?#{title}?=
27
- To: #{tomany}
34
+ Subject: #{subject_header}To: #{tomany}
28
35
  From: #{from_addr_4_header}
29
36
  Mime-Version: 1.0
30
37
  Content-Transfer-Encoding: 7bit
31
38
  Content-Type: Text/Plain; charset=iso-2022-jp
32
39
  HEAD
40
+
33
41
  src = head + "\n" + Kconv.tojis(body)
34
42
  # puts src
35
43
  m = Net::SMTPSession.new(smtp_addr, smtp_port)
@@ -37,7 +45,7 @@ HEAD
37
45
  m.sendmail(src, from_addr, to)
38
46
  m.finish
39
47
  end
40
-
48
+
41
49
  def send(from,to,title,body)
42
50
  self.class.send(from,to,title,body,@smtp_addr,@smtp_port)
43
51
  end
@@ -0,0 +1,34 @@
1
+ module Keystone
2
+ module Os
3
+ class AbstractOs
4
+
5
+ attr_accessor :version
6
+
7
+ def ip_address
8
+ end
9
+
10
+ def hostname
11
+ end
12
+
13
+ def disk
14
+ end
15
+
16
+ def process_list
17
+ end
18
+
19
+ def netstat
20
+ end
21
+
22
+ def dump
23
+ self_methods = self.methods - Class.methods
24
+ self_methods.delete("version=")
25
+ self_methods.delete("dump")
26
+ st = ""
27
+ self_methods.each do |method|
28
+ st << "== #{method} ==\n #{self.__send__(method).to_s.split("\n").join("\n ")}\n"
29
+ end
30
+ return st
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,6 @@
1
+ module Keystone
2
+ module Os
3
+ class Centos < Linux
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module Keystone
2
+ module Os
3
+ class Darwin < Unix
4
+ def process_list
5
+ `/bin/ps -aux`.chomp
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Keystone::Os
2
+ class Linux < Unix
3
+ def self.get
4
+ Dir.glob("/etc/*{-release,_version}").each do |file|
5
+ content = File.open(file).read
6
+ if content =~ /CentOS release (\d*)/
7
+ os = Centos.new
8
+ os.version = $1.to_i
9
+ return os
10
+ end
11
+ end
12
+ return Linux.new
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module Keystone
2
+ module Os
3
+ class Osx < Darwin
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+ module Keystone
2
+ module Os
3
+ class Unix < AbstractOs
4
+ def ip_address
5
+ ifconfig = `/sbin/ifconfig`
6
+ ips = []
7
+
8
+ # TODO mac
9
+ ifconfig.gsub(/inet addr:(\d+\.\d+\.\d+\.\d+)/){|ip|
10
+ if $1 != '127.0.0.1'
11
+ ips << $1
12
+ end
13
+ }
14
+ return ips
15
+ end
16
+
17
+ def hostname
18
+ `/bin/hostname`.chomp
19
+ end
20
+
21
+ def disk
22
+ `/bin/df -h`.chomp
23
+ end
24
+
25
+ def process_list
26
+ `/bin/ps -ef`.chomp
27
+ end
28
+
29
+ def netstat
30
+ `/usr/sbin/netstat -an`.chomp
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ require 'keystone/os/abstract_os'
2
+
3
+ module Keystone::Os
4
+ autoload :Centos, 'keystone/os/centos'
5
+ autoload :Linux, 'keystone/os/linux'
6
+ autoload :Darwin, 'keystone/os/darwin'
7
+ autoload :Osx, 'keystone/os/osx'
8
+ autoload :Unix, 'keystone/os/unix'
9
+ # autoload :Windows, 'keystone/env/windows.rb' # fu*k windows
10
+ def self.oses
11
+ @oses ||= constants
12
+ end
13
+
14
+ def self.get
15
+ case RUBY_PLATFORM
16
+ when /linux/
17
+ # TODO only centos impremented
18
+ Keystone::Os::Linux.get()
19
+ when /darwin/
20
+ # TODO only osx impremented
21
+ Keystone::Os::Osx.new
22
+ else
23
+ # TODO
24
+ end
25
+ end
26
+ end
@@ -59,7 +59,7 @@ module Keystone
59
59
  #
60
60
  # TODO
61
61
  def self.downcase_roma_number(st)
62
- st.tr("ⅠⅡⅢⅣ", "ⅰⅱⅲⅳ")
62
+ st.tr("ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ", "ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹ")
63
63
  end
64
64
 
65
65
  #
@@ -67,7 +67,8 @@ module Keystone
67
67
  #
68
68
  def self.to_searchtext(str)
69
69
  self.downcase_roma_number(Moji.han_to_zen(
70
- Moji.zen_to_han(str,Moji::ZEN_ALNUM | Moji::ZEN_SYMBOL).downcase,Moji::HAN_KATA | Moji::HAN_JSYMBOL).tr("ー~/","ー~/")
70
+ #Moji.zen_to_han(str,Moji::ZEN_ALNUM | Moji::ZEN_SYMBOL).downcase,Moji::HAN_KATA | Moji::HAN_JSYMBOL).tr("ー~/","ー~/")
71
+ Moji.zen_to_han(str,Moji::ZEN_ALNUM | Moji::ZEN_SYMBOL).downcase,Moji::HAN_KATA | Moji::HAN_JSYMBOL)
71
72
  )
72
73
  end
73
74
  end
data/lib/keystone.rb CHANGED
@@ -11,12 +11,12 @@ autoload :Moji , 'moji'
11
11
 
12
12
  module Keystone
13
13
 
14
- VERSION = '0.0.10'
14
+ VERSION = '0.0.11'
15
15
 
16
- autoload :StringUtil , 'keystone/string_util'
17
- autoload :BatchUtil , 'keystone/batch_util'
18
- autoload :Environment , 'keystone/environment'
19
- autoload :Mail , 'keystone/mail'
16
+ autoload :StringUtil , 'keystone/string_util'
17
+ autoload :Batch , 'keystone/batch'
18
+ autoload :Os , 'keystone/os'
19
+ autoload :Mail , 'keystone/mail'
20
20
 
21
21
  module Rails
22
22
  #autoload :ActiveSupportExt, 'keystone/rails/active_support_ext'
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'redgreen'
3
+ require 'vendor/moji'
4
+ require 'vendor/flag_set_maker'
5
+ require 'lib/keystone/string_util'
6
+
7
+ $KCODE='u'
8
+
9
+ class TestStringUtilBase < Test::Unit::TestCase
10
+ def setup
11
+ end
12
+
13
+ def test_reverse_mail
14
+ assert_equal(Keystone::StringUtil::reverse_mail("testuser@softbank.ne.jp"),"jp.ne.softbank@testuser")
15
+ assert_equal(Keystone::StringUtil::reverse_mail("test.user@somedomain.com"),"com.somedomain@test.user")
16
+ assert_equal(Keystone::StringUtil::reverse_mail("a.b@c.d"),"d.c@a.b")
17
+ assert_equal(Keystone::StringUtil::reverse_mail("a.b@"),"@a.b")
18
+ assert_equal(Keystone::StringUtil::reverse_mail("@c.d"),"d.c@")
19
+ assert_equal(Keystone::StringUtil::reverse_mail("a.b"),"a.b")
20
+ end
21
+
22
+ def test_int_to_splitted_path
23
+ assert_equal(Keystone::StringUtil.int_to_splitted_path(113355,12,"/tmp",".jpg"),"/tmp/000/000/113/355.jpg")
24
+ assert_equal(Keystone::StringUtil.int_to_splitted_path(1234567890,10,"/temp",".png"),"/temp/1/234/567/890.png")
25
+ assert_equal(Keystone::StringUtil.int_to_splitted_path(1234567890,11,"/temp",".png"),"/temp/01/234/567/890.png")
26
+ assert_raise(RangeError){Keystone::StringUtil.int_to_splitted_path(12345678901,10,"/tmp")}
27
+ assert_equal(Keystone::StringUtil.int_to_splitted_path(00000000000000001,11,"/tmp",".gif"),"/tmp/00/000/000/001.gif")
28
+ end
29
+
30
+ def test_serach_string_to_array
31
+ assert_equal(Keystone::StringUtil.serach_string_to_array(%|test test2 test3|),%w|test test2 test3|)
32
+ assert_equal(Keystone::StringUtil.serach_string_to_array(%|test "test2" test3|),%w|test test2 test3|)
33
+ assert_equal(Keystone::StringUtil.serach_string_to_array(%|test "test 2" test3|),["test","test 2","test3"])
34
+ assert_equal(Keystone::StringUtil.serach_string_to_array(%|"test 1" "test 2" test3|),["test 1","test 2","test3"])
35
+ assert_equal(Keystone::StringUtil.serach_string_to_array(%|"日本語 1" "test 2" test3|),["日本語 1","test 2","test3"])
36
+ assert_equal(Keystone::StringUtil.serach_string_to_array(%|"日本語 1" "test 2" ハンカク|),["日本語 1","test 2","ハンカク"])
37
+ # TODO
38
+ # assert_equal(Keystone::StringUtil.serach_string_to_array(%|"日本語 1" "tes\"t 2" ハンカク|),["日本語 1","test 2","ハンカク"])
39
+ end
40
+
41
+ def test_to_searchtext
42
+ assert_equal(Keystone::StringUtil.to_searchtext("日本語"),"日本語")
43
+ assert_equal(Keystone::StringUtil.to_searchtext("カタカナ"),"カタカナ")
44
+ assert_equal(Keystone::StringUtil.to_searchtext("ハンカク"),"ハンカク")
45
+ assert_equal(Keystone::StringUtil.to_searchtext("A"),"a")
46
+ assert_equal(Keystone::StringUtil.to_searchtext("1"),"1")
47
+ assert_equal(Keystone::StringUtil.to_searchtext("abCD1234"),"abcd1234")
48
+ assert_equal(Keystone::StringUtil.to_searchtext("スープ"),"スープ")
49
+ assert_equal(Keystone::StringUtil.to_searchtext("スープ"),"スープ") # ハンカク半濁点
50
+ assert_equal(Keystone::StringUtil.to_searchtext("コズミックラナウェイ"),"コズミックラナウェイ") # ハンカク濁点
51
+ assert_equal(Keystone::StringUtil.to_searchtext("ー―-‐"),"ー―-‐") # ハンカク濁点
52
+
53
+
54
+
55
+ # TODO
56
+ assert_equal(Keystone::StringUtil.to_searchtext("!”$%&¥’()*+,-./:;<=>?@[¥]^_‘{|}~#"),"!\"$%&\\'()*+,-./:;<=>?@[\\]^_`{|}~#") # 半角全角変換可能記号
57
+ assert_equal(Keystone::StringUtil.to_searchtext("。「」、ー゙゚・"),"。「」、ー゛゜・")
58
+ assert_equal(Keystone::StringUtil.to_searchtext("ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ"),"ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹ")
59
+ end
60
+ end
data/vendor/moji.rb CHANGED
@@ -298,7 +298,8 @@ module Moji
298
298
  module Detail
299
299
 
300
300
  HAN_ASYMBOL_LIST= ' !"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~'
301
- ZEN_ASYMBOL_LIST= ' !”#$%&’()*+,-./:;<=>?@[¥]^_‘{|} ̄'
301
+ # ZEN_ASYMBOL_LIST= ' !”#$%&’()*+,-./:;<=>?@[¥]^_‘{|} ̄' # Keystone replaced
302
+ ZEN_ASYMBOL_LIST= ' !”#$%&’()*+,-./:;<=>?@[¥]^_‘{|}~'
302
303
  HAN_JSYMBOL1_LIST= '。「」、ー゙゚・'
303
304
  ZEN_JSYMBOL1_LIST= '。「」、ー゛゜・'
304
305
  ZEN_JSYMBOL_LIST= '、。・゛゜´`¨ヽヾゝゞ〃仝々〆〇ー―‐\~〜∥…‥“〔〕〈〉《》「」『』【】'+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanamei-keystone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - kanamei
@@ -22,14 +22,34 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
+ - example/batch_sample.rb
26
+ - example/os.rb
27
+ - example/string_util.rb
28
+ - test/test_string_util.rb
25
29
  - lib/keystone
26
30
  - lib/keystone/base.rb
27
- - lib/keystone/batch_base.rb
31
+ - lib/keystone/batch
32
+ - lib/keystone/batch/base.rb
33
+ - lib/keystone/batch.rb
34
+ - lib/keystone/core_ext
35
+ - lib/keystone/core_ext/array.rb
36
+ - lib/keystone/core_ext/blank.rb
37
+ - lib/keystone/core_ext/dir.rb
38
+ - lib/keystone/core_ext/object.rb
39
+ - lib/keystone/core_ext/tempfile.rb
40
+ - lib/keystone/core_ext/uri.rb
28
41
  - lib/keystone/core_ext.rb
29
- - lib/keystone/environment.rb
30
42
  - lib/keystone/mail
31
43
  - lib/keystone/mail/send.rb
32
44
  - lib/keystone/mail.rb
45
+ - lib/keystone/os
46
+ - lib/keystone/os/abstract_os.rb
47
+ - lib/keystone/os/centos.rb
48
+ - lib/keystone/os/darwin.rb
49
+ - lib/keystone/os/linux.rb
50
+ - lib/keystone/os/osx.rb
51
+ - lib/keystone/os/unix.rb
52
+ - lib/keystone/os.rb
33
53
  - lib/keystone/string_util.rb
34
54
  - lib/keystone.rb
35
55
  - vendor/flag_set_maker.rb
@@ -42,6 +62,8 @@ rdoc_options: []
42
62
  require_paths:
43
63
  - lib
44
64
  - vendor
65
+ - example
66
+ - test
45
67
  required_ruby_version: !ruby/object:Gem::Requirement
46
68
  requirements:
47
69
  - - ">="
@@ -1,17 +0,0 @@
1
- module Keystone
2
- module BatchBase
3
- def execute(&process)
4
- info "start script"
5
- script_started_at = Time.now
6
- begin
7
- return (yield process)
8
- rescue => e
9
- error e
10
- Skutil::Mail.send_error(ERROR_MAIL_FROM,ERROR_MAIL_TO,ERROR_MAIL_SUBJECT,e)
11
- return e
12
- ensure
13
- info "finish script (%1.3fsec)" % (Time.now - script_started_at)
14
- end
15
- end
16
- end
17
- end
@@ -1,47 +0,0 @@
1
- module Keystone
2
- class Environment
3
- def self.ip_address
4
- ifconfig = `/sbin/ifconfig`
5
- ips = []
6
-
7
- # TODO mac
8
- ifconfig.gsub(/inet addr:(\d+\.\d+\.\d+\.\d+)/){|ip|
9
- if $1 != '127.0.0.1'
10
- ips << $1
11
- end
12
- }
13
- return ips
14
- end
15
-
16
- def self.hostname
17
- `/bin/hostname`.chomp
18
- end
19
-
20
- def self.df
21
- `/bin/df -h`.chomp
22
- end
23
-
24
- def self.ps
25
- `/bin/ps -ef`.chomp
26
- end
27
-
28
- def self.netstat
29
- `/usr/sbin/netstat -an`.chomp
30
- end
31
-
32
- def self.execute(command)
33
- `#{command}`.chomp
34
- end
35
-
36
- def self.dump
37
- self_methods = self.methods - Class.methods
38
- self_methods.delete("dump")
39
- self_methods.delete("execute")
40
- st = ""
41
- self_methods.each do |method|
42
- st << "#{method}:\n #{self.__send__(method).to_s.split("\n").join("\n ")}\n"
43
- end
44
- return st
45
- end
46
- end
47
- end