pit 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +10 -0
- data/README +4 -1
- data/Rakefile +1 -6
- data/bin/pit +0 -0
- data/lib/pit.rb +18 -1
- data/test/pit_test.rb +53 -3
- metadata +3 -3
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -49,8 +49,11 @@ ruby lib.
|
|
49
49
|
"nickname" => "default value"
|
50
50
|
})
|
51
51
|
|
52
|
+
Pit.get open $EDITOR with `require` hash if the setting does not have
|
53
|
+
required keys.
|
54
|
+
|
52
55
|
== Copyright
|
53
56
|
|
54
57
|
Author:: cho45 <cho45@lowreal.net>
|
55
58
|
Copyright:: Copyright (c) 2008 cho45
|
56
|
-
License::
|
59
|
+
License:: Ruby's
|
data/Rakefile
CHANGED
@@ -118,16 +118,11 @@ Rake::ShipitTask.new do |s|
|
|
118
118
|
system("svn", "up")
|
119
119
|
}.and {}
|
120
120
|
s.Task :rubyforge
|
121
|
-
s.Step.new {
|
122
|
-
raise "svn2cl.sh is not found" unless system("svn2cl.sh", "--version")
|
123
|
-
}.and {
|
124
|
-
system("svn2cl.sh --break-before-msg=2 --group-by-day --include-rev --separate-daylogs")
|
125
|
-
}
|
126
121
|
s.ChangeVersion "lib/pit.rb", "VERSION"
|
127
122
|
s.Commit
|
128
123
|
s.Task :clean, :package
|
129
124
|
s.RubyForge
|
130
|
-
|
125
|
+
s.Tag
|
131
126
|
s.Twitter
|
132
127
|
end
|
133
128
|
|
data/bin/pit
CHANGED
File without changes
|
data/lib/pit.rb
CHANGED
@@ -4,16 +4,24 @@ require "pathname"
|
|
4
4
|
require "tempfile"
|
5
5
|
|
6
6
|
module Pit
|
7
|
-
VERSION = "0.0.
|
7
|
+
VERSION = "0.0.6"
|
8
8
|
Directory = Pathname.new("~/.pit").expand_path
|
9
9
|
@@config = Directory + "pit.yaml"
|
10
10
|
@@profile = Directory + "default.yaml"
|
11
11
|
|
12
|
+
# Set _name_ setting to current profile.
|
13
|
+
# If not _opts_ specified, this opens $EDITOR with current profile setting.
|
14
|
+
# If `data` specified, this just sets it to current profile.
|
15
|
+
# If `config` specified, this opens $EDITOR with merged hash with specified hash and
|
16
|
+
# current profile.
|
12
17
|
def self.set(name, opts={})
|
13
18
|
profile = self.load
|
14
19
|
if opts.key?(:data)
|
15
20
|
result = opts[:data]
|
16
21
|
else
|
22
|
+
if ENV["EDITOR"].nil? || !$stdout.tty?
|
23
|
+
return {}
|
24
|
+
end
|
17
25
|
c = (opts[:config] || self.get(name)).to_yaml
|
18
26
|
t = Tempfile.new("pit")
|
19
27
|
t << c
|
@@ -32,6 +40,9 @@ module Pit
|
|
32
40
|
result
|
33
41
|
end
|
34
42
|
|
43
|
+
# Get _name_ setting from current profile.
|
44
|
+
# If not _opts_ specified, this just returns setting from current profile.
|
45
|
+
# If _require_ specified, check keys on setting and open $EDITOR.
|
35
46
|
def self.get(name, opts={})
|
36
47
|
ret = self.load[name] || {}
|
37
48
|
if opts[:require]
|
@@ -43,15 +54,21 @@ module Pit
|
|
43
54
|
ret || {"username"=>"", "password"=>""}
|
44
55
|
end
|
45
56
|
|
57
|
+
# Switch to current profile to _name_.
|
58
|
+
# Profile is set of settings. You can switch some settings using profile.
|
46
59
|
def self.switch(name, opts={})
|
47
60
|
@@profile = Directory + "#{name}.yaml"
|
48
61
|
config = self.config
|
62
|
+
ret = config["profile"]
|
49
63
|
config["profile"] = name
|
50
64
|
@@config.open("w") {|f| f << config.to_yaml }
|
65
|
+
ret
|
51
66
|
end
|
52
67
|
|
68
|
+
protected
|
53
69
|
def self.load
|
54
70
|
Directory.mkpath unless Directory.exist?
|
71
|
+
Directory.chmod 0700
|
55
72
|
unless @@config.exist?
|
56
73
|
@@config.open("w") {|f| f << {"profile"=>"default"}.to_yaml }
|
57
74
|
@@config.chmod(0600)
|
data/test/pit_test.rb
CHANGED
@@ -5,8 +5,7 @@ class Pathname
|
|
5
5
|
@@tempname_number = 0
|
6
6
|
def self.tempname(base=$0, dir=Dir.tmpdir)
|
7
7
|
@@tempname_number += 1
|
8
|
-
|
9
|
-
path = new(name)
|
8
|
+
path = new(dir) + "#{File.basename(base)}.#{$$}.#{@@tempname_number}"
|
10
9
|
at_exit do
|
11
10
|
path.rmtree if path.exist?
|
12
11
|
end
|
@@ -42,13 +41,64 @@ class PitTest < Test::Unit::TestCase
|
|
42
41
|
assert_equal "foo", Pit.set("test", :data => {"username"=>"foo","password"=>"bar"})["username"]
|
43
42
|
end
|
44
43
|
|
44
|
+
def test_editor
|
45
|
+
ENV["EDITOR"] = nil
|
46
|
+
assert_nothing_raised("When editor is not set.") do
|
47
|
+
Pit.set("test")
|
48
|
+
end
|
49
|
+
|
50
|
+
tst = Pathname.tempname
|
51
|
+
exe = Pathname.tempname
|
52
|
+
exe.open("w") do |f|
|
53
|
+
f.puts <<-EOF.gsub(/^\t+/, "")
|
54
|
+
#!/usr/bin/env ruby
|
55
|
+
|
56
|
+
File.open(ENV["TEST_FILE"], "w") do |f|
|
57
|
+
f.puts ARGF.read
|
58
|
+
end
|
59
|
+
EOF
|
60
|
+
end
|
61
|
+
exe.chmod(0700)
|
62
|
+
|
63
|
+
ENV["TEST_FILE"] = tst.to_s
|
64
|
+
ENV["EDITOR"] = exe.to_s
|
65
|
+
Pit.set("test")
|
66
|
+
|
67
|
+
assert_nothing_raised do
|
68
|
+
assert_equal({}, YAML.load_file(tst.to_s))
|
69
|
+
end
|
70
|
+
|
71
|
+
data = {
|
72
|
+
"foo" => "0101",
|
73
|
+
"bar" => "0202",
|
74
|
+
}
|
75
|
+
|
76
|
+
Pit.set("test", :data => data)
|
77
|
+
Pit.set("test")
|
78
|
+
|
79
|
+
assert_nothing_raised do
|
80
|
+
assert_equal(data, YAML.load_file(tst.to_s))
|
81
|
+
end
|
82
|
+
|
83
|
+
# clear
|
84
|
+
Pit.set("test", :data => {})
|
85
|
+
tst.open("w") {|f| }
|
86
|
+
|
87
|
+
Pit.get("test", :require => data)
|
88
|
+
|
89
|
+
assert_nothing_raised do
|
90
|
+
assert_equal(data, YAML.load_file(tst.to_s))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
45
94
|
def test_switch
|
46
95
|
Pit.switch("default")
|
47
96
|
Pit.set("test", :data => {"username"=>"foo","password"=>"bar"})
|
48
97
|
assert_equal "foo", Pit.get("test")["username"]
|
49
98
|
assert_equal "bar", Pit.get("test")["password"]
|
50
99
|
|
51
|
-
Pit.switch("profile2")
|
100
|
+
r = Pit.switch("profile2")
|
101
|
+
assert_equal "default", r
|
52
102
|
assert_equal "profile2", Pit.config["profile"]
|
53
103
|
Pit.set("test", :data => {"username"=>"foo2","password"=>"bar2"})
|
54
104
|
assert_equal "foo2", Pit.get("test")["username"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cho45
|
@@ -9,7 +9,7 @@ autorequire: pit
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-15 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
requirements: []
|
64
64
|
|
65
65
|
rubyforge_project: lowreal
|
66
|
-
rubygems_version: 1.0
|
66
|
+
rubygems_version: 1.2.0
|
67
67
|
signing_key:
|
68
68
|
specification_version: 2
|
69
69
|
summary: "pit: account management tool"
|