carrot_rpc 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db8c95c8b6b864d2c0af65ec4387ec19f890c73a
4
- data.tar.gz: 3ee199f732826c03aaaa9cdbd480da06a0f8fda8
3
+ metadata.gz: 99b2493a7ffe385eee686f6d78b57e7e2240d370
4
+ data.tar.gz: 6839c61baeafbeb0097bf89badd080d1d05c480d
5
5
  SHA512:
6
- metadata.gz: 8f69595a1d3fde344503ac5dc1c10b812fa805745d1c107a7bf60955f7b5f6fcff651c5537cf91973f945b98436d7c56394c3eebb081062878e1eefc0b59f323
7
- data.tar.gz: f4cfde4d0993018cfecf9d6507e18e4496cda93fa5826d4ecbc663a56f331cc28ec0da96299e50d98f90c11dcbe69626d44779f5d113d6726d57ec9d661336ad
6
+ metadata.gz: e611390a7dbc157412efbdd2c472c1358b1a7f6a62ca69e9637f010d46cf4382ec2a7f545e1279189aa4b1dac5426b74f7f30b7fdc326788069669470fd44d88
7
+ data.tar.gz: c6ccb1a6315f64c9180b938d551a1d38ea174ff95bc2dd48d729efe9dfa162f78069e4f7a10131f96de735bcd35eb4535afd989931684ce37d026686b67e11d9
data/CHANGELOG.md CHANGED
@@ -3,22 +3,25 @@
3
3
  **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
4
4
 
5
5
  - [Changelog](#changelog)
6
- - [v0.2.3](#v023)
6
+ - [v0.3.0](#v030)
7
7
  - [Enhancements](#enhancements)
8
8
  - [Bug Fixes](#bug-fixes)
9
+ - [v0.2.3](#v023)
10
+ - [Enhancements](#enhancements-1)
11
+ - [Bug Fixes](#bug-fixes-1)
9
12
  - [Upgrading](#upgrading)
10
13
  - [v0.2.1](#v021)
11
- - [Bug Fixes](#bug-fixes-1)
12
- - [v0.2.0](#v020)
13
- - [Enhancements](#enhancements-1)
14
14
  - [Bug Fixes](#bug-fixes-2)
15
- - [Incompatible Changes](#incompatible-changes)
16
- - [v0.1.2](#v012)
15
+ - [v0.2.0](#v020)
17
16
  - [Enhancements](#enhancements-2)
18
17
  - [Bug Fixes](#bug-fixes-3)
19
- - [v0.1.1](#v011)
18
+ - [Incompatible Changes](#incompatible-changes)
19
+ - [v0.1.2](#v012)
20
20
  - [Enhancements](#enhancements-3)
21
21
  - [Bug Fixes](#bug-fixes-4)
22
+ - [v0.1.1](#v011)
23
+ - [Enhancements](#enhancements-4)
24
+ - [Bug Fixes](#bug-fixes-5)
22
25
  - [Incompatible Changes](#incompatible-changes-1)
23
26
 
24
27
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -26,11 +29,22 @@
26
29
  # Changelog
27
30
  All significant changes in the project are documented here.
28
31
 
29
- ## v0.2.3
32
+ ## v0.3.0
33
+
34
+ ### Enhancements
35
+ * [#11](https://githb.com/C-S-D/carrot_rpc/pull/11) - Add CodeClimate badge to README - [thewalkingtoast](https://github.com/thewalkingtoast)
36
+ * [#13](https://githb.com/C-S-D/carrot_rpc/pull/13) - Document `queue_name` - [shamil614](https://github.com/shamil614)
37
+ * [#14](https://githb.com/C-S-D/carrot_rpc/pull/14) - Pass `rpc_request: true` in the `JSONAPI::Request` `context`, so resources can differentiate between API and RPC calls - [shamil614](https://github.com/shamil614)
30
38
 
39
+ ### Bug Fixes
40
+ * [#12](https://githb.com/C-S-D/carrot_rpc/pull/12) - Pass `request` to `render_errors` when handling exceptions in `CarrotRpc::RpcServer::JSONAPIResources` - [shamil614](https://github.com/shamil614)
41
+ * [#15](https://githb.com/C-S-D/carrot_rpc/pull/15) - Fix argument error bug when passing block to `CarrotRpc::TaggedLog` methods by allowing either a message or a block like standard `Logger` interface - [shamil614](https://github.com/shamil614)
42
+ * [#17](https://githb.com/C-S-D/carrot_rpc/pull/17) - New rubocop versions add new cops or deprecate old config settings, so it is not safe to have `"rubocop"` without a version in the gemspec. - [KronicDeth](http://github.com/kronicdeth)
43
+
44
+ ## v0.2.3
31
45
 
32
46
  ### Enhancements
33
- * [#9](https://github.com/C-S-D/carrot_rpc/pull/9) - [KronicDeth](http://github.com/KronicDeth)
47
+ * [#9](https://github.com/C-S-D/carrot_rpc/pull/9) - [KronicDeth](http://github.com/kronicdeth)
34
48
  * `CarrotRpc::RpcServer` subclasses can `include CarrotRpc::RpcServer::JSONAPIResources` to get
35
49
  [`JSONAPI::ActsAsResourceController`](https://github.com/cerebris/jsonapi-resources/blob/8e85d68dfbaf9181344c7618b0b29b4cfd362034/lib/jsonapi/acts_as_resource_controller.rb)
36
50
  helper methods for processing JSONAPI requests in server methods.
data/README.md CHANGED
@@ -19,6 +19,7 @@
19
19
 
20
20
  An opinionated approach to doing Remote Procedure Call (RPC) with RabbitMQ and the bunny gem. CarrotRpc serves as a way to streamline the RPC workflow so developers can focus on the implementation and not the plumbing when working with RabbitMQ.
21
21
 
22
+ [![Code Climate](https://codeclimate.com/github/C-S-D/carrot_rpc/badges/gpa.svg)](https://codeclimate.com/github/C-S-D/carrot_rpc)
22
23
  [![Circle CI](https://circleci.com/gh/C-S-D/carrot_rpc.svg?style=svg)](https://circleci.com/gh/C-S-D/carrot_rpc)
23
24
 
24
25
  ## Installation
@@ -42,7 +43,7 @@ There's two modes for CarrotRpc: server and client. The server is run via comman
42
43
  ### Server
43
44
  The server is configured via command line and run in it's own process.
44
45
 
45
- Carrot is easy to run via command line:
46
+ Carrot is easy to run via command line:
46
47
  ```bash
47
48
  carrot_rpc
48
49
  ```
@@ -75,15 +76,15 @@ Clients are configured by initializing `CarrotRpc::Configuration`. The most comm
75
76
 
76
77
  ```ruby
77
78
  CarrotRpc.configure do |config|
78
- # Required on the client to connect to RabbitMQ.
79
+ # Required on the client to connect to RabbitMQ.
79
80
  # Bunny defaults to connecting to ENV['RABBITMQ_URL']. See Bunny docs.
80
81
  config.bunny = Bunny.new.start
81
82
  # Set the log level. Ruby Logger Docs http://ruby-doc.org/stdlib-2.2.0/libdoc/logger/rdoc/Logger.html
82
83
  config.loglevel = Logger::INFO
83
- # Create a new logger or use the Rails logger.
84
+ # Create a new logger or use the Rails logger.
84
85
  # When using Rails, use a tagged log to make it easier to track RPC.
85
86
  config.logger = CarrotRpc::TaggedLog.new(logger: Rails.logger, tags: ["Carrot RPC Client"])
86
-
87
+
87
88
  # Don't use. Server implementation only. The values below are set via CLI:
88
89
  # config.pidfile = nil
89
90
  # config.runloop_sleep = 0
@@ -93,12 +94,14 @@ end
93
94
 
94
95
  ## Usage
95
96
  ### Writing Servers
96
- Carrot CLI will look for your servers in `app/servers` directory. This directory should not be autoloaded by the host application.
97
+ Carrot CLI will look for your servers in `app/servers` directory. This directory should not be autoloaded by the host application. Very important to declare the name of the queue with `queue_name`. The name must be the same as what's implemented in the `Client`.
97
98
 
98
99
 
99
100
  Example Server: `app/servers/car_server.rb`
100
101
  ```ruby
101
102
  class CarServer < CarrotRpc::RpcServer
103
+ queue_name "car_queue"
104
+
102
105
  def show(params)
103
106
  # ...do something
104
107
  Car.find(params[:id]).to_json
@@ -127,11 +130,13 @@ end
127
130
  ```
128
131
 
129
132
  ### Writing Clients
130
- Clients are not run in the CLI, and are typlically invoked during a request / response lifecycle in a web application. In the case of Rails, Clients would most likely be used in a controller action. Clients should be written in the `app/clients` directory of the host application, and should be autoloaded by Rails.
133
+ Clients are not run in the CLI, and are typlically invoked during a request / response lifecycle in a web application. In the case of Rails, Clients would most likely be used in a controller action. Clients should be written in the `app/clients` directory of the host application, and should be autoloaded by Rails. The name of the queue to send messages to must be declared with `queue_name`.
131
134
 
132
135
  Example Client: `app/clients/cars_client.rb`
133
136
  ```ruby
134
137
  class CarClient < CarrotRpc::RpcClient
138
+ queue_name "car_queue"
139
+
135
140
  # By default RpcClient defines the following Railsy inspired methods:
136
141
  # def show(params)
137
142
  # def index(params)
@@ -147,6 +152,8 @@ Example Client: `app/clients/cars_client.rb`
147
152
  Example Rails Controller:
148
153
  ```ruby
149
154
  class CarsController < ApplicationController
155
+ queue_name "car_queue"
156
+
150
157
  def show
151
158
  car_client = CarClient.new
152
159
  car_client.start
@@ -157,6 +164,42 @@ class CarsController < ApplicationController
157
164
  end
158
165
  ```
159
166
 
167
+ ### Support for JSONAPI::Resources
168
+ In the case that you're writing an application that uses the `jsonapi-resources` gem and you want the `RpcServer` to have the same functionality, then we got you covered. All you need to do is import a few modules. See [jsonapi-resources](https://github.com/cerebris/jsonapi-resources) for details on how to implement resources for your models.
169
+
170
+ Example Server with JSONAPI functionality:
171
+ ```ruby
172
+ class CarServer < CarrotRpc::RpcServer
173
+ extend CarrotRpc::RpcServer::JSONAPIResources::Actions
174
+ include CarrotRpc::RpcServer::JSONAPIResources
175
+
176
+ # declare the actions to enable
177
+ actions: :create, :destroy, :index, :show, :update
178
+
179
+ # Context so it can build urls
180
+ def base_url
181
+ "http://foo.com"
182
+ end
183
+
184
+ # Context to find the resource and create links.
185
+ def controller
186
+ "api/cars"
187
+ end
188
+
189
+ # JSONAPI::Resource example: `app/resources/car_resource.rb`
190
+ def resource_klass
191
+ CarResource
192
+ end
193
+
194
+ queue_name "car_queue"
195
+
196
+ def show(params)
197
+ # ...do something
198
+ Car.find(params[:id]).to_json
199
+ end
200
+ end
201
+ ```
202
+
160
203
  ## Development
161
204
 
162
205
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
data/carrot_rpc.gemspec CHANGED
@@ -43,7 +43,7 @@ Gem::Specification.new do |spec|
43
43
  # Unit test framework
44
44
  spec.add_development_dependency "rspec"
45
45
  # Style-checker
46
- spec.add_development_dependency "rubocop"
46
+ spec.add_development_dependency "rubocop", "~> 0.36.0"
47
47
 
48
48
  spec.required_ruby_version = "~> 2.2"
49
49
  end
@@ -77,7 +77,7 @@ module CarrotRpc::RpcServer::JSONAPIResources
77
77
  logger.error { # rubocop:disable Style/BlockDelimiters
78
78
  "Internal Server Error: #{exception.message} #{exception.backtrace.join("\n")}"
79
79
  }
80
- render_errors(internal_server_error.errors)
80
+ render_errors(internal_server_error.errors, request: request)
81
81
  end
82
82
  end
83
83
 
@@ -101,7 +101,7 @@ module CarrotRpc::RpcServer::JSONAPIResources
101
101
  def process_request_params(params) # rubocop:disable Metrics/MethodLength
102
102
  request = JSONAPI::Request.new(
103
103
  params,
104
- context: {},
104
+ context: { rpc_request: true },
105
105
  key_formatter: key_formatter,
106
106
  server_error_callbacks: []
107
107
  )
@@ -17,8 +17,8 @@ class CarrotRpc::TaggedLog
17
17
 
18
18
  # Dyanmically define logger methods with a tagged reference. Makes filtering of logs possible.
19
19
  %i(debug info warn error fatal unknown).each do |level|
20
- define_method(level) do |msg|
21
- logger.tagged(tags) { logger.send(level, msg) }
20
+ define_method(level) do |msg = nil, &block|
21
+ logger.tagged(tags) { logger.send(level, msg || block.call) }
22
22
  end
23
23
  end
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module CarrotRpc
2
- VERSION = "0.2.3".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrot_rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Hamilton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-16 00:00:00.000000000 Z
12
+ date: 2016-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -99,16 +99,16 @@ dependencies:
99
99
  name: rubocop
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: 0.36.0
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
111
+ version: 0.36.0
112
112
  description: Streamlined approach to setting up RPC over RabbitMQ.
113
113
  email:
114
114
  - shamil614@gmail.com