ripple_oh_caramba 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +2 -2
- data/VERSION +1 -1
- data/ideas/eagerly_mapping_array.rb +59 -0
- data/lib/ripple_oh_caramba.rb +35 -7
- data/ripple_oh_caramba.gemspec +64 -0
- data/spec/ripple_oh_caramba_spec.rb +27 -4
- metadata +5 -5
- data/.README.swp +0 -0
- data/lib/.ripple_oh_caramba.rb.swp +0 -0
data/README
CHANGED
@@ -56,10 +56,10 @@
|
|
56
56
|
|
57
57
|
// MUTUAL ASSOCIATION
|
58
58
|
|
59
|
-
|
59
|
+
reference_one_mutual :wife, :as => :husband, :class => Wife
|
60
60
|
# updates are automatically applied to both ends
|
61
61
|
|
62
|
-
|
62
|
+
reference_many_mutual :friends, :as => :friends, :class => self
|
63
63
|
|
64
64
|
|
65
65
|
// TOKENS FOR SIGNUP ETC
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,59 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# I could use a subclass of Array for storing
|
4
|
+
# *_many associations and have it automatically
|
5
|
+
# update the *_keys array when the it changes.
|
6
|
+
|
7
|
+
|
8
|
+
class EagerlyMappingArray < Array
|
9
|
+
|
10
|
+
def initialze(target_arr, &blk)
|
11
|
+
@target_arr = target_arr
|
12
|
+
@mapping = blk
|
13
|
+
super()
|
14
|
+
end
|
15
|
+
|
16
|
+
def apply_mapping
|
17
|
+
end
|
18
|
+
|
19
|
+
def []=(*args)
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def <<(*args)
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def concat(*args)
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def fill(*args)
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def flatten!(*args)
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
def replace(*args)
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def insert(*args)
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
def collect!(*args)
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
def map!(*args)
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
55
|
+
def push(*args)
|
56
|
+
super
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/lib/ripple_oh_caramba.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
|
2
2
|
require 'ripple'
|
3
3
|
|
4
|
-
#
|
4
|
+
# Monkeys like to patch. This code is like
|
5
|
+
# an ugly duckling.
|
5
6
|
|
6
7
|
module Ripple::Document::ClassMethods
|
7
8
|
|
@@ -9,17 +10,17 @@ module Ripple::Document::ClassMethods
|
|
9
10
|
def reference_one(name, opts={})
|
10
11
|
name = name.to_s
|
11
12
|
kls = opts[:class] ||
|
12
|
-
name.camelize
|
13
|
+
name.camelize
|
13
14
|
|
14
15
|
property :"#{name}_key", String
|
15
16
|
|
16
|
-
class_eval <<-CODE
|
17
|
+
class_eval <<-CODE, __FILE__, __LINE__
|
17
18
|
def #{name}
|
18
|
-
@#{name} ||= #{kls}.find(#{name}_key)
|
19
|
+
@#{name} ||= "#{kls}".constantize.find(#{name}_key)
|
19
20
|
end
|
20
21
|
|
21
22
|
def #{name}=(doc)
|
22
|
-
if doc.class != #{kls}
|
23
|
+
if doc.class.name != "#{kls}"
|
23
24
|
raise "got " + doc.class + ", expected #{kls}"
|
24
25
|
end
|
25
26
|
raise "must have a key" unless doc.key
|
@@ -30,8 +31,35 @@ module Ripple::Document::ClassMethods
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def reference_many(name, opts={})
|
33
|
-
|
34
|
-
|
34
|
+
plural_name = name.to_s
|
35
|
+
name = plural_name.singularize
|
36
|
+
kls = opts[:class] ||
|
37
|
+
name.camelize
|
38
|
+
|
39
|
+
property :"#{name}_keys", Array, :default => proc {[]}
|
40
|
+
before_save :"__set_#{name}_keys"
|
41
|
+
|
42
|
+
class_eval <<-CODE, __FILE__, __LINE__
|
43
|
+
|
44
|
+
def #{plural_name}
|
45
|
+
kls = '#{kls}'.constantize
|
46
|
+
@#{plural_name} ||= #{name}_keys.map do |key|
|
47
|
+
kls.find(key)
|
48
|
+
end.compact
|
49
|
+
end
|
50
|
+
|
51
|
+
def #{plural_name}=(val)
|
52
|
+
@#{plural_name} = val
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def __set_#{name}_keys
|
57
|
+
self.#{name}_keys = #{plural_name}.map do |item|
|
58
|
+
item.is_a?('#{kls}'.constantize) ?
|
59
|
+
item.key : raise(item.inspect + ' is not a #{kls}')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
CODE
|
35
63
|
end
|
36
64
|
|
37
65
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ripple_oh_caramba}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["jbe"]
|
12
|
+
s.date = %q{2011-02-20}
|
13
|
+
s.description = %q{Monkeypatches Riak, giving support for referential associations, mutual associations, and other stuff. Highly experimental.}
|
14
|
+
s.email = %q{post@jostein.be}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"ideas/eagerly_mapping_array.rb",
|
29
|
+
"lib/ripple_oh_caramba.rb",
|
30
|
+
"ripple_oh_caramba.gemspec",
|
31
|
+
"spec/ripple_oh_caramba_spec.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/jbe/ripple_oh_caramba}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
|
+
s.summary = %q{Monkey patch to extend the Riak DSL.}
|
38
|
+
s.test_files = [
|
39
|
+
"spec/ripple_oh_caramba_spec.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
50
|
+
s.add_runtime_dependency(%q<ripple>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
55
|
+
s.add_dependency(%q<ripple>, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
61
|
+
s.add_dependency(%q<ripple>, [">= 0"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -34,27 +34,50 @@ describe 'reference_one' do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
class Wanderer
|
38
|
+
include Ripple::Document
|
37
39
|
|
40
|
+
reference_many :friends, :class => Wanderer
|
41
|
+
end
|
38
42
|
|
39
43
|
|
40
|
-
|
41
|
-
|
44
|
+
|
45
|
+
describe 'reference_many' do
|
46
|
+
it 'works' do
|
47
|
+
mitch = Wanderer.create
|
48
|
+
george = Wanderer.create
|
49
|
+
wanderer = Wanderer.new(:friends => [mitch, george])
|
50
|
+
|
51
|
+
wanderer.friends.should == [mitch, george]
|
52
|
+
wanderer.save
|
53
|
+
wanderer.friend_keys.should == [mitch.key, george.key]
|
54
|
+
|
55
|
+
Wanderer.find(wanderer.key).friends.should == [mitch, george]
|
56
|
+
Wanderer.find(wanderer.key).friend_keys.should ==
|
57
|
+
[mitch.key, george.key]
|
58
|
+
|
59
|
+
[mitch, george, wanderer].each {|w| w.destroy }
|
60
|
+
end
|
42
61
|
end
|
43
62
|
|
44
|
-
describe '
|
63
|
+
describe 'reference_one_mutual' do
|
45
64
|
it 'works'
|
65
|
+
# and handles options
|
46
66
|
end
|
47
67
|
|
48
|
-
describe '
|
68
|
+
describe 'reference_many_mutual' do
|
49
69
|
it 'works'
|
70
|
+
# and handles options
|
50
71
|
end
|
51
72
|
|
52
73
|
describe 'token_key!' do
|
53
74
|
it 'works'
|
75
|
+
# and handles options
|
54
76
|
end
|
55
77
|
|
56
78
|
describe 'token' do
|
57
79
|
it 'works'
|
80
|
+
# and handles options
|
58
81
|
end
|
59
82
|
|
60
83
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- jbe
|
@@ -83,7 +83,6 @@ extra_rdoc_files:
|
|
83
83
|
- LICENSE.txt
|
84
84
|
- README
|
85
85
|
files:
|
86
|
-
- .README.swp
|
87
86
|
- .document
|
88
87
|
- .rspec
|
89
88
|
- Gemfile
|
@@ -92,8 +91,9 @@ files:
|
|
92
91
|
- README
|
93
92
|
- Rakefile
|
94
93
|
- VERSION
|
95
|
-
-
|
94
|
+
- ideas/eagerly_mapping_array.rb
|
96
95
|
- lib/ripple_oh_caramba.rb
|
96
|
+
- ripple_oh_caramba.gemspec
|
97
97
|
- spec/ripple_oh_caramba_spec.rb
|
98
98
|
has_rdoc: true
|
99
99
|
homepage: http://github.com/jbe/ripple_oh_caramba
|
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
109
|
requirements:
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
hash:
|
112
|
+
hash: 178217233
|
113
113
|
segments:
|
114
114
|
- 0
|
115
115
|
version: "0"
|
data/.README.swp
DELETED
Binary file
|
Binary file
|