risky 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/risky/all.rb +4 -0
- data/lib/risky/resolver.rb +74 -0
- data/lib/risky/version.rb +1 -1
- data/lib/risky.rb +9 -6
- metadata +34 -52
data/lib/risky/all.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module Risky::Resolver
|
2
|
+
# Makes it easy to resolve conflicts in an object in different ways.
|
3
|
+
#
|
4
|
+
# class User
|
5
|
+
# include Risky::Resolver
|
6
|
+
# value :union, :resolve => :union
|
7
|
+
# value :union, :resolve => lambda do |xs| xs.first end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def merge(versions)
|
11
|
+
p = super(versions).clone
|
12
|
+
|
13
|
+
# For each field, use the given resolver to merge all the conflicting
|
14
|
+
# values together.
|
15
|
+
values.each do |value, opts|
|
16
|
+
next unless resolver = opts[:resolve]
|
17
|
+
|
18
|
+
# Convert symbols and such to callables.
|
19
|
+
unless resolver.respond_to? :call
|
20
|
+
resolver = begin
|
21
|
+
# Try our resolvers
|
22
|
+
Resolvers.method resolver
|
23
|
+
rescue
|
24
|
+
# Try a class method
|
25
|
+
method resolver
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Resolve and set
|
30
|
+
p.send("#{value}=", resolver.call(
|
31
|
+
versions.map do |version|
|
32
|
+
version.send value
|
33
|
+
end
|
34
|
+
))
|
35
|
+
end
|
36
|
+
|
37
|
+
p
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Resolvers
|
42
|
+
extend self
|
43
|
+
|
44
|
+
def intersection(xs)
|
45
|
+
xs.compact.inject do |i, x|
|
46
|
+
i & x
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def max(xs)
|
51
|
+
xs.compact.max
|
52
|
+
end
|
53
|
+
|
54
|
+
def merge(xs)
|
55
|
+
xs.compact.inject do |m, x|
|
56
|
+
m.merge x
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def min(xs)
|
61
|
+
xs.compact.min
|
62
|
+
end
|
63
|
+
|
64
|
+
def union(xs)
|
65
|
+
xs.compact.inject do |u, x|
|
66
|
+
u | x
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.included(base)
|
72
|
+
base.extend ClassMethods
|
73
|
+
end
|
74
|
+
end
|
data/lib/risky/version.rb
CHANGED
data/lib/risky.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
class Risky
|
2
2
|
require 'set'
|
3
3
|
require 'riak'
|
4
|
+
require 'multi_json'
|
4
5
|
|
5
6
|
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
|
6
|
-
|
7
|
+
|
7
8
|
# Exceptions
|
8
9
|
require 'risky/invalid'
|
9
10
|
require 'risky/not_found'
|
@@ -11,7 +12,7 @@ class Risky
|
|
11
12
|
# Fix threading autoload bugs
|
12
13
|
require 'risky/threadsafe'
|
13
14
|
|
14
|
-
#
|
15
|
+
# Default plugins
|
15
16
|
require 'risky/cron_list'
|
16
17
|
require 'risky/indexes'
|
17
18
|
require 'risky/timestamps'
|
@@ -258,7 +259,7 @@ class Risky
|
|
258
259
|
# If your @riak proc can choose between multiple hosts, calling this on
|
259
260
|
# failure will allow subsequent requests to proceed on another host.
|
260
261
|
def self.riak!
|
261
|
-
Thread.current["self.riak"] = nil
|
262
|
+
Thread.current["#{self}.riak"] = nil
|
262
263
|
riak
|
263
264
|
end
|
264
265
|
|
@@ -416,9 +417,11 @@ class Risky
|
|
416
417
|
self.merged = true
|
417
418
|
else
|
418
419
|
# Not merging
|
419
|
-
self.values = self.class.cast(
|
420
|
+
self.values = self.class.cast(MultiJson.decode(riak_object.raw_data)) rescue {}
|
420
421
|
self.class.values.each do |k, v|
|
421
|
-
values[k]
|
422
|
+
if values[k].nil?
|
423
|
+
values[k] = (v[:default].clone rescue v[:default])
|
424
|
+
end
|
422
425
|
end
|
423
426
|
self.riak_object = riak_object
|
424
427
|
self.new = false
|
@@ -491,7 +494,7 @@ class Risky
|
|
491
494
|
return false unless valid?
|
492
495
|
end
|
493
496
|
|
494
|
-
@riak_object.raw_data = @values
|
497
|
+
@riak_object.raw_data = MultiJson.encode @values
|
495
498
|
@riak_object.content_type = "application/json"
|
496
499
|
|
497
500
|
store_opts = {}
|
metadata
CHANGED
@@ -1,87 +1,69 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: risky
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 4
|
9
|
-
version: 0.1.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Kyle Kingsbury
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2011-05-17 00:00:00 -07:00
|
12
|
+
date: 2011-10-03 00:00:00.000000000 -07:00
|
18
13
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
21
16
|
name: riak-client
|
22
|
-
|
23
|
-
|
24
|
-
requirements:
|
17
|
+
requirement: &13973420 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
25
20
|
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 0
|
30
|
-
- 0
|
31
|
-
- pre
|
21
|
+
- !ruby/object:Gem::Version
|
32
22
|
version: 1.0.0.pre
|
33
23
|
type: :runtime
|
34
|
-
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *13973420
|
35
26
|
description:
|
36
27
|
email: aphyr@aphyr.com
|
37
28
|
executables: []
|
38
|
-
|
39
29
|
extensions: []
|
40
|
-
|
41
30
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
|
31
|
+
files:
|
32
|
+
- lib/risky.rb
|
33
|
+
- lib/risky/resolver.rb
|
34
|
+
- lib/risky/version.rb
|
44
35
|
- lib/risky/invalid.rb
|
36
|
+
- lib/risky/all.rb
|
45
37
|
- lib/risky/not_found.rb
|
46
|
-
- lib/risky/threadsafe.rb
|
47
|
-
- lib/risky/version.rb
|
48
|
-
- lib/risky/timestamps.rb
|
49
38
|
- lib/risky/indexes.rb
|
39
|
+
- lib/risky/timestamps.rb
|
40
|
+
- lib/risky/threadsafe.rb
|
50
41
|
- lib/risky/cron_list.rb
|
51
|
-
- lib/risky.rb
|
52
42
|
- LICENSE
|
53
43
|
- README.markdown
|
54
44
|
has_rdoc: true
|
55
45
|
homepage: https://github.com/aphyr/risky
|
56
46
|
licenses: []
|
57
|
-
|
58
47
|
post_install_message:
|
59
48
|
rdoc_options: []
|
60
|
-
|
61
|
-
require_paths:
|
49
|
+
require_paths:
|
62
50
|
- lib
|
63
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
- 1
|
69
|
-
- 8
|
70
|
-
- 6
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
71
56
|
version: 1.8.6
|
72
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
79
63
|
requirements: []
|
80
|
-
|
81
64
|
rubyforge_project: risky
|
82
|
-
rubygems_version: 1.
|
65
|
+
rubygems_version: 1.6.2
|
83
66
|
signing_key:
|
84
67
|
specification_version: 3
|
85
68
|
summary: A Ruby ORM for the Riak distributed database.
|
86
69
|
test_files: []
|
87
|
-
|