peanut 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -7,15 +7,15 @@ Peanut is a key/value store kind of similar to BOOM. Instead of managing lists,
7
7
  Usage is pretty straight forward:
8
8
 
9
9
  peanut help show a quick help overview
10
- peanut <key> <value> adds the key/value pair to your bucket
11
- peanut rm <key> removes the key/value pair where key matches
12
- peanut <key> copies the value of key to your clipboard
13
- peanut <key> v adds the value of your clipboard to key
10
+ peanut <key> <value> adds the key/value pair to your bucket
11
+ peanut rm <key> removes the key/value pair where key matches
12
+ peanut <key> copies the value of key to your clipboard
13
+ peanut <key> v adds the value of your clipboard to key
14
14
  peanut list shows everything currently in your bucket
15
15
 
16
16
  == Installation
17
17
 
18
- gem install zap
18
+ gem install peanut
19
19
 
20
20
  == Requirements
21
21
 
@@ -9,7 +9,7 @@ module Peanut
9
9
  "pbcopy"
10
10
  end
11
11
 
12
- `echo #{string} | tr -d "\n" | #{cmd}`
12
+ system("echo -n #{string} | #{cmd}")
13
13
  end
14
14
 
15
15
  def paste
@@ -21,4 +21,4 @@ module Peanut
21
21
  end
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -9,7 +9,7 @@ module Peanut
9
9
  return help unless key
10
10
  return send key, value if is_arged_keyword?(key)
11
11
  return send key if is_keyword?(key)
12
- return save key, value if key && value
12
+ return save! key, value if key && value
13
13
  return get key
14
14
  end
15
15
 
@@ -20,14 +20,14 @@ module Peanut
20
20
  end
21
21
 
22
22
  def list
23
- puts "Your peanut bucket: \n#{'-' * 20}"
23
+ Peanut::output "Your peanut bucket: \n#{'-' * 20}"
24
24
  store.each_pair do |key, value|
25
- puts "#{key}: #{value}"
25
+ Peanut::output "#{key}: #{value}"
26
26
  end
27
27
  end
28
28
 
29
29
  def help
30
- puts %{
30
+ Peanut::output %{
31
31
  #{executable} <key> <value> sets the "key" value to "value"
32
32
  #{executable} <key> copies the value for "key" to the clipboard
33
33
  #{executable} rm <foo> removes the key/value pair where the key = foo
@@ -40,17 +40,17 @@ module Peanut
40
40
  def get(key)
41
41
  if val = store[key]
42
42
  Clipboard.copy(val)
43
- puts "Copied '#{val}' to the clipboard!"
43
+ Peanut::output "Copied '#{val}' to the clipboard!"
44
44
  else
45
- puts "No value stored with key '#{key}'"
45
+ Peanut::output "No value stored with key '#{key}'"
46
46
  end
47
47
  end
48
48
 
49
- def save(key, val)
49
+ def save!(key, val)
50
50
  val = Clipboard.paste if val == 'v'
51
- store[key.intern] = val
52
- store.save
53
- puts "Saved '#{val}' as '#{key}'"
51
+ store[key.to_sym] = val
52
+ store.save!
53
+ Peanut::output "Saved '#{val}' as '#{key}'"
54
54
  end
55
55
 
56
56
  def executable
@@ -59,8 +59,8 @@ module Peanut
59
59
 
60
60
  def rm(key)
61
61
  store[key] = nil
62
- store.save
63
- puts "Deleted the value with the key '#{key}'"
62
+ store.save!
63
+ Peanut::output "Deleted the value with the key '#{key}'"
64
64
  end
65
65
 
66
66
  def is_keyword?(word)
data/lib/peanut/store.rb CHANGED
@@ -24,7 +24,7 @@ module Peanut
24
24
  return store[key]
25
25
  end
26
26
 
27
- def save
27
+ def save!
28
28
  File.open(file, 'w') { |f| f.write(to_json) }
29
29
  end
30
30
 
@@ -1,3 +1,3 @@
1
1
  module Peanut
2
- VERSION = "0.1"
3
- end
2
+ VERSION = "0.2"
3
+ end
data/lib/peanut.rb CHANGED
@@ -6,5 +6,9 @@ module Peanut
6
6
  require 'peanut/store'
7
7
  require 'peanut/command'
8
8
 
9
+ # Makes for easier testing if I/O
10
+ def self.output(string)
11
+ puts string
12
+ end
9
13
  end
10
14
 
data/peanut-0.1.gem ADDED
Binary file
data/test/helper.rb CHANGED
@@ -13,6 +13,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
13
 
14
14
  require 'peanut'
15
15
 
16
+
16
17
  def peanut_json(name)
17
18
  #Peanut::Store.any_instance.stubs(:json_file).
18
19
  #returns("test/examples/#{name}.json")
data/test/test_command.rb CHANGED
@@ -3,13 +3,20 @@ require 'helper'
3
3
  # Dont Mind this
4
4
  # Just a little ghetto monkey patching
5
5
  # It lets us grab the STD I/O, and test it
6
- class Object
7
- class << self
8
- attr_accessor :output
9
- def puts(s)
10
- @output = s
6
+ module Peanut
7
+
8
+ attr_accessor :outputted_string
9
+ def self.output(string)
10
+ @outputted_string << string
11
+ end
12
+
13
+ def self.before_output
14
+ @outputted_string = ""
15
+ end
16
+
17
+ def self.captured_output
18
+ @outputted_string
11
19
  end
12
- end
13
20
  end
14
21
 
15
22
  class TestCommand < Test::Unit::TestCase
@@ -20,12 +27,22 @@ class TestCommand < Test::Unit::TestCase
20
27
 
21
28
  def command(cmd)
22
29
  cmd = cmd.split(' ') if cmd
23
- Object.puts Peanut::Command.run(*cmd)
30
+ Peanut::before_output
31
+ Peanut::Command.run(*cmd)
32
+ Peanut::captured_output
24
33
  end
25
34
 
26
35
  def test_adding_entry
27
36
  assert_equal "Saved 'testing' as 'test'", command("test testing")
28
37
  end
29
38
 
39
+ def test_removing_entry
40
+ assert_equal "Deleted the value with the key 'test'", command("rm test")
41
+ end
42
+
43
+ def test_list
44
+ assert_equal "Your peanut bucket: \n--------------------test: testingtest: testing", command("list")
45
+ end
46
+
30
47
  end
31
48
 
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peanut
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- version: "0.1"
8
+ - 2
9
+ version: "0.2"
10
10
  platform: ruby
11
11
  authors:
12
12
  - the_gastropod
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-11 00:00:00 -05:00
18
+ date: 2011-01-21 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,7 @@ files:
49
49
  - lib/peanut/command.rb
50
50
  - lib/peanut/store.rb
51
51
  - lib/peanut/version.rb
52
+ - peanut-0.1.gem
52
53
  - peanut.gemspec
53
54
  - test/examples/test.json
54
55
  - test/helper.rb