fauna 0.2.6 → 1.1.0

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
+ v1.1.0. Updates for Fauna 1.1. Remove schema configuration.
2
+
1
3
  v0.2.6 Implement set paging.
2
4
 
3
5
  v0.2.5 Anonymous class configuration.
data/Manifest CHANGED
@@ -1,31 +0,0 @@
1
- CHANGELOG
2
- Gemfile
3
- LICENSE
4
- Manifest
5
- README.md
6
- Rakefile
7
- examples/welcome.rb
8
- fauna.gemspec
9
- lib/fauna.rb
10
- lib/fauna/client.rb
11
- lib/fauna/connection.rb
12
- lib/fauna/ddl.rb
13
- lib/fauna/event_set.rb
14
- lib/fauna/model.rb
15
- lib/fauna/model/class.rb
16
- lib/fauna/model/user.rb
17
- lib/fauna/publisher.rb
18
- lib/fauna/rails.rb
19
- lib/fauna/resource.rb
20
- lib/tasks/fauna.rake
21
- test/association_test.rb
22
- test/class_test.rb
23
- test/client_test.rb
24
- test/connection_test.rb
25
- test/event_set_test.rb
26
- test/fixtures.rb
27
- test/publisher_test.rb
28
- test/readme_test.rb
29
- test/test_helper.rb
30
- test/user_test.rb
31
- test/validation_test.rb
data/README.md CHANGED
@@ -33,20 +33,18 @@ require "fauna"
33
33
 
34
34
  All API requests start with an instance of `Fauna::Connection`.
35
35
 
36
- Creating a connection requires either a token, a publisher key, a
37
- client key, or the publisher's email and password.
36
+ Creating a connection requires either a token, a server key, or a
37
+ client key.
38
38
 
39
- Let's use the email and password to get a publisher key:
39
+ Let's use a server key we got from our [Fauna Cloud console](https://fauna.org/console):
40
40
 
41
41
  ```ruby
42
- root = Fauna::Connection.new(email: "publisher@example.com", password: "secret")
43
- publisher_key = root.post("keys/publisher")['resource']['key']
42
+ server_key = 'ls8AkXLdakAAAALPAJFy3LvQAAGwDRAS_Prjy6O8VQBfQAlZzwAA'
44
43
  ```
45
-
46
- Now we can make a global publisher-level connection:
44
+ Now we can make a global database-level connection:
47
45
 
48
46
  ```ruby
49
- $fauna = Fauna::Connection.new(publisher_key: publisher_key)
47
+ $fauna = Fauna::Connection.new(secret: server_key)
50
48
  ```
51
49
 
52
50
  You can optionally configure a `logger` on the connection to ease
@@ -55,7 +53,7 @@ debugging:
55
53
  ```ruby
56
54
  require "logger"
57
55
  $fauna = Fauna::Connection.new(
58
- publisher_key: publisher_key,
56
+ secret: server_key,
59
57
  logger: Logger.new(STDERR))
60
58
  ```
61
59
 
@@ -66,11 +64,11 @@ context*, and then manipulate resources within that context:
66
64
 
67
65
  ```ruby
68
66
  Fauna::Client.context($fauna) do
69
- user = Fauna::User.create!(email: "taran@example.com")
67
+ user = Fauna::Resource.create('users', email: "taran@example.com")
70
68
  user.data["name"] = "Taran"
71
69
  user.data["profession"] = "Pigkeeper"
72
- user.save!
73
- user.destroy
70
+ user.save
71
+ user.delete
74
72
  end
75
73
  ```
76
74
 
@@ -91,176 +89,46 @@ fields:
91
89
 
92
90
  ```ruby
93
91
  Fauna::Client.context($fauna) do
94
- user = Fauna::User.create(unique_id: "taran77")
92
+ user = Fauna::Resource.create('users', constraints: "taran77")
95
93
 
96
94
  # fields
97
95
  user.ref # => "users/123"
98
96
  user.ts # => 2013-01-30 13:02:46 -0800
99
97
  user.deleted # => false
100
- user.unique_id # => "taran77"
98
+ user.constraints # => "taran77"
101
99
 
102
100
  # data and references
103
101
  user.data # => {}
104
102
  user.references # => {}
105
103
 
106
- # changes event set
107
- user.changes
104
+ # resource events timeline
105
+ user.events
108
106
  end
109
107
  ```
110
108
 
111
109
  ## Rails Usage
112
110
 
113
- Fauna provides ActiveModel-compatible classes that can be used
114
- directly in Rails.
115
-
116
- Fauna also provides a Rails helper that sets up a default context in
111
+ Fauna provides a Rails helper that sets up a default context in
117
112
  controllers, based on credentials in `config/fauna.yml`:
118
113
 
119
114
  ```yaml
120
115
  development:
121
116
  email: taran@example.com
122
117
  password: secret
123
- publisher_key: secret_key
118
+ server_key: secret_key
124
119
  test:
125
120
  email: taran@example.com
126
121
  password: secret
127
122
  ```
128
123
 
129
- (In `config/fauna.yml`, if an existing publisher key is specified, the
130
- email and password can be omitted. If a publisher key is not
124
+ (In `config/fauna.yml`, if an existing server key is specified, the
125
+ email and password can be omitted. If a server key is not
131
126
  specified, a new one will be created each time the app is started.)
132
127
 
133
128
  Then, in `config/initializers/fauna.rb`:
134
129
 
135
130
  ```ruby
136
131
  require "fauna/rails"
137
-
138
- Fauna.schema do
139
- # See below for schema setup
140
- end
141
- ```
142
-
143
- ### Setting Up the Schema
144
-
145
- First, create some Ruby classes to model your domain. They must
146
- inherit from the `Fauna::Class` base class:
147
-
148
- ```ruby
149
- # Create a custom Pig class.
150
- class Pig < Fauna::Class
151
- # Fields can be configured dynamically
152
- field :name, :title
153
- end
154
-
155
- # Create a custom Vision class
156
- class Vision < Fauna::Class
157
- field :pronouncement
158
- reference :pig
159
- end
160
- ```
161
-
162
- Fields and references can be configured dynamically, but the classes
163
- and event sets themselves must be configured with an additional
164
- `Fauna.schema` block (normally placed in
165
- `config/initializers/fauna.rb`):
166
-
167
- ```ruby
168
- Fauna.schema do
169
- with Pig do
170
- # Add a custom event set
171
- event_set :visions
172
- end
173
-
174
- with Vision
175
- end
176
- ```
177
-
178
- Install your schema on the server via the `fauna:migrate` Rake task,
179
- or directly from the Rails console:
180
-
181
- ```ruby
182
- Fauna::Client.context(Fauna.connection) do
183
- Fauna.migrate_schema!
184
- end
185
- ```
186
-
187
- Make sure to do this at least once, as well as every time you change
188
- the schema definition:
189
-
190
- ### Users Class
191
-
192
- ```ruby
193
- class Fauna::User
194
- # Extend the User class with a custom field
195
- field :pockets
196
- end
197
-
198
- # Create a user, fill their pockets, and delete them.
199
- Fauna::Client.context($fauna) do
200
- taran = Fauna::User.new(
201
- email: "taran@example.com",
202
- password: "secret")
203
-
204
- taran.save!
205
- taran.pockets = "Piggy treats"
206
- taran.save!
207
- taran.destroy
208
- end
209
- ```
210
-
211
- ### Custom Classes
212
-
213
- ```ruby
214
- # Create, find, update, and destroy Pigs.
215
- Fauna::Client.context($fauna) do
216
- @pig = Pig.create!(name: "Henwen", unique_id: "henwen")
217
-
218
- @pig = Pig.find(@pig.id)
219
- @pig.update(title: "Oracular Swine")
220
-
221
- @pig.title = "Most Illustrious Oracular Swine"
222
- @pig.save!
223
-
224
- @pig.destroy
225
- end
226
- ```
227
-
228
- ### Event Sets
229
-
230
- [Event Sets](https://fauna.org/API#event-sets) are high-cardinality,
231
- bidirectional event collections. Event sets must be declared in the
232
- Schema.
233
-
234
- ```ruby
235
- Fauna::Client.context($fauna) do
236
- @pig = Pig.create!(name: "Henwen", unique_id: "henwen")
237
-
238
- @vision = Vision.create!(pronouncement: "In an ominous tower...")
239
- @pig.visions.add @vision
240
-
241
- page = @pig.visions.page(:size => 2)
242
- page.events.first.resource # => @vision
243
-
244
- next_page = @pig.visions.page(:size => 2, :before => page.before)
245
- prev_page = @pig.visions.page(:size => 2, :after => page.after)
246
- end
247
- ```
248
-
249
- ### References
250
-
251
- References are single or low-cardinality, unidirectional, and have no
252
- event log. They are declared dynamically, in the class.
253
-
254
- ```ruby
255
- class Vision
256
- # References can be configured dynamically, like fields
257
- reference :pig
258
- end
259
-
260
- Fauna::Client.context($fauna) do
261
- @vision.pig # => @pig
262
- @vision.pig_ref # => "instances/1235921393191239"
263
- end
264
132
  ```
265
133
 
266
134
  ## Further Reading
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ Echoe.new("fauna") do |p|
5
5
  p.project = "fauna"
6
6
  p.summary = "Official Ruby client for the Fauna API."
7
7
  p.retain_gemspec = true
8
- p.dependencies = ["activemodel", "activesupport", "rest-client", "json"]
8
+ p.dependencies = ["rest-client", "json"]
9
9
  p.development_dependencies = ["mocha", "echoe", "minitest"]
10
10
  end
11
11
 
data/examples/welcome.rb CHANGED
@@ -18,10 +18,10 @@ pass = gets.chomp
18
18
 
19
19
  puts "\nConnected to Fauna Cloud Platform."
20
20
 
21
- puts "\nCreating a publisher key:"
21
+ puts "\nCreating a server key:"
22
22
  root = Fauna::Connection.new(email: email, password: pass)
23
- key = root.post("keys/publisher")['resource']['key']
24
- $fauna = Fauna::Connection.new(publisher_key: key)
23
+ key = root.post("keys", "role" => "server")['resource']['key']
24
+ $fauna = Fauna::Connection.new(server_key: key)
25
25
  pp key
26
26
 
27
27
  puts "\nCreating classes:"
data/fauna.gemspec CHANGED
@@ -2,37 +2,33 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "fauna"
5
- s.version = "0.2.6"
5
+ s.version = "1.1.0"
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-04-03"
9
+ s.date = "2013-07-31"
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/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", "lib/tasks/fauna.rake"]
13
- s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "examples/welcome.rb", "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", "lib/tasks/fauna.rake", "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"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/fauna.rb", "lib/fauna/cache.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/provided_classes.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "lib/fauna/set.rb", "lib/fauna/util.rb", "lib/tasks/fauna.rake"]
13
+ s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "examples/welcome.rb", "fauna.gemspec", "lib/fauna.rb", "lib/fauna/cache.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/provided_classes.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "lib/fauna/set.rb", "lib/fauna/util.rb", "lib/tasks/fauna.rake", "test/class_test.rb", "test/client_test.rb", "test/connection_test.rb", "test/database_test.rb", "test/readme_test.rb", "test/set_test.rb", "test/test_helper.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/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"]
20
+ s.test_files = ["test/class_test.rb", "test/client_test.rb", "test/connection_test.rb", "test/database_test.rb", "test/readme_test.rb", "test/set_test.rb", "test/test_helper.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  s.specification_version = 3
24
24
 
25
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_runtime_dependency(%q<activemodel>, [">= 0"])
27
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
28
26
  s.add_runtime_dependency(%q<rest-client>, [">= 0"])
29
27
  s.add_runtime_dependency(%q<json>, [">= 0"])
30
28
  s.add_development_dependency(%q<mocha>, [">= 0"])
31
29
  s.add_development_dependency(%q<echoe>, [">= 0"])
32
30
  s.add_development_dependency(%q<minitest>, [">= 0"])
33
31
  else
34
- s.add_dependency(%q<activemodel>, [">= 0"])
35
- s.add_dependency(%q<activesupport>, [">= 0"])
36
32
  s.add_dependency(%q<rest-client>, [">= 0"])
37
33
  s.add_dependency(%q<json>, [">= 0"])
38
34
  s.add_dependency(%q<mocha>, [">= 0"])
@@ -40,8 +36,6 @@ Gem::Specification.new do |s|
40
36
  s.add_dependency(%q<minitest>, [">= 0"])
41
37
  end
42
38
  else
43
- s.add_dependency(%q<activemodel>, [">= 0"])
44
- s.add_dependency(%q<activesupport>, [">= 0"])
45
39
  s.add_dependency(%q<rest-client>, [">= 0"])
46
40
  s.add_dependency(%q<json>, [">= 0"])
47
41
  s.add_dependency(%q<mocha>, [">= 0"])
data/lib/fauna.rb CHANGED
@@ -1,12 +1,7 @@
1
- require "json"
2
- require "logger"
3
- require "uri"
4
-
5
- require "restclient"
6
- require "active_model"
7
- require "active_support/inflector"
8
- require "active_support/core_ext/module/delegation"
9
- require "active_support/core_ext/hash/slice"
1
+ require 'json'
2
+ require 'logger'
3
+ require 'uri'
4
+ require 'restclient'
10
5
 
11
6
  if defined?(Rake)
12
7
  load "#{File.dirname(__FILE__)}/tasks/fauna.rake"
@@ -18,84 +13,12 @@ module Fauna
18
13
 
19
14
  class NotFound < RuntimeError
20
15
  end
21
-
22
- class MissingMigration < RuntimeError
23
- end
24
16
  end
25
17
 
26
- require "fauna/connection"
27
- require "fauna/client"
28
- require "fauna/resource"
29
- require "fauna/publisher"
30
- require "fauna/event_set"
31
- require "fauna/model"
32
- require "fauna/model/class"
33
- require "fauna/model/user"
34
- require "fauna/ddl"
35
-
36
- module Fauna
37
-
38
- DEFAULT_BLOCK = proc do
39
- with User, class_name: "users"
40
- with User::Config, class_name: "users/config"
41
- with EventsPage, class_name: "sets"
42
- with EventSetConfig, class_name: "sets/config"
43
- with ClassConfig, class_name: "classes/config"
44
- with Publisher, class_name: "publisher"
45
- end
46
-
47
- def self.configure_schema!
48
- @classes = {}
49
- @schema = Fauna::DDL.new
50
- @blocks.each { |blk| @schema.instance_eval(&blk) }
51
- @schema.configure!
52
- nil
53
- end
54
-
55
- def self.schema(&block)
56
- @blocks << block
57
- configure_schema!
58
- end
59
-
60
-
61
- def self.reset_schema!
62
- @blocks = [DEFAULT_BLOCK]
63
- configure_schema!
64
- end
65
-
66
- def self.migrate_schema!
67
- @schema.load!
68
- nil
69
- end
70
-
71
- # these should be private to the gem
72
-
73
- def self.exists_class_for_name?(fauna_class)
74
- !!@classes[fauna_class]
75
- end
76
-
77
- def self.add_class(fauna_class, klass)
78
- klass.fauna_class = fauna_class.to_s
79
- @classes.delete_if { |_, v| v == klass }
80
- @classes[fauna_class.to_s] = klass
81
- end
82
-
83
- def self.class_for_name(fauna_class)
84
- @classes[fauna_class] ||=
85
- if fauna_class =~ %r{^classes/[^/]+$}
86
- klass = begin $1.classify.constantize rescue NameError; nil end
87
- if klass.nil? || klass >= Fauna::Class || klass.fauna_class # e.g. already associated with another fauna_class
88
- klass = ::Class.new(Fauna::Class)
89
- end
90
-
91
- klass.fauna_class = fauna_class
92
- klass
93
- else
94
- ::Class.new(Fauna::Resource)
95
- end
96
- end
97
-
98
- # apply the default schema so that the built-in classes work
99
-
100
- reset_schema!
101
- end
18
+ require 'fauna/util'
19
+ require 'fauna/connection'
20
+ require 'fauna/cache'
21
+ require 'fauna/client'
22
+ require 'fauna/resource'
23
+ require 'fauna/set'
24
+ require 'fauna/provided_classes'