active_remote 3.1.3 → 3.2.0.pre
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 +5 -5
- data/Rakefile +4 -4
- data/active_remote.gemspec +1 -1
- data/lib/active_remote/dsl.rb +36 -0
- data/lib/active_remote/rpc.rb +5 -1
- data/lib/active_remote/rpc_adapters/protobuf_adapter.rb +9 -4
- data/lib/active_remote/version.rb +1 -1
- data/spec/lib/active_remote/dsl_spec.rb +21 -0
- data/spec/lib/active_remote/persistence_spec.rb +1 -1
- data/spec/lib/active_remote/rpc_adapters/protobuf_adapter_spec.rb +24 -0
- data/spec/lib/active_remote/rpc_spec.rb +1 -1
- data/spec/lib/active_remote/search_spec.rb +1 -1
- data/spec/support/definitions/tag.proto +1 -0
- data/spec/support/protobuf/author.pb.rb +4 -1
- data/spec/support/protobuf/category.pb.rb +4 -1
- data/spec/support/protobuf/error.pb.rb +4 -1
- data/spec/support/protobuf/post.pb.rb +4 -1
- data/spec/support/protobuf/serializer.pb.rb +3 -1
- data/spec/support/protobuf/tag.pb.rb +5 -1
- metadata +50 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92f1ee499d90fb4274a13471bdb2759a522f703cfe5a7843b272842489ae6c78
|
4
|
+
data.tar.gz: b21aa7a6088c87be266c731780eafd9a770c4e6ac68c944e1ad6c80179d8e7c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cf5c43c7455d6398eb78231df7743a3f70ab5c3d9265af63be031732c74d02ffd393271d8fb6e0e48c86a347c63027c5885a10a8fdedfac97c6d3e6a5b832d1
|
7
|
+
data.tar.gz: e9ae862fabefcd03f2a7fa98819efb8606d15f0310e6e34817b19f5050be0527167f0cbe3dce6a00c136e6fd655650bd6be4886c3b29649ace25c2bb47110134
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
require "bundler/gem_tasks"
|
3
|
-
require
|
3
|
+
require "protobuf/tasks"
|
4
|
+
require "rspec/core/rake_task"
|
4
5
|
|
5
6
|
desc "Run specs"
|
6
7
|
RSpec::Core::RakeTask.new(:spec)
|
@@ -15,7 +16,6 @@ task :clean do
|
|
15
16
|
end
|
16
17
|
|
17
18
|
desc "Compile spec/support protobuf definitions"
|
18
|
-
task :compile
|
19
|
-
|
20
|
-
sh(cmd)
|
19
|
+
task :compile do
|
20
|
+
::Rake::Task["protobuf:compile"].invoke("", "spec/support/definitions", "spec/support/protobuf")
|
21
21
|
end
|
data/active_remote.gemspec
CHANGED
data/lib/active_remote/dsl.rb
CHANGED
@@ -20,6 +20,38 @@ module ActiveRemote
|
|
20
20
|
@publishable_attributes += attributes
|
21
21
|
end
|
22
22
|
|
23
|
+
def endpoint_for_create(endpoint)
|
24
|
+
endpoints :create => endpoint
|
25
|
+
end
|
26
|
+
|
27
|
+
def endpoint_for_delete(endpoint)
|
28
|
+
endpoints :delete => endpoint
|
29
|
+
end
|
30
|
+
|
31
|
+
def endpoint_for_destroy(endpoint)
|
32
|
+
endpoints :destroy => endpoint
|
33
|
+
end
|
34
|
+
|
35
|
+
def endpoint_for_search(endpoint)
|
36
|
+
endpoints :search => endpoint
|
37
|
+
end
|
38
|
+
|
39
|
+
def endpoint_for_update(endpoint)
|
40
|
+
endpoints :update => endpoint
|
41
|
+
end
|
42
|
+
|
43
|
+
def endpoints(endpoints_hash = nil)
|
44
|
+
@endpoints ||= {
|
45
|
+
:create => :create,
|
46
|
+
:delete => :delete,
|
47
|
+
:destroy => :destroy,
|
48
|
+
:search => :search,
|
49
|
+
:update => :update
|
50
|
+
}
|
51
|
+
@endpoints.merge!(endpoints_hash) if endpoints_hash.present?
|
52
|
+
@endpoints
|
53
|
+
end
|
54
|
+
|
23
55
|
# Set the namespace for the underlying RPC service class. If no namespace
|
24
56
|
# is given, then none will be used.
|
25
57
|
#
|
@@ -105,6 +137,10 @@ module ActiveRemote
|
|
105
137
|
|
106
138
|
# Private convenience methods for accessing DSL methods in instances
|
107
139
|
#
|
140
|
+
def _endpoints
|
141
|
+
self.class.endpoints
|
142
|
+
end
|
143
|
+
|
108
144
|
def _publishable_attributes
|
109
145
|
self.class.publishable_attributes
|
110
146
|
end
|
data/lib/active_remote/rpc.rb
CHANGED
@@ -34,7 +34,7 @@ module ActiveRemote
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def rpc
|
37
|
-
rpc_adapter.new(service_class)
|
37
|
+
rpc_adapter.new(service_class, endpoints)
|
38
38
|
end
|
39
39
|
|
40
40
|
def rpc_adapter
|
@@ -58,6 +58,10 @@ module ActiveRemote
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
def remote_call(rpc_method, request_args)
|
62
|
+
self.class.remote_call(rpc_method, request_args)
|
63
|
+
end
|
64
|
+
|
61
65
|
def rpc
|
62
66
|
self.class.rpc
|
63
67
|
end
|
@@ -6,20 +6,25 @@ module ActiveRemote
|
|
6
6
|
include Serializers::Protobuf
|
7
7
|
|
8
8
|
attr_reader :last_request, :last_response, :service_class
|
9
|
+
attr_accessor :endpoints
|
10
|
+
|
11
|
+
delegate :client, :to => :service_class
|
9
12
|
|
10
13
|
##
|
11
14
|
# Constructor!
|
12
15
|
#
|
13
|
-
def initialize(service_class)
|
16
|
+
def initialize(service_class, endpoints)
|
14
17
|
@service_class = service_class
|
18
|
+
@endpoints = endpoints
|
15
19
|
end
|
16
20
|
|
17
21
|
# Invoke an RPC call to the service for the given rpc method.
|
18
22
|
#
|
19
|
-
def execute(
|
23
|
+
def execute(endpoint, request_args)
|
24
|
+
rpc_method = endpoints.fetch(endpoint) { endpoint }
|
20
25
|
@last_request = request(rpc_method, request_args)
|
21
26
|
|
22
|
-
|
27
|
+
client.__send__(rpc_method, @last_request) do |c|
|
23
28
|
# In the event of service failure, raise the error.
|
24
29
|
c.on_failure do |error|
|
25
30
|
protobuf_error = protobuf_error_class(error)
|
@@ -35,7 +40,7 @@ module ActiveRemote
|
|
35
40
|
@last_response
|
36
41
|
end
|
37
42
|
|
38
|
-
|
43
|
+
private
|
39
44
|
|
40
45
|
def protobuf_error_class(error)
|
41
46
|
return ::ActiveRemote::ActiveRemoteError unless error.respond_to?(:error_type)
|
@@ -21,6 +21,27 @@ describe ActiveRemote::DSL do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
describe ".endpoints" do
|
25
|
+
it "has default values" do
|
26
|
+
expect(Tag.endpoints).to eq({
|
27
|
+
:create => :create,
|
28
|
+
:delete => :delete,
|
29
|
+
:destroy => :destroy,
|
30
|
+
:search => :search,
|
31
|
+
:update => :update
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
context "given a new value for an endpoint" do
|
36
|
+
after { Tag.endpoints(:create => :create) }
|
37
|
+
|
38
|
+
it "overwrites default values" do
|
39
|
+
Tag.endpoints(:create => :register)
|
40
|
+
expect(Tag.endpoints[:create]).to eq(:register)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
24
45
|
describe ".namespace" do
|
25
46
|
context "when given a value" do
|
26
47
|
it "sets @namespace to the value" do
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ::ActiveRemote::Persistence do
|
4
4
|
let(:response_without_errors) { ::HashWithIndifferentAccess.new(:errors => []) }
|
5
|
-
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class) }
|
5
|
+
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
6
6
|
|
7
7
|
subject { ::Tag.new }
|
8
8
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ActiveRemote::RPCAdapters::ProtobufAdapter do
|
4
|
+
let(:adapter) { ActiveRemote::RPCAdapters::ProtobufAdapter.new(Tag.service_class, Tag.endpoints) }
|
5
|
+
let(:client) { double(:client) }
|
6
|
+
|
7
|
+
subject { adapter }
|
8
|
+
|
9
|
+
# The Protobuf RPC client relies on method missing and delegations
|
10
|
+
# Provide a client double to make it possible to add expectations that specific methods are called
|
11
|
+
before { allow(adapter).to receive(:client).and_return(client) }
|
12
|
+
|
13
|
+
describe "#execute" do
|
14
|
+
context "when a custom endpoint is defined" do
|
15
|
+
before { adapter.endpoints[:create] = :register }
|
16
|
+
after { adapter.endpoints[:create] = :create }
|
17
|
+
|
18
|
+
it "calls the custom endpoint" do
|
19
|
+
expect(adapter.client).to receive(:register)
|
20
|
+
adapter.execute(:create, { :name => "foo" })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -35,7 +35,7 @@ describe ::ActiveRemote::RPC do
|
|
35
35
|
let(:args) { double(:args) }
|
36
36
|
let(:response) { double(:response) }
|
37
37
|
|
38
|
-
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class) }
|
38
|
+
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
39
39
|
|
40
40
|
before { allow(rpc).to receive(:execute).and_return(response) }
|
41
41
|
before { allow(::Tag).to receive(:rpc).and_return(rpc) }
|
@@ -41,7 +41,7 @@ describe ActiveRemote::Search do
|
|
41
41
|
|
42
42
|
context "given args that respond to :to_hash" do
|
43
43
|
let(:args) { Hash.new }
|
44
|
-
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class) }
|
44
|
+
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
45
45
|
|
46
46
|
before { allow(rpc).to receive(:execute).and_return(response) }
|
47
47
|
before { allow(::Tag).to receive(:rpc).and_return(rpc) }
|
@@ -22,6 +22,7 @@ service TagService {
|
|
22
22
|
rpc Create (Tag) returns (Tag);
|
23
23
|
rpc Update (Tag) returns (Tag);
|
24
24
|
rpc Delete (Tag) returns (Tag);
|
25
|
+
rpc Register (Tag) returns (Tag);
|
25
26
|
rpc CreateAll (Tags) returns (Tags);
|
26
27
|
rpc UpdateAll (Tags) returns (Tags);
|
27
28
|
rpc DeleteAll (Tags) returns (Tags);
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
##
|
2
4
|
# This file is auto-generated. DO NOT EDIT!
|
3
5
|
#
|
4
|
-
require 'protobuf
|
6
|
+
require 'protobuf'
|
5
7
|
require 'protobuf/rpc/service'
|
6
8
|
|
7
9
|
|
@@ -12,6 +14,7 @@ require 'error.pb'
|
|
12
14
|
|
13
15
|
module Generic
|
14
16
|
module Remote
|
17
|
+
::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
|
15
18
|
|
16
19
|
##
|
17
20
|
# Message Classes
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
##
|
2
4
|
# This file is auto-generated. DO NOT EDIT!
|
3
5
|
#
|
4
|
-
require 'protobuf
|
6
|
+
require 'protobuf'
|
5
7
|
require 'protobuf/rpc/service'
|
6
8
|
|
7
9
|
|
@@ -12,6 +14,7 @@ require 'error.pb'
|
|
12
14
|
|
13
15
|
module Generic
|
14
16
|
module Remote
|
17
|
+
::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
|
15
18
|
|
16
19
|
##
|
17
20
|
# Message Classes
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
##
|
2
4
|
# This file is auto-generated. DO NOT EDIT!
|
3
5
|
#
|
4
|
-
require 'protobuf
|
6
|
+
require 'protobuf'
|
5
7
|
require 'protobuf/rpc/service'
|
6
8
|
|
7
9
|
|
@@ -13,6 +15,7 @@ require 'category.pb'
|
|
13
15
|
|
14
16
|
module Generic
|
15
17
|
module Remote
|
18
|
+
::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
|
16
19
|
|
17
20
|
##
|
18
21
|
# Message Classes
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
##
|
2
4
|
# This file is auto-generated. DO NOT EDIT!
|
3
5
|
#
|
4
|
-
require 'protobuf
|
6
|
+
require 'protobuf'
|
5
7
|
require 'protobuf/rpc/service'
|
6
8
|
|
7
9
|
|
@@ -12,6 +14,7 @@ require 'error.pb'
|
|
12
14
|
|
13
15
|
module Generic
|
14
16
|
module Remote
|
17
|
+
::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
|
15
18
|
|
16
19
|
##
|
17
20
|
# Message Classes
|
@@ -48,6 +51,7 @@ module Generic
|
|
48
51
|
rpc :create, ::Generic::Remote::Tag, ::Generic::Remote::Tag
|
49
52
|
rpc :update, ::Generic::Remote::Tag, ::Generic::Remote::Tag
|
50
53
|
rpc :delete, ::Generic::Remote::Tag, ::Generic::Remote::Tag
|
54
|
+
rpc :register, ::Generic::Remote::Tag, ::Generic::Remote::Tag
|
51
55
|
rpc :create_all, ::Generic::Remote::Tags, ::Generic::Remote::Tags
|
52
56
|
rpc :update_all, ::Generic::Remote::Tags, ::Generic::Remote::Tags
|
53
57
|
rpc :delete_all, ::Generic::Remote::Tags, ::Generic::Remote::Tags
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hutchison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '5'
|
22
|
+
version: '5.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '5'
|
32
|
+
version: '5.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,6 +218,7 @@ files:
|
|
218
218
|
- spec/lib/active_remote/persistence_spec.rb
|
219
219
|
- spec/lib/active_remote/primary_key_spec.rb
|
220
220
|
- spec/lib/active_remote/query_attribute_spec.rb
|
221
|
+
- spec/lib/active_remote/rpc_adapters/protobuf_adapter_spec.rb
|
221
222
|
- spec/lib/active_remote/rpc_spec.rb
|
222
223
|
- spec/lib/active_remote/scope_keys_spec.rb
|
223
224
|
- spec/lib/active_remote/search_spec.rb
|
@@ -263,13 +264,54 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
263
264
|
version: '0'
|
264
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
265
266
|
requirements:
|
266
|
-
- - "
|
267
|
+
- - ">"
|
267
268
|
- !ruby/object:Gem::Version
|
268
|
-
version:
|
269
|
+
version: 1.3.1
|
269
270
|
requirements: []
|
270
271
|
rubyforge_project:
|
271
|
-
rubygems_version: 2.
|
272
|
+
rubygems_version: 2.7.7
|
272
273
|
signing_key:
|
273
274
|
specification_version: 4
|
274
275
|
summary: Active Record for your platform
|
275
|
-
test_files:
|
276
|
+
test_files:
|
277
|
+
- spec/lib/active_remote/association_spec.rb
|
278
|
+
- spec/lib/active_remote/attributes_spec.rb
|
279
|
+
- spec/lib/active_remote/base_spec.rb
|
280
|
+
- spec/lib/active_remote/dirty_spec.rb
|
281
|
+
- spec/lib/active_remote/dsl_spec.rb
|
282
|
+
- spec/lib/active_remote/integration_spec.rb
|
283
|
+
- spec/lib/active_remote/persistence_spec.rb
|
284
|
+
- spec/lib/active_remote/primary_key_spec.rb
|
285
|
+
- spec/lib/active_remote/query_attribute_spec.rb
|
286
|
+
- spec/lib/active_remote/rpc_adapters/protobuf_adapter_spec.rb
|
287
|
+
- spec/lib/active_remote/rpc_spec.rb
|
288
|
+
- spec/lib/active_remote/scope_keys_spec.rb
|
289
|
+
- spec/lib/active_remote/search_spec.rb
|
290
|
+
- spec/lib/active_remote/serialization_spec.rb
|
291
|
+
- spec/lib/active_remote/serializers/protobuf_spec.rb
|
292
|
+
- spec/lib/active_remote/typecasting_spec.rb
|
293
|
+
- spec/lib/active_remote/validations_spec.rb
|
294
|
+
- spec/spec_helper.rb
|
295
|
+
- spec/support/definitions/author.proto
|
296
|
+
- spec/support/definitions/category.proto
|
297
|
+
- spec/support/definitions/error.proto
|
298
|
+
- spec/support/definitions/post.proto
|
299
|
+
- spec/support/definitions/serializer.proto
|
300
|
+
- spec/support/definitions/tag.proto
|
301
|
+
- spec/support/helpers.rb
|
302
|
+
- spec/support/models.rb
|
303
|
+
- spec/support/models/author.rb
|
304
|
+
- spec/support/models/category.rb
|
305
|
+
- spec/support/models/default_author.rb
|
306
|
+
- spec/support/models/message_with_options.rb
|
307
|
+
- spec/support/models/no_attributes.rb
|
308
|
+
- spec/support/models/post.rb
|
309
|
+
- spec/support/models/tag.rb
|
310
|
+
- spec/support/models/typecasted_author.rb
|
311
|
+
- spec/support/protobuf.rb
|
312
|
+
- spec/support/protobuf/author.pb.rb
|
313
|
+
- spec/support/protobuf/category.pb.rb
|
314
|
+
- spec/support/protobuf/error.pb.rb
|
315
|
+
- spec/support/protobuf/post.pb.rb
|
316
|
+
- spec/support/protobuf/serializer.pb.rb
|
317
|
+
- spec/support/protobuf/tag.pb.rb
|