redmiso 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -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 Howard Yeh
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.
@@ -0,0 +1,29 @@
1
+ = redmiso
2
+
3
+ Basing models on different redis servers
4
+
5
+ # # Redmiso.default(*arg)
6
+
7
+ # class Foo < Redmiso# == Redmiso.default
8
+
9
+ # end
10
+
11
+ # class Foo < Redmiso(:host => "127.0.0.1") #
12
+ # end
13
+
14
+
15
+
16
+ == Note on Patches/Pull Requests
17
+
18
+ * Fork the project.
19
+ * Make your feature addition or bug fix.
20
+ * Add tests for it. This is important so I don't break it in a
21
+ future version unintentionally.
22
+ * Commit, do not mess with rakefile, version, or history.
23
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
24
+ * Send me a pull request. Bonus points for topic branches.
25
+
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2010 Howard Yeh. See LICENSE for details.
@@ -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 = "redmiso"
8
+ gem.summary = %Q{Object Mapping for Redis}
9
+ gem.description = %Q{Neato}
10
+ gem.email = "hayeah@gmail.com"
11
+ gem.homepage = "http://github.com/hayeah/redmiso"
12
+ gem.authors = ["Howard Yeh"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "redmiso #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,127 @@
1
+ require 'redis'
2
+ class Redmiso
3
+ end
4
+
5
+ require 'redmiso/type'
6
+
7
+ class Redmiso
8
+ class << self
9
+ attr_accessor :default
10
+
11
+ def redis
12
+ # use Redis default by default
13
+ @redis ||= Redis.new(default || {})
14
+ @redis
15
+ end
16
+
17
+ def string(name)
18
+ t = type(Type::String,name)
19
+ define_method("#{name}=") do |value|
20
+ t.set(value)
21
+ end
22
+ end
23
+
24
+ def instance_field
25
+ end
26
+
27
+ def class_field
28
+ end
29
+
30
+ def type(type,name)
31
+ t = type.new(redis,"#{self}.#{name}")
32
+ self.class_eval do
33
+ define_method(name) do |&block|
34
+ if block
35
+ t.instance_eval(block)
36
+ else
37
+ t.value
38
+ end
39
+ end
40
+ end
41
+ t
42
+ end
43
+
44
+ def exist?(id)
45
+ r = redis.sismember(id_set,id)
46
+ r
47
+ end
48
+
49
+ def create(id=nil)
50
+ id ||= redis.incr(auto_increment)
51
+ unless redis.sadd(id_set,id)
52
+ raise "can't create with existing id: #{id}"
53
+ end
54
+ self.new(id)
55
+ end
56
+
57
+ def delete(id)
58
+ if redis.srem(id_set,id) == 0
59
+ raise "can't delete id: #{id}"
60
+ end
61
+ end
62
+
63
+ def ids
64
+ redis.smembers(id_set).map(&:to_i)
65
+ end
66
+
67
+ def all
68
+ ids.map { |id| self.new(id) }
69
+ end
70
+
71
+ def count
72
+ redis.scard(id_set)
73
+ end
74
+
75
+ def [](id)
76
+ self.new(id) if exist?(id)
77
+ end
78
+
79
+ def vacuum
80
+ # clean up everything not in root set
81
+ raise "abstract"
82
+ redis.keys("#{self}.*")
83
+ # then extrat ids of fields, and check existence in rootset
84
+ end
85
+
86
+ def garbage
87
+ # return attributes of objects not in rootset
88
+ end
89
+
90
+ private
91
+ # this is the ROOT for this class
92
+ def id_set
93
+ @id_set ||= "#{self}#ids"
94
+ @id_set
95
+ end
96
+
97
+ def auto_increment
98
+ @auto_increment ||= "#{self}#auto_increment"
99
+ @auto_increment
100
+ end
101
+ end
102
+
103
+ def redis
104
+ self.class.redis
105
+ end
106
+
107
+ attr_reader :id
108
+ def initialize(id)
109
+ @id = id
110
+ end
111
+
112
+ def delete
113
+ self.class.delete(id)
114
+ end
115
+
116
+ def exist?
117
+ self.class.exist?(id)
118
+ end
119
+
120
+ def ==(obj)
121
+ obj.class == self.class && obj.id == self.id
122
+ end
123
+ end
124
+
125
+
126
+
127
+
@@ -0,0 +1,108 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'redis/raketasks'
3
+ #require 'logger'
4
+
5
+
6
+ describe "Redmiso" do
7
+ class TestMiso < Redmiso
8
+ #string(:a_string)
9
+ end
10
+
11
+ before(:all) do
12
+ result = RedisRunner.start_detached
13
+ raise("Could not start redis-server, aborting") unless result
14
+
15
+ # yea, this sucks, but it seems like sometimes we try to connect too quickly w/o it
16
+ sleep 1
17
+
18
+ # use database 15 for testing so we dont accidentally step on you real data
19
+ TestMiso.default = { :db => 15 }
20
+ @r = TestMiso.redis
21
+ raise("spec runs on database 15, but it's not empty") unless @r.dbsize == 0
22
+
23
+ end
24
+
25
+ before(:each) do
26
+ @r['foo'] = 'bar'
27
+ end
28
+
29
+ after(:each) do
30
+ @r.keys('*').each {|k|
31
+ @r.del k
32
+ }
33
+ end
34
+
35
+ after(:all) do
36
+ begin
37
+ @r.flushdb
38
+ @r.save
39
+ @r.quit
40
+ ensure
41
+ RedisRunner.stop
42
+ end
43
+ end
44
+
45
+ it "checks existence" do
46
+ TestMiso.exist?(10).should == false
47
+ o = TestMiso.create(10)
48
+ TestMiso.exist?(10).should == true
49
+ o.exist?.should == true
50
+ end
51
+
52
+ it "creates" do
53
+ o = TestMiso.create(10)
54
+ o.should be_a(TestMiso)
55
+ TestMiso.exist?(10).should == true
56
+ end
57
+
58
+ it "creates with auto increment" do
59
+ o = TestMiso.create
60
+ o.id.should == 1
61
+ o = TestMiso.create
62
+ o.id.should == 2
63
+ end
64
+
65
+ it "raises when create with duplicate id" do
66
+ TestMiso.create(10)
67
+ lambda { TestMiso.create(10) }.should raise_error
68
+ end
69
+
70
+ it "counts the root set" do
71
+ TestMiso.create
72
+ TestMiso.create
73
+ TestMiso.count.should == 2
74
+ end
75
+
76
+ it "gets all objects from root set" do
77
+ o = TestMiso.create
78
+ TestMiso.all.should == [o]
79
+ end
80
+
81
+ it "deletes from root set" do
82
+ o = TestMiso.create
83
+ o.exist?.should == true
84
+ o.delete
85
+ o.exist?.should == false
86
+ end
87
+
88
+ it "returns nil cannot find object" do
89
+ TestMiso[10].should be_nil
90
+ end
91
+
92
+ it "finds object" do
93
+ TestMiso.create(10)
94
+ o = TestMiso[10].should be_a(TestMiso)
95
+ end
96
+
97
+ # context "ID Set" do
98
+
99
+
100
+ # it "creates with auto increment"
101
+
102
+ # end
103
+
104
+ # it "fails" do
105
+ # fail "hey buddy, you should probably rename this file and start specing for real"
106
+ # end
107
+
108
+ end
@@ -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 'redmiso'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redmiso
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Howard Yeh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-14 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ description: Neato
26
+ email: hayeah@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/redmiso.rb
42
+ - spec/redmiso_spec.rb
43
+ - spec/spec.opts
44
+ - spec/spec_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/hayeah/redmiso
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Object Mapping for Redis
73
+ test_files:
74
+ - spec/redmiso_spec.rb
75
+ - spec/spec_helper.rb