scottburton11-tokyomapper 0.1.0 → 0.1.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/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
+ *.tdb
data/README.rdoc CHANGED
@@ -1,27 +1,29 @@
1
1
  = tokyomapper
2
2
 
3
- TokyoMapper is an extremely lightweight ORM for TokyoCabinet. It stuffs your instance variables into a .tdb row, and loads them into new instances on #find. Nothing fancy!
3
+ TokyoMapper is an extremely lightweight ORM for TokyoCabinet.
4
+
5
+ It stuffs your instance variables into a .tdb row, and loads them into new instances on #find. Nothing fancy!
4
6
 
5
7
  == Example
6
8
 
7
9
 
8
- class Elephant
9
- include TokyoMapper
10
+ class Elephant
11
+ include TokyoMapper
10
12
 
11
- attr_accessor :trunk_length
13
+ attr_accessor :trunk_length
12
14
 
13
- def initialize(params)
14
- @trunk_length = params[:trunk_length]
15
- end
16
- end
15
+ def initialize(params)
16
+ @trunk_length = params[:trunk_length]
17
+ end
18
+ end
17
19
 
18
- elephant = Elephant.new(:trunk_length => "Super Long")
19
- elephant.save
20
- #=> true
21
- # creates elephant.tdb unless it exists
20
+ elephant = Elephant.new(:trunk_length => "Super Long")
21
+ elephant.save
22
+ #=> true
23
+ # creates elephant.tdb unless it exists
22
24
 
23
- Elephant.all
24
- #=> [#<Elephant:0x18b8100 @trunk_length="Super Long"]
25
+ Elephant.all
26
+ #=> [#<Elephant:0x18b8100 @trunk_length="Super Long"]
25
27
 
26
28
 
27
29
 
@@ -32,8 +34,6 @@ Elephant.all
32
34
  * Add tests for it. This is important so I don't break it in a
33
35
  future version unintentionally.
34
36
  * Commit, do not mess with rakefile, version, or history.
35
- (if you want to have your own version, that is fine but
36
- bump version in a commit by itself I can ignore when I pull)
37
37
  * Send me a pull request. Bonus points for topic branches.
38
38
 
39
39
  == Copyright
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'tokyomapper'
3
+
4
+ require 'spec/expectations'
5
+ require 'features/env/feature_helpers'
6
+
7
+ Before do
8
+
9
+ end
10
+
11
+
12
+ After do
13
+ clean_up_databases
14
+ end
@@ -0,0 +1,8 @@
1
+ module FeatureHelpers
2
+ def clean_up_databases
3
+ # Dir.glob("#{__FILE__}/../../*.tdb").each {|file| File.delete(file)}
4
+ Dir.glob("./*.tdb").each {|file| File.delete(file)}
5
+ end
6
+ end
7
+
8
+ World(FeatureHelpers)
@@ -0,0 +1,13 @@
1
+ Feature: Save a row to the database
2
+ In order to persist an instance of my class
3
+ As a user
4
+ I want to call #save on my class name
5
+
6
+ Background:
7
+ Given I have included TokyoMapper in my class
8
+
9
+ Scenario: Call #save
10
+ Given I have an instance of my class with some data
11
+ When I call save on it
12
+ Then it should get saved to the database
13
+
@@ -0,0 +1,25 @@
1
+ Given /^I have included TokyoMapper in my class$/ do
2
+
3
+ class MyClass
4
+ include TokyoMapper
5
+ attr_accessor :attr1
6
+ attr_accessor :attr2
7
+ def initialize(attrs)
8
+ @attr1 = attrs[:attr1]
9
+ @attr2 = attrs[:attr2]
10
+ end
11
+ end
12
+
13
+ end
14
+
15
+ Given /^I have an instance of my class with some data$/ do
16
+ @my_instance = MyClass.new(:attr1 => "Data1", :attr2 => "Data2")
17
+ end
18
+
19
+ When /^I call save on it$/ do
20
+ @my_instance.save
21
+ end
22
+
23
+ Then /^it should get saved to the database$/ do
24
+ MyClass.all.size.should be(1)
25
+ end
data/lib/tokyomapper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'tokyocabinet'
2
+
1
3
  module TokyoMapper
2
4
  include TokyoCabinet
3
5
 
@@ -62,7 +64,17 @@ module TokyoMapper
62
64
  module InstanceMethods
63
65
 
64
66
  def save
65
- self.class.connection { |db| db.put(db.genuid, self.class.stringify_keys(self.instance_values))}
67
+ self.class.connection do |db|
68
+ db.put(db.genuid, self.class.stringify_keys(self.instance_values))
69
+ end
70
+ end
71
+
72
+ def instance_values
73
+ instance_values_hash = Hash.new
74
+ instance_variables.each do |key|
75
+ instance_values_hash[key.instance_variable_name] = self.send(key.instance_variable_name.to_sym)
76
+ end
77
+ return instance_values_hash
66
78
  end
67
79
 
68
80
  end
@@ -72,4 +84,37 @@ module TokyoMapper
72
84
  receiver.send :include, InstanceMethods
73
85
  end
74
86
 
87
+ end
88
+
89
+ class String
90
+ def pluralize
91
+ case self
92
+ when %r|s$|
93
+ self << "es"
94
+ when %r|sh$|
95
+ self << "es"
96
+ when %r|e$|
97
+ self << "s"
98
+ when %r|o$|
99
+ self << "es"
100
+ when %r|[aeiou]+y$|
101
+ self << "s"
102
+ when %r|[^aeiou]+y$|
103
+ self.chomp("y") << "ies"
104
+ else
105
+ self << "s"
106
+ end
107
+ end
108
+
109
+ def instance_variable_name
110
+ case self
111
+ when %r|^:@|
112
+ self.delete(":@")
113
+ when %r|^@|
114
+ self.delete("@")
115
+ else
116
+ self
117
+ end
118
+ end
119
+
75
120
  end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'tokyomapper'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
@@ -0,0 +1,59 @@
1
+ require File.join(File.dirname(__FILE__),'spec_helper')
2
+
3
+ describe String, "pluralization" do
4
+
5
+ it "should add an 's' at the end of strings ending in 'e'" do
6
+ string = "Quiche"
7
+ string.pluralize.should eql("Quiches")
8
+ end
9
+
10
+ it "should add an 'es' to the end of strings ending in 'o'" do
11
+ string = "Hero"
12
+ string.pluralize.should eql("Heroes")
13
+ end
14
+
15
+ it "should add an 'ies' to the end of strings ending in a consonant and 'y'" do
16
+ string = "Cherry"
17
+ string.pluralize.should eql("Cherries")
18
+ end
19
+
20
+ it "should add an 's' to the end of strings ending in a vowel and 'y'" do
21
+ string = "Day"
22
+ string.pluralize.should eql("Days")
23
+ end
24
+
25
+ it "should add an 's' at the end of most strings ending in consonants" do
26
+ string = "Kitten"
27
+ string.pluralize.should eql("Kittens")
28
+ end
29
+
30
+ it "should add an 'es' at the end of strings ending in 's'" do
31
+ string = "Kiss"
32
+ string.pluralize.should eql("Kisses")
33
+ end
34
+
35
+ it "should add an 'es' to the end of strings with a sibilant 'sh'" do
36
+ string = "Dish"
37
+ string.pluralize.should eql("Dishes")
38
+ end
39
+
40
+ end
41
+
42
+ describe String, "instance_variable_name method" do
43
+
44
+ it "should remove the @ symbol" do
45
+ name = "@bar"
46
+ name.instance_variable_name.should eql("bar")
47
+ end
48
+
49
+ it "should remove any :@ symbol combination" do
50
+ name = ":@bar"
51
+ name.instance_variable_name.should eql("bar")
52
+ end
53
+
54
+ it "shouldn't affect strings with just a colon :" do
55
+ name = ":not_a_symbol"
56
+ name.instance_variable_name.should eql(name)
57
+ end
58
+
59
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__),'spec_helper')
2
+
3
+ module TestSetup
4
+ class TestClass
5
+ include TokyoMapper
6
+ attr_accessor :attr1
7
+ attr_accessor :attr2
8
+ def initialize(attrs = {:attr1 => "attribute 1 value", :attr2 => "attribute 2 value"})
9
+ @attr1 = attrs[:attr1]
10
+ @attr2 = attrs[:attr2]
11
+ end
12
+ end
13
+ end
14
+
15
+ describe TokyoMapper::InstanceMethods, "instance_values method" do
16
+ include TestSetup
17
+
18
+ before(:each) do
19
+ @test = TestSetup::TestClass.new
20
+ end
21
+
22
+ it "returns a hash of instance variable names and their values" do
23
+ @test.instance_values.should == {"attr1" => "attribute 1 value", "attr2" => "attribute 2 value"}
24
+ end
25
+ end
26
+
27
+
28
+ describe TokyoMapper, "save a record" do
29
+ include TestSetup
30
+
31
+ before(:each) do
32
+ @test = TestSetup::TestClass.new(:attr1 => "Test 1", :attr2 => "Test 2")
33
+ TestSetup::TestClass.db.stub!(:open).and_return(true)
34
+ TestSetup::TestClass.db.stub!(:close).and_return(true)
35
+ TestSetup::TestClass.db.stub!(:genuid).and_return("1")
36
+ TestSetup::TestClass.db.should_receive(:put).with("1", {"attr1" => "Test 1", "attr2" => "Test 2"}).and_return(true)
37
+ end
38
+
39
+ it "should be true" do
40
+ @test.save.should be(true)
41
+ end
42
+ end
@@ -0,0 +1,58 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{tokyomapper}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Scott Burton"]
9
+ s.date = %q{2009-08-17}
10
+ s.description = %q{TokyoMapper is a simple ORM for TokyoCabinet. Just 'include TokyoMapper' in your class and go! Requires the tokyocabinet-ruby bindings and the tokyocabinet package.}
11
+ s.email = %q{scottburton11@gmail.com}
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "README.rdoc"
15
+ ]
16
+ s.files = [
17
+ ".document",
18
+ ".gitignore",
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "features/env/env.rb",
24
+ "features/env/feature_helpers.rb",
25
+ "features/save_row.feature",
26
+ "features/step_definitions/tokyo_mapper_steps.rb",
27
+ "lib/tokyomapper.rb",
28
+ "spec/spec.opts",
29
+ "spec/spec_helper.rb",
30
+ "spec/string_extensions_spec.rb",
31
+ "spec/tokyo_mapper_spec.rb",
32
+ "test/test_helper.rb",
33
+ "test/tokyomapper_test.rb",
34
+ "tokyomapper.gemspec"
35
+ ]
36
+ s.homepage = %q{http://github.com/scottburton11/tokyomapper}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{A succinct ORM for TokyoCabinet}
41
+ s.test_files = [
42
+ "spec/spec_helper.rb",
43
+ "spec/string_extensions_spec.rb",
44
+ "spec/tokyo_mapper_spec.rb",
45
+ "test/test_helper.rb",
46
+ "test/tokyomapper_test.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ else
55
+ end
56
+ else
57
+ end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scottburton11-tokyomapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Burton
@@ -29,9 +29,18 @@ files:
29
29
  - README.rdoc
30
30
  - Rakefile
31
31
  - VERSION
32
+ - features/env/env.rb
33
+ - features/env/feature_helpers.rb
34
+ - features/save_row.feature
35
+ - features/step_definitions/tokyo_mapper_steps.rb
32
36
  - lib/tokyomapper.rb
37
+ - spec/spec.opts
38
+ - spec/spec_helper.rb
39
+ - spec/string_extensions_spec.rb
40
+ - spec/tokyo_mapper_spec.rb
33
41
  - test/test_helper.rb
34
42
  - test/tokyomapper_test.rb
43
+ - tokyomapper.gemspec
35
44
  has_rdoc: false
36
45
  homepage: http://github.com/scottburton11/tokyomapper
37
46
  licenses:
@@ -60,5 +69,8 @@ signing_key:
60
69
  specification_version: 3
61
70
  summary: A succinct ORM for TokyoCabinet
62
71
  test_files:
72
+ - spec/spec_helper.rb
73
+ - spec/string_extensions_spec.rb
74
+ - spec/tokyo_mapper_spec.rb
63
75
  - test/test_helper.rb
64
76
  - test/tokyomapper_test.rb