fauna 1.3.2 → 1.3.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGY2NjU0NzY0YjAxMGViODQ0YTRlYzBkOGFjM2JlNGJiZTJkYzY1Ng==
4
+ YzZmYmZjOTlmOWM0ZjEwYWY4ZjcwOWE3NzVjYjdlYTEwZTQ4Y2Q1OQ==
5
5
  data.tar.gz: !binary |-
6
- OGJjZmVhODYzNGNiM2RjMTRiMmEwYWQ3NDMyZmU5OWRkNjU5ZDhhYw==
6
+ Y2ExYTdiMzU3YjQ5OGQ1Zjg2OWYzMjI5OWE4Mzg5MWQwYzgzOTBlNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTliY2Q1ZTRlNDIzMWNmNTAyOGQ4OWJmZDQwNmExZTViYjM3NzJjZGRiMWNk
10
- OTk3NjA0M2MwODNkZTVlNzU5ZDhiNDZmMDg0ZTg1MzE2NWE0MDdmYjFkZjg2
11
- ZGU3ZWRiZmUxYzE0MmJmNTc5M2IzYWFhOWFiYTE2NzdmNDY1YTM=
9
+ NDI4MmY3ZTI2YzEyOGQ5MTM5ZDNmZmFiNTJlN2MxYmRjZDM5ZTllMzc1YTYz
10
+ M2ZkNDJlNjIyMjIxODBjMTgyYjEzYjg1NGFhMzBjN2U1ODNiMjhmZmRjOGQz
11
+ NWY5OGE0YjVhYTVkZGUzZDIxMGMxNDk3YzdlMzZiYjgwOTliMTY=
12
12
  data.tar.gz: !binary |-
13
- YzVjZTA3ZTE2ZTMyOTczMDZhOGZhYjBiZWRhMmMxMjgwNWY2NTE4OGQ0Mjhi
14
- MmQ3YTJjNWQ1M2ZjZjg0OTA5NmVkOTZlN2NlY2QzZjFiODQ3NWQzYTQ3ZWMx
15
- Y2U5NTJhOTgxNjUzODNhYjI4M2ZjMTM3MTE2ZGJhYTA1NjIzMjA=
13
+ ZjE2NGM0Y2ExZjA3MjcxMDRlNDRlN2Y0OWU1OWM2YzE1MjAxYzZjOGJiYTky
14
+ ZjIwMWJkYzc4ZWJlZTcxMTk3MDk1Nzc1ZjEwNjU0MzBjMGJhNzFjM2EzOTgw
15
+ Yzk1Y2NmZTMzMmIwMjBkY2Y1YjhhNzUzYTc3NDk1ODVlNjQxZjA=
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v1.3.3 Fix #61.
2
+
1
3
  v1.3.2 Fix patch.
2
4
 
3
5
  v1.3.1 Switch to Faraday http client.
data/Manifest CHANGED
@@ -4,7 +4,6 @@ LICENSE
4
4
  Manifest
5
5
  README.md
6
6
  Rakefile
7
- fauna-ruby.pem
8
7
  fauna.gemspec
9
8
  lib/fauna.rb
10
9
  lib/fauna/cache.rb
data/README.md CHANGED
@@ -36,8 +36,6 @@ All API requests start with an instance of `Fauna::Connection`.
36
36
  Creating a connection requires either a token, a server key, or a
37
37
  client key.
38
38
 
39
- Let's use a server key we got from our [Fauna Cloud console](https://fauna.org/account/databases):
40
-
41
39
  ```ruby
42
40
  server_key = 'ls8AkXLdakAAAALPAJFy3LvQAAGwDRAS_Prjy6O8VQBfQAlZzwAA'
43
41
  ```
data/Rakefile CHANGED
@@ -1,23 +1,30 @@
1
1
  require 'echoe'
2
2
 
3
- Echoe.new("fauna") do |p|
4
- p.author = "Fauna, Inc."
5
- p.project = "fauna"
6
- p.summary = "Ruby client for the Fauna distributed database."
3
+ Echoe.new('fauna') do |p|
4
+ p.author = 'Fauna, Inc.'
5
+ p.project = 'fauna'
6
+ p.summary = 'Ruby client for the Fauna distributed database.'
7
7
  p.retain_gemspec = true
8
- p.require_signed
9
- p.certificate_chain = ["fauna-ruby.pem"]
10
- p.licenses = ["Mozilla Public License, Version 2.0 (MPL2)"]
11
- p.dependencies = ["faraday ~>0.9.0", "json ~>1.8.0"]
12
- p.development_dependencies = ["mocha", "echoe", "minitest ~>4.0"]
8
+ p.licenses = ['Mozilla Public License, Version 2.0 (MPL2)']
9
+ p.dependencies = ['faraday ~>0.9.0', 'json ~>1.8.0']
10
+ p.development_dependencies = ['mocha', 'echoe', 'minitest ~>4.0', 'rubocop']
13
11
  end
14
12
 
15
13
  task :beautify do
16
- require "ruby-beautify"
17
- Dir["**/*rb"].each do |filename|
14
+ require 'ruby-beautify'
15
+ Dir['**/*rb'].each do |filename|
18
16
  s = RBeautify.beautify_string(:ruby, File.read(filename))
19
17
  File.write(filename, s) unless s.empty?
20
- end
18
+ end
19
+ end
20
+
21
+ begin
22
+ require 'rubocop/rake_task'
23
+ RuboCop::RakeTask.new
24
+ rescue LoadError
25
+ task :rubocop do
26
+ $stderr.puts 'Rubocop is disabled'
27
+ end
21
28
  end
22
29
 
23
30
  task :prerelease => [:manifest, :test, :install]
data/fauna.gemspec CHANGED
@@ -1,25 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: fauna 1.3.2 ruby lib
2
+ # stub: fauna 1.3.3 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fauna"
6
- s.version = "1.3.2"
6
+ s.version = "1.3.3"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Fauna, Inc."]
10
- s.cert_chain = ["/Users/eweaver/fauna/fauna-ruby/fauna-ruby.pem"]
11
- s.date = "2014-05-15"
10
+ s.date = "2014-11-18"
12
11
  s.description = "Ruby client for the Fauna distributed database."
13
12
  s.email = ""
14
13
  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/named_resource.rb", "lib/fauna/rails.rb", "lib/fauna/resource.rb", "lib/fauna/set.rb", "lib/fauna/util.rb", "lib/tasks/fauna.rake"]
15
- s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "fauna-ruby.pem", "fauna.gemspec", "lib/fauna.rb", "lib/fauna/cache.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/named_resource.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/query_test.rb", "test/readme_test.rb", "test/set_test.rb", "test/test_helper.rb"]
14
+ s.files = ["CHANGELOG", "Gemfile", "LICENSE", "Manifest", "README.md", "Rakefile", "fauna.gemspec", "lib/fauna.rb", "lib/fauna/cache.rb", "lib/fauna/client.rb", "lib/fauna/connection.rb", "lib/fauna/named_resource.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/query_test.rb", "test/readme_test.rb", "test/set_test.rb", "test/test_helper.rb"]
16
15
  s.homepage = "http://fauna.github.com/fauna/"
17
16
  s.licenses = ["Mozilla Public License, Version 2.0 (MPL2)"]
18
17
  s.rdoc_options = ["--line-numbers", "--title", "Fauna", "--main", "README.md"]
19
18
  s.require_paths = ["lib"]
20
19
  s.rubyforge_project = "fauna"
21
20
  s.rubygems_version = "2.1.10"
22
- s.signing_key = "/Users/eweaver/cloudburst/configuration/gem_certificates/gem-private_key.pem"
23
21
  s.summary = "Ruby client for the Fauna distributed database."
24
22
  s.test_files = ["test/class_test.rb", "test/client_test.rb", "test/connection_test.rb", "test/database_test.rb", "test/query_test.rb", "test/readme_test.rb", "test/set_test.rb", "test/test_helper.rb"]
25
23
 
@@ -32,12 +30,14 @@ Gem::Specification.new do |s|
32
30
  s.add_development_dependency(%q<mocha>, [">= 0"])
33
31
  s.add_development_dependency(%q<echoe>, [">= 0"])
34
32
  s.add_development_dependency(%q<minitest>, ["~> 4.0"])
33
+ s.add_development_dependency(%q<rubocop>, [">= 0"])
35
34
  else
36
35
  s.add_dependency(%q<faraday>, ["~> 0.9.0"])
37
36
  s.add_dependency(%q<json>, ["~> 1.8.0"])
38
37
  s.add_dependency(%q<mocha>, [">= 0"])
39
38
  s.add_dependency(%q<echoe>, [">= 0"])
40
39
  s.add_dependency(%q<minitest>, ["~> 4.0"])
40
+ s.add_dependency(%q<rubocop>, [">= 0"])
41
41
  end
42
42
  else
43
43
  s.add_dependency(%q<faraday>, ["~> 0.9.0"])
@@ -45,5 +45,6 @@ Gem::Specification.new do |s|
45
45
  s.add_dependency(%q<mocha>, [">= 0"])
46
46
  s.add_dependency(%q<echoe>, [">= 0"])
47
47
  s.add_dependency(%q<minitest>, ["~> 4.0"])
48
+ s.add_dependency(%q<rubocop>, [">= 0"])
48
49
  end
49
50
  end
data/lib/fauna.rb CHANGED
@@ -5,9 +5,7 @@ require 'faraday'
5
5
  require 'cgi'
6
6
  require 'zlib'
7
7
 
8
- if defined?(Rake)
9
- load "#{File.dirname(__FILE__)}/tasks/fauna.rake"
10
- end
8
+ load "#{File.dirname(__FILE__)}/tasks/fauna.rake" if defined?(Rake)
11
9
 
12
10
  module Fauna
13
11
  class Invalid < RuntimeError
data/lib/fauna/cache.rb CHANGED
@@ -6,7 +6,7 @@ module Fauna
6
6
  attr_reader :connection
7
7
 
8
8
  def initialize(connection)
9
- raise ArgumentError, "Connection cannot be nil" unless connection
9
+ fail ArgumentError, 'Connection cannot be nil' unless connection
10
10
  @cache = {}
11
11
  @connection = connection
12
12
  end
@@ -32,18 +32,16 @@ module Fauna
32
32
 
33
33
  def put(ref, data)
34
34
  res = @connection.put(ref, data)
35
- if res['resource']
36
- update_cache(ref, res)
37
- res['resource']
38
- end
35
+ return unless res['resource']
36
+ update_cache(ref, res)
37
+ res['resource']
39
38
  end
40
39
 
41
40
  def patch(ref, data)
42
41
  res = @connection.patch(ref, data)
43
- if res['resource']
44
- update_cache(ref, res)
45
- res['resource']
46
- end
42
+ return unless res['resource']
43
+ update_cache(ref, res)
44
+ res['resource']
47
45
  end
48
46
 
49
47
  def delete(ref, data)
@@ -52,11 +50,11 @@ module Fauna
52
50
  nil
53
51
  end
54
52
 
55
- private
53
+ private
56
54
 
57
55
  def update_cache(ref, res)
58
- # FIXME Implement set range caching
59
- if (res['resource']['class'] != "resources" && res['resource']['class'] != "events")
56
+ # FIXME: Implement set range caching
57
+ if res['resource']['class'] != 'resources' && res['resource']['class'] != 'events'
60
58
  @cache[ref] = res['resource']['ref'] # store the non-canonical ref as a pointer to the real one.
61
59
  @cache[res['resource']['ref']] = res['resource']
62
60
  end
data/lib/fauna/client.rb CHANGED
@@ -16,7 +16,7 @@ module Fauna
16
16
  end
17
17
 
18
18
  def self.reset_context
19
- stack = []
19
+ stack = [] # rubocop:disable Lint/UselessAssignment
20
20
  end
21
21
 
22
22
  def self.get(ref, query = {}, pagination = {})
@@ -40,11 +40,11 @@ module Fauna
40
40
  end
41
41
 
42
42
  def self.connection
43
- stack.last or raise NoContextError, "You must be within a Fauna::Client.context block to perform operations."
43
+ stack.last || fail(NoContextError, 'You must be within a Fauna::Client.context block to perform operations.')
44
44
  end
45
45
 
46
46
  class << self
47
- private
47
+ private
48
48
 
49
49
  def stack
50
50
  Thread.current[:fauna_context_stack] ||= []
@@ -1,5 +1,5 @@
1
1
  module Fauna
2
- class Connection
2
+ class Connection # rubocop:disable Metrics/ClassLength
3
3
  class Error < RuntimeError
4
4
  attr_reader :error, :reason, :parameters
5
5
 
@@ -28,25 +28,25 @@ module Fauna
28
28
 
29
29
  attr_reader :domain, :scheme, :port, :credentials, :timeout, :connection_timeout, :adapter, :logger
30
30
 
31
- def initialize(params={})
31
+ def initialize(params = {}) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
32
32
  @logger = params[:logger] || nil
33
- @domain = params[:domain] || "rest1.fauna.org"
34
- @scheme = params[:scheme] || "https"
35
- @port = params[:port] || (@scheme == "https" ? 443 : 80)
33
+ @domain = params[:domain] || 'rest1.fauna.org'
34
+ @scheme = params[:scheme] || 'https'
35
+ @port = params[:port] || (@scheme == 'https' ? 443 : 80)
36
36
  @timeout = params[:timeout] || 60
37
37
  @connection_timeout = params[:connection_timeout] || 60
38
38
  @adapter = params[:adapter] || Faraday.default_adapter
39
- @credentials = params[:secret].to_s.split(":")
39
+ @credentials = params[:secret].to_s.split(':')
40
40
 
41
- if ENV["FAUNA_DEBUG"]
41
+ if ENV['FAUNA_DEBUG']
42
42
  @logger = Logger.new(STDERR)
43
43
  @logger.formatter = proc { |_, _, _, msg| "#{msg}\n" }
44
44
  end
45
45
 
46
46
  @conn = Faraday.new(
47
47
  :url => "#{@scheme}://#{@domain}:#{@port}/",
48
- :headers => { "Accept-Encoding" => "gzip", "Content-Type" => "application/json;charset=utf-8" },
49
- :request => { :timeout => @timeout, :open_timeout => @connection_timeout }
48
+ :headers => { 'Accept-Encoding' => 'gzip', 'Content-Type' => 'application/json;charset=utf-8' },
49
+ :request => { :timeout => @timeout, :open_timeout => @connection_timeout },
50
50
  ) do |conn|
51
51
  conn.adapter(@adapter)
52
52
  conn.basic_auth(@credentials[0].to_s, @credentials[1].to_s)
@@ -74,39 +74,36 @@ module Fauna
74
74
  nil
75
75
  end
76
76
 
77
- private
77
+ private
78
78
 
79
79
  def parse(headers, body)
80
80
  obj = body.empty? ? {} : JSON.parse(body)
81
- obj.merge!("headers" => headers)
81
+ obj.merge!('headers' => headers)
82
82
  obj
83
83
  end
84
84
 
85
85
  def log(indent)
86
- Array(yield).map do |string|
87
- string.split("\n")
88
- end.flatten.each do |line|
89
- @logger.debug(" " * indent + line)
90
- end
86
+ lines = Array(yield).collect { |string| string.split("\n") }
87
+ lines.flatten.each { |line| @logger.debug(' ' * indent + line) }
91
88
  end
92
89
 
93
90
  def query_string_for_logging(query)
94
- if query && !query.empty?
95
- "?" + query.map do |k,v|
96
- "#{k}=#{v}"
97
- end.join("&")
98
- end
91
+ return unless query && !query.empty?
92
+
93
+ '?' + query.collect do |k, v|
94
+ "#{k}=#{v}"
95
+ end.join('&')
99
96
  end
100
97
 
101
98
  def inflate(response)
102
- if ["gzip", "deflate"].include?(response.headers["Content-Encoding"])
99
+ if %w(gzip deflate).include?(response.headers['Content-Encoding'])
103
100
  Zlib::GzipReader.new(StringIO.new(response.body.to_s), :external_encoding => Encoding::UTF_8).read
104
101
  else
105
102
  response.body.to_s
106
103
  end
107
104
  end
108
105
 
109
- def execute(action, ref, data = nil, query = nil)
106
+ def execute(action, ref, data = nil, query = nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
110
107
  if @logger
111
108
  log(0) { "Fauna #{action.to_s.upcase} /#{ref}#{query_string_for_logging(query)}" }
112
109
  log(2) { "Credentials: #{@credentials}" }
@@ -120,7 +117,7 @@ module Fauna
120
117
  real = r1.to_f - r0.to_f
121
118
  cpu = (t1.utime - t0.utime) + (t1.stime - t0.stime) + (t1.cutime - t0.cutime) + (t1.cstime - t0.cstime)
122
119
  log(2) { ["Response headers: #{JSON.pretty_generate(response.headers)}", "Response JSON: #{body}"] }
123
- log(2) { "Response (#{response.status}): API processing #{response.headers["X-HTTP-Request-Processing-Time"]}ms, network latency #{((real - cpu)*1000).to_i}ms, local processing #{(cpu*1000).to_i}ms" }
120
+ log(2) { "Response (#{response.status}): API processing #{response.headers['X-HTTP-Request-Processing-Time']}ms, network latency #{((real - cpu) * 1000).to_i}ms, local processing #{(cpu * 1000).to_i}ms" }
124
121
  else
125
122
  response = execute_without_logging(action, ref, data, query)
126
123
  body = inflate(response)
@@ -130,17 +127,17 @@ module Fauna
130
127
  when 200..299
131
128
  [response.headers, body]
132
129
  when 400
133
- raise BadRequest.new(JSON.parse(body))
130
+ fail BadRequest.new(JSON.parse(body))
134
131
  when 401
135
- raise Unauthorized.new(JSON.parse(body))
132
+ fail Unauthorized.new(JSON.parse(body))
136
133
  when 403
137
- raise PermissionDenied.new(JSON.parse(body))
134
+ fail PermissionDenied.new(JSON.parse(body))
138
135
  when 404
139
- raise NotFound.new(JSON.parse(body))
136
+ fail NotFound.new(JSON.parse(body))
140
137
  when 405
141
- raise MethodNotAllowed.new(JSON.parse(body))
138
+ fail MethodNotAllowed.new(JSON.parse(body))
142
139
  else
143
- raise NetworkError, body
140
+ fail NetworkError, body
144
141
  end
145
142
  end
146
143
 
@@ -148,7 +145,7 @@ module Fauna
148
145
  @conn.send(action) do |req|
149
146
  req.params = query if query.is_a?(Hash)
150
147
  req.body = data.to_json if data.is_a?(Hash)
151
- req.url(ref)
148
+ req.url(ref || '')
152
149
  end
153
150
  end
154
151
  end
@@ -8,10 +8,10 @@ module Fauna
8
8
  super || "#{fauna_class}/#{name}"
9
9
  end
10
10
 
11
- private
11
+ private
12
12
 
13
13
  def post
14
- raise Invalid, "Cannot POST to named resource."
14
+ fail Invalid, 'Cannot POST to named resource.'
15
15
  end
16
16
  end
17
17
  end
data/lib/fauna/rails.rb CHANGED
@@ -10,11 +10,12 @@ if defined?(Rails)
10
10
  @silent = false
11
11
 
12
12
  CONFIG_FILE = "#{Rails.root}/config/fauna.yml"
13
- LOCAL_CONFIG_FILE = "#{ENV["HOME"]}/.fauna.yml"
14
- APP_NAME = Rails.application.class.name.split("::").first.underscore
13
+ LOCAL_CONFIG_FILE = "#{ENV['HOME']}/.fauna.yml"
14
+ APP_NAME = Rails.application.class.name.split('::').first.underscore
15
15
  FIXTURES_DIR = "#{Rails.root}/test/fixtures/fauna"
16
16
 
17
- def self.auth!
17
+ # rubocop:disable Metrics/BlockNesting
18
+ def self.auth! # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
18
19
  if File.exist? CONFIG_FILE
19
20
  credentials = YAML.load_file(CONFIG_FILE)[Rails.env] || {}
20
21
 
@@ -22,37 +23,38 @@ if defined?(Rails)
22
23
  credentials.merge!((YAML.load_file(LOCAL_CONFIG_FILE)[APP_NAME] || {})[Rails.env] || {})
23
24
  end
24
25
 
25
- if !@silent
26
- if credentials["secret"]
27
- STDERR.puts ">> Using Fauna server key #{credentials["secret"].inspect} for #{APP_NAME.inspect}."
26
+ unless @silent
27
+ if credentials['secret']
28
+ STDERR.puts ">> Using Fauna server key #{credentials['secret'].inspect} for #{APP_NAME.inspect}."
28
29
  else
29
- STDERR.puts ">> Using Fauna account #{credentials["email"].inspect} for #{APP_NAME.inspect}."
30
+ STDERR.puts ">> Using Fauna account #{credentials['email'].inspect} for #{APP_NAME.inspect}."
30
31
  end
31
32
 
32
- STDERR.puts ">> You can change this in config/fauna.yml or ~/.fauna.yml."
33
+ STDERR.puts '>> You can change this in config/fauna.yml or ~/.fauna.yml.'
33
34
  end
34
35
 
35
- if credentials["secret"]
36
- secret = credentials["secret"]
36
+ if credentials['secret']
37
+ secret = credentials['secret']
37
38
  else
38
39
  self.root_connection = Connection.new(
39
- :email => credentials["email"],
40
- :password => credentials["password"],
41
- :logger => Rails.logger)
40
+ :email => credentials['email'],
41
+ :password => credentials['password'],
42
+ :logger => Rails.logger)
42
43
 
43
- secret = root_connection.post("keys", "role" => "server")["resource"]["key"]
44
+ secret = root_connection.post('keys', 'role' => 'server')['resource']['key']
44
45
  end
45
46
 
46
- self.connection = Connection.new(secret: secret, logger: Rails.logger)
47
+ self.connection = Connection.new(:secret => secret, :logger => Rails.logger)
47
48
  else
48
- if !@silent
49
- STDERR.puts ">> Fauna account not configured. You can add one in config/fauna.yml."
49
+ unless @silent
50
+ STDERR.puts '>> Fauna account not configured. You can add one in config/fauna.yml.'
50
51
  end
51
52
  end
52
53
 
53
54
  @silent = true
54
55
  nil
55
56
  end
57
+ # rubocop:enable Metrics/BlockNesting
56
58
 
57
59
  # Around filter to set up a default context
58
60
 
@@ -85,7 +87,7 @@ if defined?(Rails)
85
87
  # suffix for association fields, but not _ref.
86
88
  if defined? ActiveSupport::Inflector
87
89
  ActiveSupport::Inflector.inflections do |inflect|
88
- inflect.human /_ref$/i, ''
90
+ inflect.human(/_ref$/i, '')
89
91
  end
90
92
  end
91
93
  end