inaba 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/CHANGELOG_jp.md +7 -0
- data/LICENSE +7 -0
- data/README.md +127 -0
- data/README_jp.md +127 -0
- data/Rakefile +21 -0
- data/bin/inaba +9 -0
- data/lib/inaba/manipulator.rb +143 -0
- data/test.sdb.dir +0 -0
- data/test.sdb.pag +0 -0
- data/test/tb_manipulator.rb +173 -0
- data/test/test.sdb.dir +0 -0
- data/test/test.sdb.pag +0 -0
- metadata +124 -0
data/CHANGELOG.md
ADDED
data/CHANGELOG_jp.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012 Moza USANE
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
Inaba SDBM Manipulator
|
2
|
+
=======================
|
3
|
+
|
4
|
+
## Introduction
|
5
|
+
|
6
|
+
Inaba SDBM Manipulator is a command line tool to manipulate SDBM database.
|
7
|
+
|
8
|
+
## Operation Environment
|
9
|
+
|
10
|
+
We checked good operation within following environment.
|
11
|
+
|
12
|
+
- Linux(openSUSE 12.2)・Mac OS X 10.8.2
|
13
|
+
- Ruby 1.9.3
|
14
|
+
|
15
|
+
## Architectonics
|
16
|
+
|
17
|
+
- **bin**
|
18
|
+
- **inaba** :: Executable script
|
19
|
+
- **doc** :: Documents generated by rdoc
|
20
|
+
- **lib**
|
21
|
+
- **inaba**
|
22
|
+
- **manipulator.rb** :: Manipulator class
|
23
|
+
- **Rakefile** :: Rakefile that is used to generate gem file
|
24
|
+
- **test**
|
25
|
+
- **tb_manipulator.rb** :: Unit test of Manipulator
|
26
|
+
|
27
|
+
## Depended libraries
|
28
|
+
|
29
|
+
- [Hakto SDBM Safe Wrapper](http://blog.quellencode.org/post/37391766923/ruby-hakto-safe-sdbm-wrapper)
|
30
|
+
- [Ariete STDOUT & STDERR Capture Module](http://blog.quellencode.org/post/37625422082/ariete-stdout-stderr-capture-module)
|
31
|
+
|
32
|
+
## Install
|
33
|
+
|
34
|
+
Download inaba-x.y.z.gem, then execute following command to install Inaba.
|
35
|
+
|
36
|
+
`$ sudo gem install inaba-x.y.z.gem`
|
37
|
+
|
38
|
+
On the other hand, you can install from RubyGems.org to use following command.
|
39
|
+
|
40
|
+
`$ sudo gem install inaba`
|
41
|
+
|
42
|
+
## Tutorial
|
43
|
+
|
44
|
+
### Configuration of environment variable
|
45
|
+
|
46
|
+
Set file path of SDBM database to environment variable named $INABA_DB. If target database file is named rabbit.sdb, use following command in bash.
|
47
|
+
|
48
|
+
`$ export INABA_DB="rabbit.sdb"`
|
49
|
+
|
50
|
+
### Add key value pair
|
51
|
+
|
52
|
+
Use **add** command to add a value to key.
|
53
|
+
|
54
|
+
`$ inaba add rabbit RABBIT`
|
55
|
+
|
56
|
+
Use **list** command to show key value pairs.
|
57
|
+
|
58
|
+
`$ inaba list`
|
59
|
+
|
60
|
+
[rabbit]:RABBIT
|
61
|
+
|
62
|
+
Add more pairs.
|
63
|
+
|
64
|
+
`$ inaba add bunny BUNNY`
|
65
|
+
|
66
|
+
`$ inaba add hare HARE`
|
67
|
+
|
68
|
+
`$ inaba list`
|
69
|
+
|
70
|
+
[rabbit]:RABBIT
|
71
|
+
[bunny]:BUNNY
|
72
|
+
[hare]:HARE
|
73
|
+
|
74
|
+
Inaba can output a pair list with CSV format.
|
75
|
+
|
76
|
+
`$ inaba csv`
|
77
|
+
|
78
|
+
rabbit,RABBIT
|
79
|
+
bunny,BUNNY
|
80
|
+
hare,HARE
|
81
|
+
|
82
|
+
Also use **keys** command to list keys.
|
83
|
+
|
84
|
+
`$ inaba keys`
|
85
|
+
|
86
|
+
rabbit, bunny, hare,
|
87
|
+
|
88
|
+
**Values** command works listing values.
|
89
|
+
|
90
|
+
`$ inaba values`
|
91
|
+
|
92
|
+
RABBIT, BUNNY, HARE,
|
93
|
+
|
94
|
+
Use **del** command to delete key value command.
|
95
|
+
|
96
|
+
`$ inaba del rabbit`
|
97
|
+
|
98
|
+
`$ inaba list`
|
99
|
+
|
100
|
+
[bunny]:BUNNY
|
101
|
+
[hare]:HARE
|
102
|
+
|
103
|
+
**Clear** command removes all key value pairs.
|
104
|
+
|
105
|
+
`$ inaba clear`
|
106
|
+
|
107
|
+
## Commands reference
|
108
|
+
|
109
|
+
|コマンド |引数 |説明 |
|
110
|
+
|----------|-------------|------------------------------------|
|
111
|
+
|**add** |*key* *value*|Add *value* to *key* |
|
112
|
+
|**del** |*key* |Delete a value associated with *key*|
|
113
|
+
|**list** | |Output key value pairs |
|
114
|
+
|**keys** | |Output keys |
|
115
|
+
|**values**| |Output values |
|
116
|
+
|**csv** | |Output pairs with CSV format |
|
117
|
+
|**help** | |Output command list |
|
118
|
+
|
119
|
+
## License
|
120
|
+
|
121
|
+
Inaba is distributed with MIT License. See the LICENSE file to read the detail of license.
|
122
|
+
|
123
|
+
## About Author
|
124
|
+
|
125
|
+
Moza USANE
|
126
|
+
[http://blog.quellencode.org/](http://blog.quellencode.org/ "")
|
127
|
+
mozamimy@quellencode.org
|
data/README_jp.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
Inaba SDBM Manipulator
|
2
|
+
======================
|
3
|
+
|
4
|
+
## イントロダクション
|
5
|
+
|
6
|
+
Inaba SDBM Manipulatorは、SDBMの内容を操作するためのコマンドラインツールである。キーバリューペアの追加、削除、一覧など、基本的なインターフェースを取り揃えている。
|
7
|
+
|
8
|
+
## 動作環境
|
9
|
+
|
10
|
+
以下の環境で開発およびテストをしている。
|
11
|
+
|
12
|
+
- Linux(openSUSE 12.2)・Mac OS X 10.8.2
|
13
|
+
- Ruby 1.9.3
|
14
|
+
|
15
|
+
## 構成
|
16
|
+
|
17
|
+
- **bin**
|
18
|
+
- **inaba** :: 実行スクリプト
|
19
|
+
- **doc** :: rdocによるドキュメント
|
20
|
+
- **lib**
|
21
|
+
- **inaba**
|
22
|
+
- **manipulator.rb** :: Manipulatorクラス
|
23
|
+
- **Rakefile** :: gemパッケージ生成用のRakefile
|
24
|
+
- **test**
|
25
|
+
- **tb_manipulator.rb** :: Manipulatorのテスト
|
26
|
+
|
27
|
+
## 依存ライブラリ
|
28
|
+
|
29
|
+
- [Hakto SDBM Safe Wrapper](http://blog.quellencode.org/post/37391766923/ruby-hakto-safe-sdbm-wrapper)
|
30
|
+
- [Ariete STDOUT & STDERR Capture Module](http://blog.quellencode.org/post/37625422082/ariete-stdout-stderr-capture-module)
|
31
|
+
|
32
|
+
## インストール
|
33
|
+
|
34
|
+
inaba-x.y.z.gemファイル(x、y、zはバージョン番号)をダウンロードし、以下のコマンドを入力してインストールする。
|
35
|
+
|
36
|
+
`$ sudo gem install inaba-x.y.z.gem`
|
37
|
+
|
38
|
+
または、RubyGems.orgからgemコマンドを使ってインストールすることもできる。
|
39
|
+
|
40
|
+
`$ sudo gem install inaba`
|
41
|
+
|
42
|
+
## チュートリアル
|
43
|
+
|
44
|
+
### 環境変数の設定
|
45
|
+
|
46
|
+
ファイル名入力の手間を省くために、環境変数INABA_DBにファイル名をセットする。対象のDBファイルがrabbit.sdbであれば、bashでは以下のように設定する。
|
47
|
+
|
48
|
+
`$ export INABA_DB="rabbit.sdb"`
|
49
|
+
|
50
|
+
### キーバリューペアを追加する
|
51
|
+
|
52
|
+
キーに値を追加するにはaddコマンドを使う。これで、キーrabbitに値RABBITがセットされる。
|
53
|
+
|
54
|
+
`$ inaba add rabbit RABBIT`
|
55
|
+
|
56
|
+
キーバリューペアの一覧を見るには、listコマンドを使う。
|
57
|
+
|
58
|
+
`$ inaba list`
|
59
|
+
|
60
|
+
[rabbit]:RABBIT
|
61
|
+
|
62
|
+
もっとキーバリューペアを追加してみよう。
|
63
|
+
|
64
|
+
`$ inaba add bunny BUNNY`
|
65
|
+
|
66
|
+
`$ inaba add hare HARE`
|
67
|
+
|
68
|
+
`$ inaba list`
|
69
|
+
|
70
|
+
[rabbit]:RABBIT
|
71
|
+
[bunny]:BUNNY
|
72
|
+
[hare]:HARE
|
73
|
+
|
74
|
+
CSV形式で出力することもできる。
|
75
|
+
|
76
|
+
`$ inaba csv`
|
77
|
+
|
78
|
+
rabbit,RABBIT
|
79
|
+
bunny,BUNNY
|
80
|
+
hare,HARE
|
81
|
+
|
82
|
+
キーのみを一覧することもできる。
|
83
|
+
|
84
|
+
`$ inaba key`
|
85
|
+
|
86
|
+
rabbit, bunny, hare,
|
87
|
+
|
88
|
+
値のみを一覧することもできる
|
89
|
+
|
90
|
+
`$ inaba values`
|
91
|
+
|
92
|
+
RABBIT, BUNNY, HARE,
|
93
|
+
|
94
|
+
キーバリューペアの削除にはdelコマンドを使う。
|
95
|
+
|
96
|
+
`$ inaba del rabbit`
|
97
|
+
|
98
|
+
`$ inaba list`
|
99
|
+
|
100
|
+
[bunny]:BUNNY
|
101
|
+
[hare]:HARE
|
102
|
+
|
103
|
+
全て削除するためにはclearコマンドを使う。
|
104
|
+
|
105
|
+
`$ inaba clear`
|
106
|
+
|
107
|
+
## コマンド一覧
|
108
|
+
|
109
|
+
|コマンド |引数 |説明 |
|
110
|
+
|----------|-------------|-----------------------------------|
|
111
|
+
|**add** |*key* *value*|*key*に*value*を追加する |
|
112
|
+
|**del** |*key* |*key*に関連付けられた値を削除する |
|
113
|
+
|**list** | |キーバリューペアの一覧を出力する |
|
114
|
+
|**keys** | |キー一覧を出力する |
|
115
|
+
|**values**| |値一覧を出力する |
|
116
|
+
|**csv** | |キーバリューペアをCSV形式で出力する|
|
117
|
+
|**help** | |コマンド一覧を出力する |
|
118
|
+
|
119
|
+
## ライセンス
|
120
|
+
|
121
|
+
本ソフトウェアは、MIT Licenseのもとで配布されている。詳細はLICENSEファイルに記している。
|
122
|
+
|
123
|
+
## 作者について
|
124
|
+
|
125
|
+
Moza USANE
|
126
|
+
[http://blog.quellencode.org/](http://blog.quellencode.org/ "")
|
127
|
+
mozamimy@quellencode.org
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rake/gempackagetask"
|
2
|
+
|
3
|
+
spec = Gem::Specification.new do |s|
|
4
|
+
s.name = "inaba"
|
5
|
+
s.summary = "Inaba SDBM Manipulator is a command line tool to manipulate SDBM database."
|
6
|
+
s.description = File.read(File.join(File.dirname(__FILE__), "README.md"))
|
7
|
+
s.version = "0.0.1"
|
8
|
+
s.author = "Moza USANE"
|
9
|
+
s.email = "mozamimy@quellencode.org"
|
10
|
+
s.homepage = "http://quellencode.org/"
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.required_ruby_version = ">=1.9"
|
13
|
+
s.add_dependency "hakto", ">=0.0.1"
|
14
|
+
s.add_dependency "ariete", ">=0.0.1"
|
15
|
+
s.executables = ["inaba"]
|
16
|
+
s.files = Dir["**/**"]
|
17
|
+
s.test_files = Dir["test/tb_*.rb"]
|
18
|
+
s.has_rdoc = true
|
19
|
+
end
|
20
|
+
|
21
|
+
Rake::GemPackageTask.new(spec).define
|
data/bin/inaba
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "hakto/safe_sdbm"
|
5
|
+
|
6
|
+
# Inaba git like SDBM manipulator is a manipulator of SDBM database.
|
7
|
+
# Author:: Moza USANE (mailto:mozamimy@quellencode.org)
|
8
|
+
# Copyright:: Copyright (c) 2012 Moza USANE
|
9
|
+
# License:: MIT License (see the LICENSE file)
|
10
|
+
module Inaba
|
11
|
+
|
12
|
+
# Manipulator of SDBM database.
|
13
|
+
# It manipurates SDBM database by some sub commands.
|
14
|
+
class Manipulator
|
15
|
+
|
16
|
+
# Return codes
|
17
|
+
ARG_ERROR = -1
|
18
|
+
CMD_ERROR = -2
|
19
|
+
ENV_ERROR = -3
|
20
|
+
SUCCESS = 0
|
21
|
+
|
22
|
+
# Initialize Manipulator
|
23
|
+
def initialize(argv)
|
24
|
+
@argv = argv
|
25
|
+
check_env
|
26
|
+
end
|
27
|
+
|
28
|
+
# Run Manipulator
|
29
|
+
# ==== Return
|
30
|
+
# ret_code :: Return code of Manipulator's process.
|
31
|
+
def run
|
32
|
+
COMMANDS.each do |cmd_group|
|
33
|
+
cmd_group.each do |cmd|
|
34
|
+
ret_code = self.send("operate_#{cmd_group[0]}", @argv) if @argv[0] == cmd
|
35
|
+
return ret_code if (ret_code == ARG_ERROR or ret_code == SUCCESS)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
print_unrecognizable_error
|
40
|
+
return CMD_ERROR
|
41
|
+
end
|
42
|
+
|
43
|
+
# Does Manipulator has a valid environment variable: $INABA_DB
|
44
|
+
# ==== Return
|
45
|
+
# is_ready :: ready status
|
46
|
+
def ready?
|
47
|
+
@is_ready
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
ENV_STRING = "INABA_DB"
|
52
|
+
|
53
|
+
COMMAND_ADD = ["add", "a"]
|
54
|
+
COMMAND_CLEAR = ["clear", "c"]
|
55
|
+
COMMAND_DEL = ["del", "d"]
|
56
|
+
COMMAND_LIST = ["list", "l"]
|
57
|
+
COMMAND_KEYS = ["keys", "k"]
|
58
|
+
COMMAND_VALUES = ["values", "v"]
|
59
|
+
COMMAND_CSV = ["csv", "s"]
|
60
|
+
COMMAND_HELP = ["help", "h"]
|
61
|
+
COMMANDS = [COMMAND_ADD, COMMAND_DEL, COMMAND_LIST,
|
62
|
+
COMMAND_KEYS, COMMAND_VALUES, COMMAND_CSV,
|
63
|
+
COMMAND_HELP, COMMAND_CLEAR]
|
64
|
+
|
65
|
+
def check_env
|
66
|
+
if ENV[ENV_STRING]
|
67
|
+
@dbm = Hakto::SafeSDBM.new(ENV[ENV_STRING])
|
68
|
+
@is_ready = true
|
69
|
+
else
|
70
|
+
print_env_error_msg
|
71
|
+
@is_ready = false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def print_env_error_msg
|
76
|
+
warn "**Environment variable error**"
|
77
|
+
warn "Did you define $INABA_DB environment variable?"
|
78
|
+
warn "Try following command if you use bash."
|
79
|
+
warn 'export INABA_DB="[your_db_file_path]"'
|
80
|
+
end
|
81
|
+
|
82
|
+
def print_unrecognizable_error
|
83
|
+
warn "**Unrecognizable command '#{@argv[0]}'"
|
84
|
+
operate_help
|
85
|
+
end
|
86
|
+
|
87
|
+
def operate_add(cmd_line)
|
88
|
+
operate(cmd_line, 3) do
|
89
|
+
@dbm[cmd_line[1]] = cmd_line[2]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def operate_clear(cmd_line)
|
94
|
+
operate(cmd_line, 1) {@dbm.clear}
|
95
|
+
end
|
96
|
+
|
97
|
+
def operate_del(cmd_line)
|
98
|
+
operate(cmd_line, 2) {@dbm.delete(cmd_line[1])}
|
99
|
+
end
|
100
|
+
|
101
|
+
def operate_list(cmd_line)
|
102
|
+
operate(cmd_line, 1) {@dbm.print_each}
|
103
|
+
end
|
104
|
+
|
105
|
+
def operate_keys(cmd_line)
|
106
|
+
operate(cmd_line, 1) {@dbm.print_keys; print "\n"}
|
107
|
+
end
|
108
|
+
|
109
|
+
def operate_values(cmd_line)
|
110
|
+
operate(cmd_line, 1) {@dbm.print_values; print "\n"}
|
111
|
+
end
|
112
|
+
|
113
|
+
def operate_csv(cmd_line)
|
114
|
+
operate(cmd_line, 1) {print @dbm.csv_each}
|
115
|
+
end
|
116
|
+
|
117
|
+
def operate_help
|
118
|
+
puts "[command] [description]"
|
119
|
+
puts "add key value :: Add a key-value pair"
|
120
|
+
puts "del key :: Delete value on key"
|
121
|
+
puts "list :: Print all key-value pairs"
|
122
|
+
puts "keys :: Print all keys"
|
123
|
+
puts "values :: Print all values"
|
124
|
+
puts "csv :: Print all values as CSV format"
|
125
|
+
puts "help :: Print this help"
|
126
|
+
end
|
127
|
+
|
128
|
+
def operate(cmd, cmd_length, &block)
|
129
|
+
if cmd.length == cmd_length
|
130
|
+
yield
|
131
|
+
return SUCCESS
|
132
|
+
else
|
133
|
+
print_argument_error(cmd)
|
134
|
+
return ARG_ERROR
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def print_argument_error(cmd)
|
139
|
+
warn "**Command's argument is invalid"
|
140
|
+
warn "in #{cmd[0]} command."
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/test.sdb.dir
ADDED
File without changes
|
data/test.sdb.pag
ADDED
Binary file
|
@@ -0,0 +1,173 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "test/unit"
|
5
|
+
require "ariete"
|
6
|
+
require_relative "../lib/inaba/manipulator"
|
7
|
+
|
8
|
+
include Inaba
|
9
|
+
include Ariete
|
10
|
+
|
11
|
+
# Notice:
|
12
|
+
# Set $INABA_DB environment variable before running this test.
|
13
|
+
# $ export INABA_DB="your_db_file_path"
|
14
|
+
class ManipulatorTest < Test::Unit::TestCase
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@mnp = Manipulator.new("dummy")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_add
|
21
|
+
add_common(["add", "rabbit", "RABBIT"])
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_add_abbr
|
25
|
+
add_common(["a", "rabbit", "RABBIT"])
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_del
|
29
|
+
del_common(["del", "rabbit"])
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_del_abbr
|
33
|
+
del_common(["d", "rabbit"])
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_clear
|
37
|
+
clear_common(["clear"])
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_clear_abbr
|
41
|
+
clear_common(["c"])
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_list
|
45
|
+
list_common(["list"])
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_list_abbr
|
49
|
+
list_common(["l"])
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_keys
|
53
|
+
keys_common(["keys"])
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_keys_abbr
|
57
|
+
keys_common(["k"])
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_values
|
61
|
+
values_common(["values"])
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_values_abbr
|
65
|
+
values_common(["v"])
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_csv
|
69
|
+
csv_common(["csv"])
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_csv_abbr
|
73
|
+
csv_common(["s"])
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_arg_error
|
77
|
+
argv = ["add", "invalid"]
|
78
|
+
@mnp.instance_variable_set(:@argv, argv)
|
79
|
+
ret_code = @mnp.run
|
80
|
+
assert_equal(Manipulator::ARG_ERROR, ret_code)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_cmd_error
|
84
|
+
argv = ["invalid", "rabbit", "pyonpyon"]
|
85
|
+
@mnp.instance_variable_set(:@argv, argv)
|
86
|
+
ret_code = @mnp.run
|
87
|
+
assert_equal(Manipulator::CMD_ERROR, ret_code)
|
88
|
+
end
|
89
|
+
|
90
|
+
def teardown
|
91
|
+
dbm = @mnp.instance_variable_get(:@dbm)
|
92
|
+
dbm.clear
|
93
|
+
end
|
94
|
+
|
95
|
+
# common methods
|
96
|
+
|
97
|
+
def add_common(argv)
|
98
|
+
@mnp.instance_variable_set(:@argv, argv)
|
99
|
+
|
100
|
+
ret_code = @mnp.run
|
101
|
+
dbm = @mnp.instance_variable_get(:@dbm)
|
102
|
+
assert_equal("RABBIT", dbm["rabbit"])
|
103
|
+
assert_equal(Manipulator::SUCCESS, ret_code)
|
104
|
+
end
|
105
|
+
|
106
|
+
def del_common(argv)
|
107
|
+
@mnp.instance_variable_set(:@argv, argv)
|
108
|
+
dbm = @mnp.instance_variable_get(:@dbm)
|
109
|
+
add_some_pair(dbm)
|
110
|
+
|
111
|
+
ret_code = @mnp.run
|
112
|
+
assert_equal(2, dbm.size)
|
113
|
+
assert_equal(Manipulator::SUCCESS, ret_code)
|
114
|
+
assert_nil(dbm["rabbit"])
|
115
|
+
assert_equal("INABA", dbm["inaba"])
|
116
|
+
assert_equal("HAKTO", dbm["hakto"])
|
117
|
+
end
|
118
|
+
|
119
|
+
def clear_common(argv)
|
120
|
+
@mnp.instance_variable_set(:@argv, argv)
|
121
|
+
dbm = @mnp.instance_variable_get(:@dbm)
|
122
|
+
add_some_pair(dbm)
|
123
|
+
|
124
|
+
ret_code = @mnp.run
|
125
|
+
assert_equal(0, dbm.size)
|
126
|
+
assert_nil(dbm["rabbit"])
|
127
|
+
assert_nil(dbm["hakto"])
|
128
|
+
assert_nil(dbm["inaba"])
|
129
|
+
end
|
130
|
+
|
131
|
+
def list_common(argv)
|
132
|
+
@mnp.instance_variable_set(:@argv, argv)
|
133
|
+
dbm = @mnp.instance_variable_get(:@dbm)
|
134
|
+
add_some_pair(dbm)
|
135
|
+
|
136
|
+
result = capture_stdout {@mnp.run}
|
137
|
+
assert_equal("[rabbit]:RABBIT\n[hakto]:HAKTO\n[inaba]:INABA\n", result)
|
138
|
+
end
|
139
|
+
|
140
|
+
def keys_common(argv)
|
141
|
+
@mnp.instance_variable_set(:@argv, argv)
|
142
|
+
dbm = @mnp.instance_variable_get(:@dbm)
|
143
|
+
add_some_pair(dbm)
|
144
|
+
|
145
|
+
result = capture_stdout {@mnp.run}
|
146
|
+
assert_equal("rabbit, hakto, inaba, \n", result)
|
147
|
+
end
|
148
|
+
|
149
|
+
def values_common(argv)
|
150
|
+
@mnp.instance_variable_set(:@argv, argv)
|
151
|
+
dbm = @mnp.instance_variable_get(:@dbm)
|
152
|
+
add_some_pair(dbm)
|
153
|
+
|
154
|
+
result = capture_stdout {@mnp.run}
|
155
|
+
assert_equal("RABBIT, HAKTO, INABA, \n", result)
|
156
|
+
end
|
157
|
+
|
158
|
+
def csv_common(argv)
|
159
|
+
@mnp.instance_variable_set(:@argv, argv)
|
160
|
+
dbm = @mnp.instance_variable_get(:@dbm)
|
161
|
+
add_some_pair(dbm)
|
162
|
+
|
163
|
+
result = capture_stdout {@mnp.run}
|
164
|
+
assert_equal("rabbit,RABBIT\r\nhakto,HAKTO\r\ninaba,INABA\r\n", result)
|
165
|
+
end
|
166
|
+
|
167
|
+
def add_some_pair(dbm)
|
168
|
+
dbm["rabbit"] = "RABBIT"
|
169
|
+
dbm["hakto"] = "HAKTO"
|
170
|
+
dbm["inaba"] = "INABA"
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
data/test/test.sdb.dir
ADDED
File without changes
|
data/test/test.sdb.pag
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inaba
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Moza USANE
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hakto
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ariete
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.0.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.1
|
46
|
+
description: ! "Inaba SDBM Manipulator\n=======================\n\n## Introduction\n\nInaba
|
47
|
+
SDBM Manipulator is a command line tool to manipulate SDBM database.\n\n## Operation
|
48
|
+
Environment\n\nWe checked good operation within following environment.\n\n- Linux(openSUSE
|
49
|
+
12.2)・Mac OS X 10.8.2\n- Ruby 1.9.3\n \n## Architectonics\n\n- **bin**\n - **inaba**
|
50
|
+
:: Executable script\n- **doc** :: Documents generated by rdoc\n- **lib**\n - **inaba**\n
|
51
|
+
\ - **manipulator.rb** :: Manipulator class\n- **Rakefile** :: Rakefile that is
|
52
|
+
used to generate gem file\n- **test**\n - **tb_manipulator.rb** :: Unit test of
|
53
|
+
Manipulator\n \n## Depended libraries\n\n- [Hakto SDBM Safe Wrapper](http://blog.quellencode.org/post/37391766923/ruby-hakto-safe-sdbm-wrapper)\n-
|
54
|
+
[Ariete STDOUT & STDERR Capture Module](http://blog.quellencode.org/post/37625422082/ariete-stdout-stderr-capture-module)\n\n##
|
55
|
+
Install\n\nDownload inaba-x.y.z.gem, then execute following command to install Inaba.\n\n`$
|
56
|
+
sudo gem install inaba-x.y.z.gem`\n\nOn the other hand, you can install from RubyGems.org
|
57
|
+
to use following command.\n\n`$ sudo gem install inaba`\n\n## Tutorial\n\n### Configuration
|
58
|
+
of environment variable\n\nSet file path of SDBM database to environment variable
|
59
|
+
named $INABA_DB. If target database file is named rabbit.sdb, use following command
|
60
|
+
in bash.\n\n`$ export INABA_DB=\"rabbit.sdb\"`\n\n### Add key value pair\n\nUse
|
61
|
+
**add** command to add a value to key.\n\n`$ inaba add rabbit RABBIT`\n\nUse **list**
|
62
|
+
command to show key value pairs.\n\n`$ inaba list`\n\n [rabbit]:RABBIT\n \nAdd
|
63
|
+
more pairs.\n\n`$ inaba add bunny BUNNY`\n\n`$ inaba add hare HARE`\n\n`$ inaba
|
64
|
+
list`\n\n [rabbit]:RABBIT\n [bunny]:BUNNY\n [hare]:HARE\n \nInaba can
|
65
|
+
output a pair list with CSV format.\n\n`$ inaba csv`\n\n rabbit,RABBIT\n bunny,BUNNY\n
|
66
|
+
\ hare,HARE\n \nAlso use **keys** command to list keys.\n\n`$ inaba keys`\n\n
|
67
|
+
\ rabbit, bunny, hare,\n \n**Values** command works listing values.\n\n`$ inaba
|
68
|
+
values`\n\n RABBIT, BUNNY, HARE,\n\nUse **del** command to delete key value command.\n\n`$
|
69
|
+
inaba del rabbit`\n\n`$ inaba list`\n\n [bunny]:BUNNY\n [hare]:HARE\n \n**Clear**
|
70
|
+
command removes all key value pairs.\n\n`$ inaba clear` \n\n## Commands reference\n\n|コマンド
|
71
|
+
\ |引数 |説明 |\n|----------|-------------|------------------------------------|\n|**add**
|
72
|
+
\ |*key* *value*|Add *value* to *key* |\n|**del** |*key* |Delete
|
73
|
+
a value associated with *key*|\n|**list** | |Output key value pairs
|
74
|
+
\ |\n|**keys** | |Output keys |\n|**values**|
|
75
|
+
\ |Output values |\n|**csv** | |Output
|
76
|
+
pairs with CSV format |\n|**help** | |Output command list |\n\n##
|
77
|
+
License\n\nInaba is distributed with MIT License. See the LICENSE file to read the
|
78
|
+
detail of license.\n\n## About Author\n\nMoza USANE \n[http://blog.quellencode.org/](http://blog.quellencode.org/
|
79
|
+
\"\") \nmozamimy@quellencode.org"
|
80
|
+
email: mozamimy@quellencode.org
|
81
|
+
executables:
|
82
|
+
- inaba
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- README.md
|
87
|
+
- CHANGELOG_jp.md
|
88
|
+
- Rakefile
|
89
|
+
- test.sdb.pag
|
90
|
+
- test/test.sdb.pag
|
91
|
+
- test/tb_manipulator.rb
|
92
|
+
- test/test.sdb.dir
|
93
|
+
- bin/inaba
|
94
|
+
- README_jp.md
|
95
|
+
- lib/inaba/manipulator.rb
|
96
|
+
- test.sdb.dir
|
97
|
+
- CHANGELOG.md
|
98
|
+
- LICENSE
|
99
|
+
homepage: http://quellencode.org/
|
100
|
+
licenses: []
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.9'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.23
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Inaba SDBM Manipulator is a command line tool to manipulate SDBM database.
|
123
|
+
test_files:
|
124
|
+
- test/tb_manipulator.rb
|