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.
Files changed (55) hide show
  1. data/Gemfile +5 -0
  2. data/lib/splash.rb +22 -26
  3. data/lib/splash/acts_as_collection.rb +3 -2
  4. data/lib/splash/acts_as_scope.rb +97 -33
  5. data/lib/splash/acts_as_scope_root.rb +2 -1
  6. data/lib/splash/annotated.rb +2 -1
  7. data/lib/splash/application.rb +2 -1
  8. data/lib/splash/attribute.rb +39 -21
  9. data/lib/splash/attributed_struct.rb +2 -1
  10. data/lib/splash/callbacks.rb +37 -0
  11. data/lib/splash/collection.rb +14 -11
  12. data/lib/splash/connection.rb +2 -1
  13. data/lib/splash/constraint.rb +3 -5
  14. data/lib/splash/constraint/all.rb +2 -1
  15. data/lib/splash/constraint/any.rb +2 -1
  16. data/lib/splash/constraint/in.rb +2 -1
  17. data/lib/splash/constraint/not_nil.rb +2 -1
  18. data/lib/splash/created_at.rb +16 -0
  19. data/lib/splash/document.rb +43 -15
  20. data/lib/splash/embed.rb +29 -9
  21. data/lib/splash/has_attributes.rb +68 -37
  22. data/lib/splash/has_collection.rb +79 -0
  23. data/lib/splash/has_constraint.rb +2 -1
  24. data/lib/splash/map_reduce.rb +124 -0
  25. data/lib/splash/matcher.rb +160 -0
  26. data/lib/splash/namespace.rb +149 -15
  27. data/lib/splash/password.rb +2 -1
  28. data/lib/splash/persister.rb +22 -62
  29. data/lib/splash/query_interface.rb +28 -6
  30. data/lib/splash/saveable.rb +5 -104
  31. data/lib/splash/scope.rb +16 -3
  32. data/lib/splash/scope/map_reduce_interface.rb +33 -0
  33. data/lib/splash/scope/options.rb +16 -6
  34. data/lib/splash/updated_at.rb +15 -0
  35. data/lib/splash/validates.rb +3 -1
  36. data/lib/splash/validator.rb +2 -1
  37. data/lib/splash/writeback.rb +46 -0
  38. data/lib/standart_extensions/array.rb +9 -0
  39. data/lib/standart_extensions/bson.rb +122 -0
  40. data/lib/standart_extensions/class.rb +11 -0
  41. data/lib/{splash/standart_extensions → standart_extensions}/hash.rb +6 -1
  42. data/lib/{splash/standart_extensions → standart_extensions}/module.rb +17 -3
  43. data/lib/standart_extensions/object.rb +13 -0
  44. data/splash.gemspec +17 -0
  45. metadata +20 -16
  46. data/lib/splash/scope_delegator.rb +0 -14
  47. data/lib/splash/scope_options.rb +0 -31
  48. data/lib/splash/standart_extensions/object.rb +0 -11
  49. data/lib/splash/standart_extensions/string.rb +0 -5
  50. data/spec/helper.rb +0 -15
  51. data/spec/lib/annotated_spec.rb +0 -87
  52. data/spec/lib/collection_spec.rb +0 -64
  53. data/spec/lib/has_attributes_spec.rb +0 -43
  54. data/spec/lib/has_constraints_spec.rb +0 -53
  55. data/spec/lib/inheritance_spec.rb +0 -69
data/spec/helper.rb DELETED
@@ -1,15 +0,0 @@
1
- require "rubygems"
2
- gem "mongo"
3
- require "mongo"
4
-
5
- require File.join(File.dirname(__FILE__),"../../Humanized/lib/humanized")
6
-
7
- culture=Humanized::Culture.new
8
- culture.default_case = :nominativ
9
- culture.converter = Humanized::Converter.new({})
10
-
11
-
12
- Humanized::Culture.native=culture
13
- Humanized::Culture.current=culture
14
-
15
- require File.join(File.dirname(__FILE__),"../lib/splash")
@@ -1,87 +0,0 @@
1
- require File.join(File.dirname(__FILE__),"../helper")
2
-
3
- describe Splash::Annotated do
4
-
5
- it "should work for modules" do
6
-
7
- module NameAnnotations
8
-
9
- include Splash::Annotated
10
-
11
- class << self
12
- def included(base)
13
- base.extend(ClassMethods)
14
- super
15
- end
16
- end
17
-
18
- module ClassMethods
19
-
20
- def named(fn,name)
21
- @named||={}
22
- @named[fn]=name
23
- end
24
-
25
- def name(fn)
26
- return @named[fn] rescue nil
27
- end
28
-
29
- define_annotation :named
30
- end
31
-
32
- end
33
-
34
- class ClassWithSimpleAnnotations
35
-
36
- include NameAnnotations
37
-
38
- named "Nice Function!"
39
- def nice
40
- return 42
41
- end
42
-
43
- end
44
-
45
- ClassWithSimpleAnnotations.name(:nice).should == "Nice Function!"
46
-
47
- end
48
-
49
- it "should work for classes" do
50
-
51
- class AnnotatedParent
52
-
53
- include Splash::Annotated
54
-
55
- class << self
56
-
57
- def named(fn,name)
58
- @named||={}
59
- @named[fn]=name
60
- end
61
-
62
- def name(fn)
63
- return @named[fn] rescue nil
64
- end
65
-
66
- define_annotation :named
67
-
68
- end
69
-
70
- end
71
-
72
- class Child < AnnotatedParent
73
-
74
- include NameAnnotations
75
-
76
- named "Nice Function!"
77
- def nice
78
- return 42
79
- end
80
-
81
- end
82
-
83
- Child.name(:nice).should == "Nice Function!"
84
-
85
- end
86
-
87
- end
@@ -1,64 +0,0 @@
1
- require File.join(File.dirname(__FILE__),"../helper")
2
-
3
- describe Splash::ActsAsCollection do
4
-
5
- it "should support class integration" do
6
-
7
- class Friend
8
-
9
- end
10
-
11
- class FriendList < Array
12
-
13
- include Splash::ActsAsCollection.of(Friend)
14
-
15
- end
16
-
17
- FriendList.should < Splash::ActsAsCollection
18
-
19
- fl = FriendList.new
20
-
21
- fl.respond_to?(:create).should be_true
22
-
23
- fl.create
24
-
25
- fl.should have(1).item
26
-
27
- end
28
-
29
- it "should support the collection class" do
30
-
31
- class Friend
32
-
33
- end
34
-
35
- fl = Splash::Collection.of(Friend).new
36
-
37
- fl.respond_to?(:create).should be_true
38
-
39
- fl.create
40
-
41
- fl.should have(1).item
42
-
43
- end
44
-
45
- it "should support comparison" do
46
-
47
-
48
- class User
49
-
50
- end
51
-
52
- class Admin < User
53
-
54
- end
55
-
56
- fl = Splash::Collection.of(User).new
57
-
58
- fl.should be_a(Splash::Collection.of(User))
59
-
60
-
61
- end
62
-
63
-
64
- end
@@ -1,43 +0,0 @@
1
- require File.join(File.dirname(__FILE__),"../helper")
2
-
3
- describe Splash::HasAttributes do
4
-
5
- describe "declaration" do
6
-
7
- it "should look cool and work" do
8
-
9
- class User
10
-
11
- include Splash::HasAttributes
12
-
13
-
14
- # simple style
15
- def_attribute 'name'
16
-
17
- # simple with type
18
- def_attribute 'friends', Splash::Collection.of(User)
19
-
20
- def_attribute( 'mails', Splash::Collection.of(String)) do
21
-
22
- self.default = Splash::Collection.of(String).new
23
-
24
- end
25
-
26
- end
27
-
28
- User.attributes.should have(3).items
29
-
30
- u = User.new
31
-
32
- u.name.should be_nil
33
-
34
- u.friends.should be_nil
35
-
36
- u.mails.should_not be_nil
37
- u.mails.should be_a(Splash::Collection.of(String))
38
-
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,53 +0,0 @@
1
- require File.join(File.dirname(__FILE__),"../helper")
2
-
3
- describe Splash::HasConstraint do
4
-
5
- describe "declaration" do
6
-
7
- it "should work in a trivial case" do
8
-
9
- class Field
10
-
11
- include Splash::HasConstraint
12
-
13
- end
14
-
15
- f = Field.new
16
-
17
- f.constraint.should_not be_nil
18
-
19
- f.constraint.accept?(nil).should be_true
20
-
21
- end
22
-
23
- it "should give the power to write simple constraints fast" do
24
-
25
- class Field
26
-
27
- include Splash::HasConstraint
28
-
29
- end
30
-
31
- f = Field.new
32
-
33
- f.constraint.create "should not be nil" do |value|
34
- !value.nil?
35
- end
36
-
37
- f.constraint.create "should be a string with 5 to 10 chars" do |value|
38
- value.kind_of?(String) && (5..10).include?(value.length)
39
- end
40
-
41
- f.constraint.should have(2).items
42
-
43
- f.constraint.accept?(nil).should be_false
44
-
45
- f.constraint.accept?("aaa").should be_false
46
-
47
- f.constraint.accept?("aaaaa").should be_true
48
-
49
- end
50
-
51
- end
52
-
53
- end
@@ -1,69 +0,0 @@
1
- require File.join(File.dirname(__FILE__),"../helper")
2
-
3
- describe "inheritance" do
4
-
5
- it "should generate normal methods" do
6
-
7
- class A
8
-
9
- merged_inheritable_attr :a
10
- merged_inheritable_attr :b,"b"
11
-
12
- end
13
-
14
- A.respond_to?(:a).should be_true
15
- A.respond_to?(:b).should be_true
16
-
17
- A.b.should == "b"
18
-
19
- A.all_b.should == "b"
20
-
21
-
22
- end
23
-
24
- it "should generate inheritable methods" do
25
-
26
- class A
27
-
28
- merged_inheritable_attr :a
29
- merged_inheritable_attr :b,"b" do |a,b|
30
- a + b
31
- end
32
-
33
- end
34
-
35
- class B < A
36
-
37
- end
38
-
39
- class C < B
40
- merged_inheritable_attr :c
41
- end
42
-
43
- A.a << 1
44
-
45
- B.respond_to?(:a).should be_true
46
- B.respond_to?(:b).should be_true
47
-
48
- B.b = "c"
49
-
50
- B.a << 2
51
-
52
- B.all_b.should == "cb"
53
-
54
- C.all_b.should == "bcb"
55
-
56
- C.a << 3
57
-
58
- A.a.should have(1).item
59
- A.all_a.should have(1).item
60
-
61
- B.a.should have(1).item
62
- B.all_a.should have(2).items
63
-
64
- C.a.should have(1).item
65
- C.all_a.should have(3).items
66
-
67
- end
68
-
69
- end