mushbomb 0.0.1

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Paul
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ I'll think of something
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "mushbomb"
8
+ gem.summary = %Q{A simple key-value store to a json file}
9
+ gem.description = %Q{mushbomb is a simple key-value store to a json file}
10
+ gem.email = "paulbjensen@gmail.com"
11
+ gem.homepage = "http://github.com/paulbjensen/mushbomb"
12
+ gem.authors = ["Paul Jensen"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "json", ">= 1.2.2"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "mushbomb #{version}"
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/mushbomb.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+
4
+ class Mushbomb
5
+
6
+ attr_accessor :file_path, :parsed_file
7
+
8
+ def initialize(file_path)
9
+ raise NoInputFileError if file_path.nil?
10
+ raise InvalidInputFileError if File.extname(file_path) != ".json"
11
+ @file_path = file_path
12
+ end
13
+
14
+ def parsed_file
15
+ JSON.parse File.read(file_path)
16
+ end
17
+
18
+ def get(key=nil)
19
+ return parsed_file if key.nil?
20
+ raise NoKeyFoundError unless parsed_file.has_key?(key)
21
+ parsed_file[key]
22
+ end
23
+
24
+ def set(key, value=nil)
25
+ raise InvalidInputError if key.nil?
26
+ old_file_data = parsed_file
27
+ file = File.open(file_path, 'w+')
28
+ file.write(old_file_data.merge!({key => value}).to_json)
29
+ file.close
30
+ end
31
+
32
+ def delete(key=nil)
33
+ if key.nil?
34
+ file = File.open(file_path, 'w+')
35
+ file.write({}.to_json)
36
+ else
37
+ raise NoKeyFoundError unless parsed_file.has_key?(key)
38
+ old_file_data = parsed_file
39
+ file = File.open(file_path, 'w+')
40
+ old_file_data.delete(key)
41
+ file.write(old_file_data.to_json)
42
+ end
43
+ file.close
44
+ end
45
+
46
+ end
47
+
48
+ class NoInputFileError < StandardError
49
+ def message
50
+ 'You need to intialize Mushbomb with a file'
51
+ end
52
+ end
53
+
54
+ class InvalidInputFileError < StandardError
55
+ def message
56
+ 'You need to intialize Mushbomb with a json file, ending with .json'
57
+ end
58
+ end
59
+
60
+ class NoKeyFoundError < StandardError
61
+ def message
62
+ 'No key found'
63
+ end
64
+ end
65
+
66
+ class InvalidInputError < StandardError
67
+ def message
68
+ 'You need to pass a key to this method'
69
+ end
70
+ end
data/mushbomb.gemspec ADDED
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mushbomb}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Paul Jensen"]
12
+ s.date = %q{2010-04-25}
13
+ s.description = %q{mushbomb is a simple key-value store to a json file}
14
+ s.email = %q{paulbjensen@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/mushbomb.rb",
27
+ "mushbomb.gemspec",
28
+ "spec/invalid_file.txt",
29
+ "spec/mushbomb_spec.rb",
30
+ "spec/sample_file.json",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/paulbjensen/mushbomb}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.6}
38
+ s.summary = %q{A simple key-value store to a json file}
39
+ s.test_files = [
40
+ "spec/mushbomb_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
50
+ s.add_development_dependency(%q<json>, [">= 1.2.2"])
51
+ else
52
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_dependency(%q<json>, [">= 1.2.2"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_dependency(%q<json>, [">= 1.2.2"])
58
+ end
59
+ end
60
+
File without changes
@@ -0,0 +1,69 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Mushbomb" do
4
+
5
+ before do
6
+ @file = File.open('spec/sample_file.json', 'w+')
7
+ @file.write({:name => 'bob', 'age' => 29}.to_json)
8
+ @file.close
9
+ @mushbomb = Mushbomb.new('spec/sample_file.json')
10
+ end
11
+
12
+ describe "initialize" do
13
+ it "should raise an error if it is not initialized with a file" do
14
+ lambda{Mushbomb.new}.should raise_error
15
+ end
16
+
17
+ it "should raise an error if the file is not a JSON file" do
18
+ lambda{Mushbomb.new('spec/invalid_file.txt')}.should raise_error(InvalidInputFileError, 'You need to intialize Mushbomb with a json file, ending with .json')
19
+ end
20
+ end
21
+
22
+ describe "#get" do
23
+ it "should return all of the json data, if no key is passed in" do
24
+ @mushbomb.get.should == {"name" => "bob", "age" => 29}
25
+ end
26
+
27
+ it "should return the value of a key, if a key is passed in" do
28
+ @mushbomb.get("name").should == "bob"
29
+ @mushbomb.get("age").should == 29
30
+ end
31
+
32
+ it "should raise an error if the key is not found" do
33
+ lambda{@mushbomb.get("msg")}.should raise_error(NoKeyFoundError, 'No key found')
34
+ end
35
+
36
+ end
37
+
38
+ describe "#set" do
39
+
40
+ it "should raise an error if no key is passed to the method" do
41
+ lambda{@mushbomb.set(nil)}.should raise_error(InvalidInputError, 'You need to pass a key to this method')
42
+ end
43
+
44
+ it "should set the json key's value to the value" do
45
+ @mushbomb.set("msg", "hi")
46
+ @mushbomb.get("msg").should == "hi"
47
+ end
48
+ end
49
+
50
+ describe "#delete" do
51
+
52
+ it "should raise an error if the key is not found" do
53
+ lambda{@mushbomb.delete("msg")}.should raise_error(NoKeyFoundError, 'No key found')
54
+ end
55
+
56
+ it "should remove the key if a key is passed in" do
57
+ @mushbomb.delete("age")
58
+ lambda{@mushbomb.get("age")}.should raise_error(NoKeyFoundError, 'No key found')
59
+ end
60
+
61
+ it "should remove the whole key value store set if no key is passed in" do
62
+ @mushbomb.delete
63
+ @mushbomb.parsed_file.should == {}
64
+ @mushbomb.get.should == {}
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1 @@
1
+ {}
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'mushbomb'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mushbomb
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Paul Jensen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-25 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: json
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 2
45
+ version: 1.2.2
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: mushbomb is a simple key-value store to a json file
49
+ email: paulbjensen@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.md
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - VERSION
64
+ - lib/mushbomb.rb
65
+ - mushbomb.gemspec
66
+ - spec/invalid_file.txt
67
+ - spec/mushbomb_spec.rb
68
+ - spec/sample_file.json
69
+ - spec/spec.opts
70
+ - spec/spec_helper.rb
71
+ has_rdoc: true
72
+ homepage: http://github.com/paulbjensen/mushbomb
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --charset=UTF-8
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.6
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: A simple key-value store to a json file
101
+ test_files:
102
+ - spec/mushbomb_spec.rb
103
+ - spec/spec_helper.rb