splash 0.0.1.alpha → 0.0.1.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/lib/splash.rb +22 -26
- data/lib/splash/acts_as_collection.rb +3 -2
- data/lib/splash/acts_as_scope.rb +97 -33
- data/lib/splash/acts_as_scope_root.rb +2 -1
- data/lib/splash/annotated.rb +2 -1
- data/lib/splash/application.rb +2 -1
- data/lib/splash/attribute.rb +39 -21
- data/lib/splash/attributed_struct.rb +2 -1
- data/lib/splash/callbacks.rb +37 -0
- data/lib/splash/collection.rb +14 -11
- data/lib/splash/connection.rb +2 -1
- data/lib/splash/constraint.rb +3 -5
- data/lib/splash/constraint/all.rb +2 -1
- data/lib/splash/constraint/any.rb +2 -1
- data/lib/splash/constraint/in.rb +2 -1
- data/lib/splash/constraint/not_nil.rb +2 -1
- data/lib/splash/created_at.rb +16 -0
- data/lib/splash/document.rb +43 -15
- data/lib/splash/embed.rb +29 -9
- data/lib/splash/has_attributes.rb +68 -37
- data/lib/splash/has_collection.rb +79 -0
- data/lib/splash/has_constraint.rb +2 -1
- data/lib/splash/map_reduce.rb +124 -0
- data/lib/splash/matcher.rb +160 -0
- data/lib/splash/namespace.rb +149 -15
- data/lib/splash/password.rb +2 -1
- data/lib/splash/persister.rb +22 -62
- data/lib/splash/query_interface.rb +28 -6
- data/lib/splash/saveable.rb +5 -104
- data/lib/splash/scope.rb +16 -3
- data/lib/splash/scope/map_reduce_interface.rb +33 -0
- data/lib/splash/scope/options.rb +16 -6
- data/lib/splash/updated_at.rb +15 -0
- data/lib/splash/validates.rb +3 -1
- data/lib/splash/validator.rb +2 -1
- data/lib/splash/writeback.rb +46 -0
- data/lib/standart_extensions/array.rb +9 -0
- data/lib/standart_extensions/bson.rb +122 -0
- data/lib/standart_extensions/class.rb +11 -0
- data/lib/{splash/standart_extensions → standart_extensions}/hash.rb +6 -1
- data/lib/{splash/standart_extensions → standart_extensions}/module.rb +17 -3
- data/lib/standart_extensions/object.rb +13 -0
- data/splash.gemspec +17 -0
- metadata +20 -16
- data/lib/splash/scope_delegator.rb +0 -14
- data/lib/splash/scope_options.rb +0 -31
- data/lib/splash/standart_extensions/object.rb +0 -11
- data/lib/splash/standart_extensions/string.rb +0 -5
- data/spec/helper.rb +0 -15
- data/spec/lib/annotated_spec.rb +0 -87
- data/spec/lib/collection_spec.rb +0 -64
- data/spec/lib/has_attributes_spec.rb +0 -43
- data/spec/lib/has_constraints_spec.rb +0 -53
- data/spec/lib/inheritance_spec.rb +0 -69
data/lib/splash/validator.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class Splash::Writeback < Hash
|
3
|
+
|
4
|
+
def writeback_methods
|
5
|
+
@writeback_methods ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.merge(*args)
|
9
|
+
args.compact!
|
10
|
+
return nil unless args.any?
|
11
|
+
result = self.new
|
12
|
+
args.each do |arg|
|
13
|
+
result = result.merge(self.cast(arg))
|
14
|
+
end
|
15
|
+
return result
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.cast(hash_or_proc)
|
19
|
+
return hash_or_proc if hash_or_proc.kind_of? self
|
20
|
+
return self[hash_or_proc] if hash_or_proc.kind_of? Hash
|
21
|
+
if hash_or_proc.kind_of? Proc
|
22
|
+
r = self.new
|
23
|
+
r.writeback_methods << hash_or_proc
|
24
|
+
return r
|
25
|
+
end
|
26
|
+
raise "can't convert #{hash_or_proc} into Writeback'"
|
27
|
+
end
|
28
|
+
|
29
|
+
def writeback(to)
|
30
|
+
self.each do |key,value|
|
31
|
+
to.send("#{key.to_s}=",value)
|
32
|
+
end
|
33
|
+
@writeback_methods.each do |meth|
|
34
|
+
meth.call(to)
|
35
|
+
end
|
36
|
+
return to
|
37
|
+
end
|
38
|
+
|
39
|
+
def merge(other)
|
40
|
+
result = super(other)
|
41
|
+
result.writeback_methods.push(*self.writeback_methods)
|
42
|
+
result.writeback_methods.push(*other.writeback_methods)
|
43
|
+
return result
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require "bson"
|
3
|
+
module BSON
|
4
|
+
module ClassTypeConverter
|
5
|
+
|
6
|
+
MAX_INT32 = 2**31-1
|
7
|
+
|
8
|
+
MIN_INT32 = -(2**31)
|
9
|
+
|
10
|
+
INT32 = MIN_INT32 .. MAX_INT32
|
11
|
+
|
12
|
+
def self.map!(*args)
|
13
|
+
args.each_slice(2) do |klass,type|
|
14
|
+
@class_to_type[klass] << type
|
15
|
+
@type_to_class[type] << klass
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.classes(type)
|
20
|
+
@type_to_class[type]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.types_for_class(klass)
|
24
|
+
@class_to_type.each do |other_class,value|
|
25
|
+
if other_class >= klass
|
26
|
+
return value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
return nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.types_for_object(object)
|
33
|
+
if object.kind_of? Integer
|
34
|
+
if INT32.include?(object)
|
35
|
+
# ouch, 64 bit ints!
|
36
|
+
return [16].to_set
|
37
|
+
else
|
38
|
+
# ouch, 64 bit ints!
|
39
|
+
return [18].to_set
|
40
|
+
end
|
41
|
+
end
|
42
|
+
found_class = Object
|
43
|
+
found_type = nil
|
44
|
+
@class_to_type.each do |other_class,value|
|
45
|
+
if object.kind_of? other_class and !(other_class > found_class)
|
46
|
+
found_class = other_class
|
47
|
+
found_type = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return found_type
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.reset!
|
54
|
+
@class_to_type = Hash.new{|hash,key| hash[key] = Set.new }
|
55
|
+
@type_to_class = Hash.new{|hash,key| hash[key] = Set.new }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
ClassTypeConverter.reset!
|
60
|
+
|
61
|
+
ClassTypeConverter.map!(
|
62
|
+
Float, 1,
|
63
|
+
|
64
|
+
String, 2,
|
65
|
+
|
66
|
+
# Object:
|
67
|
+
Hash, 3,
|
68
|
+
|
69
|
+
Array, 4,
|
70
|
+
|
71
|
+
BSON::Binary, 5,
|
72
|
+
|
73
|
+
# Undefined (deprecated)
|
74
|
+
# NilClass, 6,
|
75
|
+
|
76
|
+
BSON::ObjectId, 7,
|
77
|
+
|
78
|
+
# Boolean:
|
79
|
+
TrueClass, 8,
|
80
|
+
FalseClass, 8,
|
81
|
+
|
82
|
+
Time, 9,
|
83
|
+
|
84
|
+
# Null:
|
85
|
+
NilClass, 10,
|
86
|
+
|
87
|
+
Regexp, 11,
|
88
|
+
|
89
|
+
BSON::DBRef, 12,
|
90
|
+
|
91
|
+
Symbol, 14,
|
92
|
+
|
93
|
+
BSON::Code, 15,
|
94
|
+
|
95
|
+
Integer, 16,
|
96
|
+
Integer, 18,
|
97
|
+
|
98
|
+
BSON::MaxKey, 127,
|
99
|
+
|
100
|
+
BSON::MinKey, -1
|
101
|
+
)
|
102
|
+
|
103
|
+
def self.types_for_object(object)
|
104
|
+
ClassTypeConverter.types_for_object(object)
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.types_for_class(klass)
|
108
|
+
ClassTypeConverter.types_for_class(klass)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.types(klass_or_object)
|
112
|
+
if klass_or_object.kind_of? Module
|
113
|
+
ClassTypeConverter.types_for_class(klass_or_object)
|
114
|
+
else
|
115
|
+
ClassTypeConverter.types_for_object(klass_or_object)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.type(klass_or_object)
|
120
|
+
self.types(klass_or_object).first
|
121
|
+
end
|
122
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require File.join File.dirname(__FILE__), "object"
|
2
3
|
require File.join File.dirname(__FILE__), "module"
|
3
4
|
class Hash
|
@@ -31,6 +32,10 @@ class Hash
|
|
31
32
|
self.reject{|key,val| !keys.include? key}
|
32
33
|
end
|
33
34
|
|
35
|
+
def except(keys)
|
36
|
+
self.reject{|key,val| keys.include? key}
|
37
|
+
end
|
38
|
+
|
34
39
|
def hashmap
|
35
40
|
self.inject({}) do |newhash, (k,v)|
|
36
41
|
newhash[k] = yield(k, v)
|
@@ -42,4 +47,4 @@ class Hash
|
|
42
47
|
self.merge(hsh)
|
43
48
|
end
|
44
49
|
|
45
|
-
end
|
50
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
class Module
|
2
3
|
|
3
4
|
def persister
|
4
|
-
@persister
|
5
|
+
@persister || self
|
5
6
|
end
|
6
7
|
|
7
8
|
def persister=(p)
|
@@ -69,5 +70,18 @@ end
|
|
69
70
|
|
70
71
|
DEF
|
71
72
|
end
|
72
|
-
|
73
|
-
|
73
|
+
|
74
|
+
def autoload_all(base)
|
75
|
+
Dir[File.join(base,'*.rb')].each do |file|
|
76
|
+
path = file[base.size..-4].split('/')
|
77
|
+
path.shift if path.first == ''
|
78
|
+
path.map! do |part|
|
79
|
+
part.gsub(/(^|_)([a-z])/){
|
80
|
+
$2.upcase
|
81
|
+
}
|
82
|
+
end
|
83
|
+
autoload path.join, file
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/splash.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{splash}
|
3
|
+
s.version = "0.0.1.beta"
|
4
|
+
s.date = %q{2010-10-11}
|
5
|
+
s.authors = ["HannesG"]
|
6
|
+
s.email = %q{hannes.georg@googlemail.com}
|
7
|
+
s.summary = %q{Be Splashed!}
|
8
|
+
s.homepage = %q{http://github.com/hannesg/splash}
|
9
|
+
s.description = %q{Splashes Mongo}
|
10
|
+
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
|
13
|
+
s.files = Dir.glob("lib/**/**/*") + ["Rakefile", "Gemfile","splash.gemspec"]
|
14
|
+
s.add_dependency "mongo", ">= 1.0"
|
15
|
+
|
16
|
+
s.add_development_dependency 'rspec', ">= 1.3"
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: splash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31098181
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 1
|
10
|
-
-
|
11
|
-
version: 0.0.1.
|
10
|
+
- beta
|
11
|
+
version: 0.0.1.beta
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- HannesG
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-10-11 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -59,30 +59,32 @@ extra_rdoc_files: []
|
|
59
59
|
|
60
60
|
files:
|
61
61
|
- lib/splash.rb
|
62
|
-
- lib/splash/scope_options.rb
|
63
62
|
- lib/splash/connection.rb
|
64
|
-
- lib/splash/scope_delegator.rb
|
65
63
|
- lib/splash/persister.rb
|
66
64
|
- lib/splash/query_interface.rb
|
67
65
|
- lib/splash/annotated.rb
|
68
66
|
- lib/splash/validates.rb
|
67
|
+
- lib/splash/map_reduce.rb
|
69
68
|
- lib/splash/scope.rb
|
70
69
|
- lib/splash/saveable.rb
|
70
|
+
- lib/splash/has_collection.rb
|
71
71
|
- lib/splash/attributed_struct.rb
|
72
72
|
- lib/splash/has_constraint.rb
|
73
|
+
- lib/splash/matcher.rb
|
74
|
+
- lib/splash/updated_at.rb
|
73
75
|
- lib/splash/constraint.rb
|
74
76
|
- lib/splash/acts_as_scope_root.rb
|
75
77
|
- lib/splash/attribute.rb
|
76
78
|
- lib/splash/scope/options.rb
|
77
|
-
- lib/splash/
|
78
|
-
- lib/splash/standart_extensions/object.rb
|
79
|
-
- lib/splash/standart_extensions/module.rb
|
80
|
-
- lib/splash/standart_extensions/string.rb
|
79
|
+
- lib/splash/scope/map_reduce_interface.rb
|
81
80
|
- lib/splash/password.rb
|
82
81
|
- lib/splash/embed.rb
|
83
82
|
- lib/splash/validator.rb
|
83
|
+
- lib/splash/writeback.rb
|
84
84
|
- lib/splash/has_attributes.rb
|
85
85
|
- lib/splash/document.rb
|
86
|
+
- lib/splash/created_at.rb
|
87
|
+
- lib/splash/callbacks.rb
|
86
88
|
- lib/splash/constraint/not_nil.rb
|
87
89
|
- lib/splash/constraint/in.rb
|
88
90
|
- lib/splash/constraint/all.rb
|
@@ -92,13 +94,15 @@ files:
|
|
92
94
|
- lib/splash/acts_as_scope.rb
|
93
95
|
- lib/splash/collection.rb
|
94
96
|
- lib/splash/application.rb
|
95
|
-
-
|
96
|
-
-
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
100
|
-
-
|
97
|
+
- lib/standart_extensions/hash.rb
|
98
|
+
- lib/standart_extensions/array.rb
|
99
|
+
- lib/standart_extensions/class.rb
|
100
|
+
- lib/standart_extensions/bson.rb
|
101
|
+
- lib/standart_extensions/object.rb
|
102
|
+
- lib/standart_extensions/module.rb
|
101
103
|
- Rakefile
|
104
|
+
- Gemfile
|
105
|
+
- splash.gemspec
|
102
106
|
has_rdoc: true
|
103
107
|
homepage: http://github.com/hannesg/splash
|
104
108
|
licenses: []
|
data/lib/splash/scope_options.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
class ScopeOptions
|
2
|
-
|
3
|
-
def self.cast(hsh)
|
4
|
-
if hsh.kind_of? self
|
5
|
-
return hsh
|
6
|
-
end
|
7
|
-
return self.new(hsh)
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(hsh=nil)
|
11
|
-
@options={:selector=>{},:limit=>-1}
|
12
|
-
@options.merge! hsh if hsh
|
13
|
-
|
14
|
-
@options.freeze
|
15
|
-
end
|
16
|
-
|
17
|
-
def merge(options)
|
18
|
-
self.class.new(@options.merge(options.to_h))
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_h
|
22
|
-
@options
|
23
|
-
end
|
24
|
-
|
25
|
-
def selector
|
26
|
-
@options[:selector]
|
27
|
-
end
|
28
|
-
def options
|
29
|
-
@options.reject{|key,value| key == :selector}
|
30
|
-
end
|
31
|
-
end
|