fauna 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/Manifest +1 -1
- data/fauna.gemspec +2 -2
- data/lib/fauna.rb +1 -1
- data/lib/fauna/model.rb +11 -10
- data/lib/fauna/model/class.rb +0 -6
- data/lib/fauna/model/event_set.rb +51 -20
- data/lib/fauna/model/publisher.rb +1 -1
- data/lib/fauna/model/user.rb +4 -10
- data/test/model/class_test.rb +5 -0
- data/test/model/event_set_test.rb +8 -0
- data/test/model/user_test.rb +5 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/fauna.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "fauna"
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.3"
|
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-
|
9
|
+
s.date = "2013-03-03"
|
10
10
|
s.description = "Official Ruby client for the Fauna API."
|
11
11
|
s.email = ""
|
12
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"]
|
data/lib/fauna.rb
CHANGED
@@ -33,7 +33,7 @@ module Fauna
|
|
33
33
|
DEFAULT_BLOCK = proc do
|
34
34
|
with User, class_name: "users"
|
35
35
|
with User::Config, class_name: "users/config"
|
36
|
-
with
|
36
|
+
with EventsPage, class_name: "sets"
|
37
37
|
with EventSetConfig, class_name: "sets/config"
|
38
38
|
with ClassConfig, class_name: "classes/config"
|
39
39
|
with Publisher, class_name: "publisher"
|
data/lib/fauna/model.rb
CHANGED
@@ -14,18 +14,13 @@ module Fauna
|
|
14
14
|
base.send :include, ActiveModel::Serialization
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
ref =
|
20
|
-
if self <= Fauna::User::Config
|
21
|
-
"users/#{id}/config"
|
22
|
-
else
|
23
|
-
"#{fauna_class}/#{id}"
|
24
|
-
end
|
25
|
-
|
26
|
-
Fauna::Resource.find(ref)
|
17
|
+
def self.all
|
18
|
+
Fauna::EventSet.new(fauna_class)
|
27
19
|
end
|
28
20
|
|
21
|
+
def self.find_by_id(id)
|
22
|
+
Fauna::Resource.find("#{fauna_class}/#{id}")
|
23
|
+
end
|
29
24
|
|
30
25
|
def self.find_by_unique_id(unique_id)
|
31
26
|
find("#{fauna_class}/unique_id/#{unique_id}")
|
@@ -60,5 +55,11 @@ module Fauna
|
|
60
55
|
def to_model
|
61
56
|
self
|
62
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def post
|
62
|
+
Fauna::Client.post(self.class.fauna_class, struct)
|
63
|
+
end
|
63
64
|
end
|
64
65
|
end
|
data/lib/fauna/model/class.rb
CHANGED
@@ -1,46 +1,69 @@
|
|
1
1
|
|
2
2
|
module Fauna
|
3
|
-
class
|
4
|
-
|
5
|
-
attr_reader :ts, :set_ref, :resource_ref, :action
|
3
|
+
class SetRef
|
4
|
+
attr_reader :ts, :resource_ref
|
6
5
|
|
7
6
|
def initialize(attrs)
|
8
|
-
# TODO v1
|
9
7
|
@ts = attrs['ts']
|
10
|
-
@set_ref = attrs['set']
|
11
8
|
@resource_ref = attrs['resource']
|
12
|
-
@action = attrs['action']
|
13
9
|
end
|
14
10
|
|
15
11
|
def resource
|
16
12
|
Fauna::Resource.find(resource_ref)
|
17
13
|
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Event < SetRef
|
17
|
+
attr_reader :set_ref, :action
|
18
|
+
|
19
|
+
def initialize(attrs)
|
20
|
+
super(attrs)
|
21
|
+
@set_ref = attrs['set']
|
22
|
+
@action = attrs['action']
|
23
|
+
end
|
18
24
|
|
19
25
|
def set
|
20
26
|
EventSet.new(set_ref)
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
24
|
-
class
|
30
|
+
class EventsPage < Fauna::Resource
|
31
|
+
include Enumerable
|
32
|
+
|
33
|
+
def self.find(ref, query = nil)
|
34
|
+
alloc(Fauna::Client.get(ref, query).to_hash)
|
35
|
+
end
|
36
|
+
|
25
37
|
def events
|
26
38
|
@events ||= struct['events'].map { |e| Event.new(e) }
|
27
39
|
end
|
28
40
|
|
29
|
-
def
|
30
|
-
|
41
|
+
def each(&block)
|
42
|
+
events.each(&block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def empty?
|
46
|
+
events.empty?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class RefsPage < Fauna::Resource
|
51
|
+
include Enumerable
|
52
|
+
|
53
|
+
def self.find(ref, query = nil)
|
54
|
+
alloc(Fauna::Client.get(ref, query).to_hash)
|
55
|
+
end
|
56
|
+
|
57
|
+
def refs
|
58
|
+
@refs ||= struct['events'].map { |e| SetRef.new(e) }
|
31
59
|
end
|
32
60
|
|
33
61
|
def resources
|
34
|
-
|
35
|
-
|
36
|
-
events.inject([]) do |a, ev|
|
37
|
-
if (ev.action == 'create' && !seen[ev.resource_ref])
|
38
|
-
seen[ev.resource_ref] = true
|
39
|
-
a << ev.resource
|
40
|
-
end
|
62
|
+
refs.map(&:resource)
|
63
|
+
end
|
41
64
|
|
42
|
-
|
43
|
-
|
65
|
+
def empty?
|
66
|
+
events.empty?
|
44
67
|
end
|
45
68
|
end
|
46
69
|
|
@@ -52,7 +75,15 @@ module Fauna
|
|
52
75
|
end
|
53
76
|
|
54
77
|
def page(query = nil)
|
55
|
-
|
78
|
+
EventsPage.find(ref, query)
|
79
|
+
end
|
80
|
+
|
81
|
+
def creates(query = nil)
|
82
|
+
RefsPage.find("#{ref}/creates", query)
|
83
|
+
end
|
84
|
+
|
85
|
+
def updates(query = nil)
|
86
|
+
RefsPage.find("#{ref}/updates", query)
|
56
87
|
end
|
57
88
|
|
58
89
|
def events(query = nil)
|
@@ -60,7 +91,7 @@ module Fauna
|
|
60
91
|
end
|
61
92
|
|
62
93
|
def resources(query = nil)
|
63
|
-
|
94
|
+
creates(query).resources
|
64
95
|
end
|
65
96
|
|
66
97
|
def add(resource)
|
data/lib/fauna/model/user.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
module Fauna
|
3
3
|
class User < Fauna::Model
|
4
4
|
|
5
|
-
class Config < Fauna::
|
5
|
+
class Config < Fauna::Resource; end
|
6
6
|
|
7
7
|
def self.self
|
8
8
|
find("users/self")
|
@@ -12,18 +12,12 @@ module Fauna
|
|
12
12
|
find("users/email/#{email}")
|
13
13
|
end
|
14
14
|
|
15
|
-
def email; struct['email']; end
|
16
|
-
|
17
|
-
def password; struct['password']; end
|
18
|
-
|
19
15
|
def config
|
20
16
|
Fauna::User::Config.find("#{ref}/config")
|
21
17
|
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
def
|
26
|
-
Fauna::Client.post("users", struct)
|
27
|
-
end
|
19
|
+
# set on user create
|
20
|
+
def email; struct['email']; end
|
21
|
+
def password; struct['password']; end
|
28
22
|
end
|
29
23
|
end
|
data/test/model/class_test.rb
CHANGED
@@ -35,4 +35,12 @@ class EventSetTest < ActiveModel::TestCase
|
|
35
35
|
assert_equal page.events.size, 1
|
36
36
|
@model.posts.remove(page.events[0].resource)
|
37
37
|
end
|
38
|
+
|
39
|
+
def test_event_set_resources
|
40
|
+
post = Post.create(:body => "Hello")
|
41
|
+
@model.posts.add(post)
|
42
|
+
assert_equal [post], @model.posts.resources
|
43
|
+
assert_equal [post], @model.posts.creates.resources
|
44
|
+
assert_equal [post], @model.posts.updates.resources
|
45
|
+
end
|
38
46
|
end
|
data/test/model/user_test.rb
CHANGED
@@ -16,6 +16,11 @@ class UserTest < ActiveModel::TestCase
|
|
16
16
|
assert user.ref
|
17
17
|
end
|
18
18
|
|
19
|
+
def test_all
|
20
|
+
user = Fauna::User.create(@attributes)
|
21
|
+
assert Fauna::User.all.resources.include?(user)
|
22
|
+
end
|
23
|
+
|
19
24
|
def test_save
|
20
25
|
user = Fauna::User.new(@attributes)
|
21
26
|
user.save
|
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.
|
4
|
+
version: 0.2.3
|
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-
|
12
|
+
date: 2013-03-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|