smart_adapters 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: 5eaeabe911a0b9b60e65687446a57cbd06669c329dfec08670866062f202af52
4
- data.tar.gz: '082e37e56694963820b08257b6db3389ec024f53d695c730db60ee05bc3ef1e9'
3
+ metadata.gz: eb19d73886d1004c3f7a6013730e74d8850c2a62f9ebdbadc5bd73a20c4174b7
4
+ data.tar.gz: 5d84224b5c54ee3dee1b57f83d5cdc0d0e5d4009889da2ec0abd99eb60581e78
5
5
  SHA512:
6
- metadata.gz: 103ce0a344b8988bfbbe946022cb599202fd7a5f9f31310eb3a039ccff7cb1711a22e1d102558e9fe4faefaf4fcaff350b17742a6c10e16c1e510691db74761b
7
- data.tar.gz: 8739e38404a22d95125134ffe4e8d4b53e6d1812f0883791e7db5b9b70041848ca78b64afd5072dd581fd467ce2c96dd334716437632f1a6732541dae95b513a
6
+ metadata.gz: 27280726284035ae961f4c0e76da0a72d9d6cc2522300b09597b2632f7b10740fc239dd79b35472e9d12f3b8c656f3eaed8d901344e1808ebaf8384907c3b6b5
7
+ data.tar.gz: a692b2b8ae0c5848fc51f88c26cd0cc27fa94ef8fa3a437148c4a0e7fbf506225644fd968d350bbf20b962f522561532ade1496dfcce69c853b62b95a5ff6d90
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/smart_adapters.svg)](https://badge.fury.io/rb/smart_adapters) [![Build Status](https://travis-ci.org/andrearampin/smart_adapters.svg?branch=master)](https://travis-ci.org/andrearampin/smart_adapters) [![Maintainability](https://api.codeclimate.com/v1/badges/9d55d1d054401ab93a6e/maintainability)](https://codeclimate.com/github/andrearampin/smart_adapters/maintainability)
4
4
 
5
- Smart Adapters were born from the need to fully decouple the controller logic from the rendering of the response.
6
- In the [Ruby on Rails documentation](https://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to), the controller has to decide the format of the answer based on the (Content-Type) request:
5
+ Smart Adapters neatly decouple the controllers from the views independently by the request format.
6
+ In the [Ruby on Rails documentation](https://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to), the controller decides the format of the answer based on the (Content-Type) request:
7
7
 
8
8
  ```ruby
9
9
  # app/controllers/people_controller.rb
@@ -16,28 +16,29 @@ def index
16
16
  end
17
17
  ```
18
18
 
19
- Although, this method looks simple it's already highlighting how two distinct formats might have a slightly different implementation. The problem here is that over time this controller might inherit unnecessary complexity by simply introducting new properties or formats.
20
-
21
- The Smart Adapters solve this problem by delegating the task of properly render the response based on the request format to well-defined classes, one per format. The following implementation makes use of the Smart Adapters:
19
+ The problem here is that over time the controllers inherit unnecessary complexity due to the evolution of the project (new logics and/or formats). The Smart Adapters solve the problem responding to a request with the appropriate format by using purposely designed classes.
22
20
 
23
21
  ```ruby
22
+ # Controller
24
23
  # app/controllers/people_controller.rb
25
24
  def index
26
25
  current_adapter.success Person.all
27
26
  end
28
27
 
28
+ # HTML Adapter
29
29
  # app/models/smart_adapters/people/index/html_adapter.rb
30
30
  def success(people)
31
31
  render 'people/show', locals: { people: people }
32
32
  end
33
33
 
34
+ # XML Adapter
34
35
  # app/models/smart_adapters/people/index/xml_adapter.rb
35
36
  def success(people)
36
37
  render xml: people, status: :ok
37
38
  end
38
39
  ```
39
40
 
40
- Now that the application has a class per format, it is easy to keep the controller dry while implementing format specific features. For instance, in case of an XML request, the adapter could add more details to the `people` collection or track some metrics without bloating the controller.
41
+ The application can now be kept dry while introducing new formats and functionalities. For instance, in case of an XML request, the adapter could add more details to the `people` collection or track some metrics without bloating the controller.
41
42
 
42
43
  ```ruby
43
44
  # app/models/smart_adapters/people/index/xml_adapter.rb
@@ -69,6 +70,14 @@ end
69
70
 
70
71
  Add the adapters for your **controller/action/format**.
71
72
 
73
+ ## Formats supported
74
+ - HTML
75
+ - JSON
76
+ - JS
77
+ - XML
78
+ - CSV
79
+ - TXT
80
+
72
81
  ### Example
73
82
 
74
83
  `app/controlles/users_controller.rb`
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SmartAdapters
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Rampin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-13 00:00:00.000000000 Z
11
+ date: 2018-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,8 +52,7 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Smart Adapters allow to keep the controllers DRY while being able to
56
- respond to any request format.
55
+ description: Smart Adapters keep Rails controllers dry.
57
56
  email:
58
57
  - andrea.rampin@gmail.com
59
58
  executables: []