whats 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ whats
2
+ =====
3
+ whats is a persistent hash to use as a memo in your terminal.
4
+
5
+ * * *
6
+ Installation
7
+ ------------
8
+
9
+ gem install whats
10
+
11
+ * * *
12
+ Usage
13
+ -----
14
+ Add an entry
15
+
16
+ whats -a myIP -m "192.168.0.1"
17
+
18
+ Or
19
+
20
+ whats -add myIP
21
+
22
+ Retrieve an entry
23
+
24
+ whats myIP
25
+ # 192.168.0.1
26
+
27
+ List all entries
28
+
29
+ whats -l
30
+
31
+ Delete an entry
32
+
33
+ whats -d myIP
34
+
35
+ Execute (for shell script entries)
36
+
37
+ whats -a files -m "ls -l"
38
+ whats -e files
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.test_files = FileList['test/*_test.rb']
5
+ t.verbose = true
6
+ end
7
+
8
+ task "run" do
9
+ puts `ruby -I lib bin/memo -a Mika -m "C'est moi"`
10
+ end
11
+
data/bin/whats ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'whats'
4
+
5
+ runner = Whats::Runner.new ARGV
6
+ runner.run
@@ -0,0 +1,46 @@
1
+ require 'optparse'
2
+
3
+ module Whats
4
+ class Option
5
+ attr_accessor :choice, :key, :message
6
+
7
+ def initialize args
8
+ @args = args
9
+ end
10
+
11
+ def parse
12
+ if @args[0][0] == "-"
13
+ OptionParser.new do |opts|
14
+ opts.banner = "Usage: whats [options]"
15
+
16
+ opts.on("-a", "--add VAL", "Adds an entry") do |val|
17
+ @choice = :add
18
+ @key = val
19
+ end
20
+
21
+ opts.on("-m", "--message M", String, "Memo's message") do |val|
22
+ @message = val
23
+ end
24
+
25
+ opts.on("-d", "--delete K", String, "Delete a key") do |val|
26
+ @choice = :delete
27
+ @key = val
28
+ end
29
+
30
+ opts.on("-l", "--list", "List all memo keys") do
31
+ @choice = :list
32
+ end
33
+
34
+ opts.on("-e", "--execute K", String, "Executes the given key") do |val|
35
+ @choice = :execute
36
+ @key = val
37
+ end
38
+
39
+ end.parse! @args
40
+ else
41
+ @choice = :lookup
42
+ @key = @args[0]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,31 @@
1
+ module Whats
2
+ class Runner
3
+ def initialize args
4
+ @options = Option.new args
5
+ @memo = Whats.new
6
+ end
7
+
8
+ def run
9
+ @options.parse
10
+ case @options.choice
11
+ when :add
12
+ unless @options.message
13
+ File.open(TMP_FILE, 'w').close
14
+ system "vim #{TMP_FILE}"
15
+ @options.message = File.read TMP_FILE
16
+ end
17
+ @memo[@options.key] = @options.message
18
+ @memo.save
19
+ when :delete
20
+ @memo.delete @options.key
21
+ @memo.save
22
+ when :list
23
+ @memo.each {|k, v| puts k}
24
+ when :execute
25
+ exec "#{@memo[@options.key]}"
26
+ when :lookup
27
+ puts @memo[@options.key]
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/whats.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'yaml'
2
+ require 'whats/option'
3
+ require 'whats/runner'
4
+
5
+ module Whats
6
+ FOLDER = Dir.home+'/.whats'
7
+ FILE_PATH = FOLDER+'/whats'
8
+ TMP_FILE = FOLDER+'/tmp'
9
+
10
+ class Whats < Hash
11
+
12
+ def initialize
13
+ if File.exists? FILE_PATH
14
+ entries = YAML::load(File.read FILE_PATH)
15
+ self.replace entries unless entries.nil?
16
+ end
17
+ end
18
+
19
+ def save
20
+ Dir.mkdir FOLDER unless Dir.exists? FOLDER
21
+ f = File.open(FILE_PATH, 'w')
22
+ f << YAML::dump(self)
23
+ f.close
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require 'whats'
4
+
5
+ class OptionTest < Test::Unit::TestCase
6
+
7
+ context "Option" do
8
+
9
+ should "handle: -a Key -m Message" do
10
+ opt = Whats::Option.new %w(-a Key -m Message)
11
+ opt.parse
12
+ assert_equal :add, opt.choice
13
+ assert_equal "Key", opt.key
14
+ assert_equal "Message", opt.message
15
+ end
16
+
17
+ should "handle: -d Key" do
18
+ opt = Whats::Option.new %w(-d Key)
19
+ opt.parse
20
+ assert_equal :delete, opt.choice
21
+ assert_equal "Key", opt.key
22
+ end
23
+
24
+ should "handle: -l" do
25
+ opt = Whats::Option.new %w(-l)
26
+ opt.parse
27
+ assert_equal :list, opt.choice
28
+ end
29
+
30
+ should "handle: -e Key" do
31
+ opt = Whats::Option.new %w(-e Key)
32
+ opt.parse
33
+ assert_equal :execute, opt.choice
34
+ assert_equal "Key", opt.key
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require 'whats'
4
+
5
+ class WhatsTest < Test::Unit::TestCase
6
+
7
+ context "The memo should" do
8
+
9
+ setup do
10
+ @m = Whats::Whats.new
11
+ end
12
+
13
+ end
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whats
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Michael Sokol
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-02-22 00:00:00 -05:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description:
21
+ email: mikaa123@gmail.com
22
+ executables:
23
+ - whats
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - Rakefile
30
+ - README.md
31
+ - lib/whats.rb
32
+ - lib/whats/option.rb
33
+ - lib/whats/runner.rb
34
+ - bin/whats
35
+ - test/whats_test.rb
36
+ - test/option_test.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/mikaa123/whats
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: A persistant hash to use as a memo in your terminal
69
+ test_files:
70
+ - test/whats_test.rb
71
+ - test/option_test.rb