fauna 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.2.4 Event set query API
2
+
1
3
  v0.2.3 Event set API enhancements
2
4
 
3
5
  v0.2.2 Support for Fauna API version 1
data/Manifest CHANGED
@@ -1,6 +1,7 @@
1
1
  CHANGELOG
2
2
  Gemfile
3
3
  LICENSE
4
+ Manifest
4
5
  README.md
5
6
  Rakefile
6
7
  fauna.gemspec
@@ -8,22 +9,21 @@ lib/fauna.rb
8
9
  lib/fauna/client.rb
9
10
  lib/fauna/connection.rb
10
11
  lib/fauna/ddl.rb
12
+ lib/fauna/event_set.rb
11
13
  lib/fauna/model.rb
12
14
  lib/fauna/model/class.rb
13
- lib/fauna/model/event_set.rb
14
- lib/fauna/model/publisher.rb
15
15
  lib/fauna/model/user.rb
16
+ lib/fauna/publisher.rb
16
17
  lib/fauna/rails.rb
17
18
  lib/fauna/resource.rb
19
+ test/association_test.rb
20
+ test/class_test.rb
18
21
  test/client_test.rb
19
22
  test/connection_test.rb
23
+ test/event_set_test.rb
20
24
  test/fixtures.rb
21
- test/model/association_test.rb
22
- test/model/class_test.rb
23
- test/model/event_set_test.rb
24
- test/model/publisher_test.rb
25
- test/model/user_test.rb
26
- test/model/validation_test.rb
25
+ test/publisher_test.rb
27
26
  test/readme_test.rb
28
27
  test/test_helper.rb
29
- Manifest
28
+ test/user_test.rb
29
+ test/validation_test.rb
@@ -2,22 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "fauna"
5
- s.version = "0.2.3"
5
+ s.version = "0.2.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Fauna, Inc."]
9
- s.date = "2013-03-03"
9
+ s.date = "2013-03-05"
10
10
  s.description = "Official Ruby client for the Fauna API."
11
11
  s.email = ""
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/fauna.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/ddl.rb", "lib/fauna/model.rb", "lib/fauna/model/class.rb", "lib/fauna/model/event_set.rb", "lib/fauna/model/publisher.rb", "lib/fauna/model/user.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb"]
13
- s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "fauna.gemspec", "lib/fauna.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/ddl.rb", "lib/fauna/model.rb", "lib/fauna/model/class.rb", "lib/fauna/model/event_set.rb", "lib/fauna/model/publisher.rb", "lib/fauna/model/user.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "test/client_test.rb", "test/connection_test.rb", "test/fixtures.rb", "test/model/association_test.rb", "test/model/class_test.rb", "test/model/event_set_test.rb", "test/model/publisher_test.rb", "test/model/user_test.rb", "test/model/validation_test.rb", "test/readme_test.rb", "test/test_helper.rb"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/fauna.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/ddl.rb", "lib/fauna/event_set.rb", "lib/fauna/model.rb", "lib/fauna/model/class.rb", "lib/fauna/model/user.rb", "lib/fauna/publisher.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb"]
13
+ s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "fauna.gemspec", "lib/fauna.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/ddl.rb", "lib/fauna/event_set.rb", "lib/fauna/model.rb", "lib/fauna/model/class.rb", "lib/fauna/model/user.rb", "lib/fauna/publisher.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "test/association_test.rb", "test/class_test.rb", "test/client_test.rb", "test/connection_test.rb", "test/event_set_test.rb", "test/fixtures.rb", "test/publisher_test.rb", "test/readme_test.rb", "test/test_helper.rb", "test/user_test.rb", "test/validation_test.rb"]
14
14
  s.homepage = "http://fauna.github.com/fauna/"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Fauna", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "fauna"
18
18
  s.rubygems_version = "1.8.23"
19
19
  s.summary = "Official Ruby client for the Fauna API."
20
- s.test_files = ["test/client_test.rb", "test/connection_test.rb", "test/model/association_test.rb", "test/model/class_test.rb", "test/model/event_set_test.rb", "test/model/publisher_test.rb", "test/model/user_test.rb", "test/model/validation_test.rb", "test/readme_test.rb", "test/test_helper.rb"]
20
+ s.test_files = ["test/association_test.rb", "test/class_test.rb", "test/client_test.rb", "test/connection_test.rb", "test/event_set_test.rb", "test/publisher_test.rb", "test/readme_test.rb", "test/test_helper.rb", "test/user_test.rb", "test/validation_test.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  s.specification_version = 3
@@ -21,10 +21,10 @@ end
21
21
  require "fauna/connection"
22
22
  require "fauna/client"
23
23
  require "fauna/resource"
24
+ require "fauna/publisher"
25
+ require "fauna/event_set"
24
26
  require "fauna/model"
25
27
  require "fauna/model/class"
26
- require "fauna/model/publisher"
27
- require "fauna/model/event_set"
28
28
  require "fauna/model/user"
29
29
  require "fauna/ddl"
30
30
 
@@ -94,6 +94,28 @@ module Fauna
94
94
  creates(query).resources
95
95
  end
96
96
 
97
+ def self.join(*args)
98
+ EventSetQuery.new('join', *args)
99
+ end
100
+
101
+ def self.union(*args)
102
+ EventSetQuery.new('union', *args)
103
+ end
104
+
105
+ def self.intersection(*args)
106
+ EventSetQuery.new('intersection', *args)
107
+ end
108
+
109
+ def self.difference(*args)
110
+ EventSetQuery.new('difference', *args)
111
+ end
112
+
113
+ def self.query(&block)
114
+ module_eval(&block)
115
+ end
116
+ end
117
+
118
+ class CustomEventSet < EventSet
97
119
  def add(resource)
98
120
  self.class.add(ref, resource)
99
121
  end
@@ -113,6 +135,41 @@ module Fauna
113
135
  end
114
136
  end
115
137
 
138
+ class EventSetQuery < EventSet
139
+ def initialize(function, *params)
140
+ @function = function
141
+ @params = params
142
+ end
143
+
144
+ def query
145
+ @query ||=
146
+ begin
147
+ pstrs = @params.map do |p|
148
+ p.respond_to?(:query) ? p.query : "'#{p.respond_to?(:ref) ? p.ref : p}'"
149
+ end
150
+
151
+ "#{@function}(#{pstrs.join(',')})"
152
+ end
153
+ end
154
+
155
+ def ref
156
+ "query?query=#{query}"
157
+ end
158
+
159
+ def page(query = nil)
160
+ EventsPage.find("query", (query || {}).merge(:query => self.query))
161
+ end
162
+
163
+ def creates(query = nil)
164
+ RefsPage.find("query/creates", (query || {}).merge(:query => self.query))
165
+ end
166
+
167
+ def updates(query = nil)
168
+ RefsPage.find("query/updates", (query || {}).merge(:query => self.query))
169
+ end
170
+
171
+ end
172
+
116
173
  class EventSetConfig < Fauna::Resource
117
174
  def initialize(parent_class, name, attrs = {})
118
175
  super(attrs)
@@ -35,7 +35,7 @@ module Fauna
35
35
  event_sets << set_name
36
36
  event_sets.uniq!
37
37
 
38
- define_method(name.to_s) { Fauna::EventSet.new("#{ref}/#{set_name}") }
38
+ define_method(name.to_s) { Fauna::CustomEventSet.new("#{ref}/#{set_name}") }
39
39
  end
40
40
  end
41
41
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  class AssociationTest < MiniTest::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  class ClassTest < ActiveModel::TestCase
4
4
  include ActiveModel::Lint::Tests
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  # TODO use association_test classes
4
4
 
@@ -43,4 +43,28 @@ class EventSetTest < ActiveModel::TestCase
43
43
  assert_equal [post], @model.posts.creates.resources
44
44
  assert_equal [post], @model.posts.updates.resources
45
45
  end
46
+
47
+ def test_event_set_query
48
+ posts = (1..3).map do |i|
49
+ Post.create(:body => "p#{i}").tap do |p|
50
+ @model.posts.add(p)
51
+ end
52
+ end
53
+
54
+ comments = posts.map do |p|
55
+ (1..3).map do |i|
56
+ Comment.create(:body => "#{p.body}_c#{i}").tap do |c|
57
+ p.comments.add(c)
58
+ end
59
+ end
60
+ end
61
+
62
+ q = Fauna::EventSet.join(@model.posts, 'sets/comments')
63
+
64
+ assert_equal 9, q.resources.size
65
+
66
+ comments.flatten.each do |c|
67
+ assert q.resources.include?(c)
68
+ end
69
+ end
46
70
  end
@@ -42,6 +42,10 @@ class Post < Fauna::Class
42
42
  field :body
43
43
  end
44
44
 
45
+ class Comment < Fauna::Class
46
+ field :body
47
+ end
48
+
45
49
  Fauna.schema do |f|
46
50
  with Pig, :class_name => "classes/pigs" do
47
51
  event_set :visions
@@ -55,5 +59,9 @@ Fauna.schema do |f|
55
59
  event_set :posts
56
60
  end
57
61
 
58
- with Post
62
+ with Post do
63
+ event_set :comments
64
+ end
65
+
66
+ with Comment
59
67
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  class PublisherTest < ActiveModel::TestCase
4
4
  # include ActiveModel::Lint::Tests
@@ -1,4 +1,4 @@
1
- require File.expand_path("../../test_helper", __FILE__)
1
+ require File.expand_path("../test_helper", __FILE__)
2
2
 
3
3
  class UserTest < ActiveModel::TestCase
4
4
  # include ActiveModel::Lint::Tests
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../test_helper', __FILE__)
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  class ClassValidationTest < MiniTest::Unit::TestCase
4
4
  def test_validates_presence_of_field
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fauna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-03 00:00:00.000000000 Z
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -135,11 +135,11 @@ extra_rdoc_files:
135
135
  - lib/fauna/client.rb
136
136
  - lib/fauna/connection.rb
137
137
  - lib/fauna/ddl.rb
138
+ - lib/fauna/event_set.rb
138
139
  - lib/fauna/model.rb
139
140
  - lib/fauna/model/class.rb
140
- - lib/fauna/model/event_set.rb
141
- - lib/fauna/model/publisher.rb
142
141
  - lib/fauna/model/user.rb
142
+ - lib/fauna/publisher.rb
143
143
  - lib/fauna/rails.rb
144
144
  - lib/fauna/resource.rb
145
145
  files:
@@ -154,24 +154,24 @@ files:
154
154
  - lib/fauna/client.rb
155
155
  - lib/fauna/connection.rb
156
156
  - lib/fauna/ddl.rb
157
+ - lib/fauna/event_set.rb
157
158
  - lib/fauna/model.rb
158
159
  - lib/fauna/model/class.rb
159
- - lib/fauna/model/event_set.rb
160
- - lib/fauna/model/publisher.rb
161
160
  - lib/fauna/model/user.rb
161
+ - lib/fauna/publisher.rb
162
162
  - lib/fauna/rails.rb
163
163
  - lib/fauna/resource.rb
164
+ - test/association_test.rb
165
+ - test/class_test.rb
164
166
  - test/client_test.rb
165
167
  - test/connection_test.rb
168
+ - test/event_set_test.rb
166
169
  - test/fixtures.rb
167
- - test/model/association_test.rb
168
- - test/model/class_test.rb
169
- - test/model/event_set_test.rb
170
- - test/model/publisher_test.rb
171
- - test/model/user_test.rb
172
- - test/model/validation_test.rb
170
+ - test/publisher_test.rb
173
171
  - test/readme_test.rb
174
172
  - test/test_helper.rb
173
+ - test/user_test.rb
174
+ - test/validation_test.rb
175
175
  homepage: http://fauna.github.com/fauna/
176
176
  licenses: []
177
177
  post_install_message:
@@ -203,13 +203,13 @@ signing_key:
203
203
  specification_version: 3
204
204
  summary: Official Ruby client for the Fauna API.
205
205
  test_files:
206
+ - test/association_test.rb
207
+ - test/class_test.rb
206
208
  - test/client_test.rb
207
209
  - test/connection_test.rb
208
- - test/model/association_test.rb
209
- - test/model/class_test.rb
210
- - test/model/event_set_test.rb
211
- - test/model/publisher_test.rb
212
- - test/model/user_test.rb
213
- - test/model/validation_test.rb
210
+ - test/event_set_test.rb
211
+ - test/publisher_test.rb
214
212
  - test/readme_test.rb
215
213
  - test/test_helper.rb
214
+ - test/user_test.rb
215
+ - test/validation_test.rb