crud_responder 0.2.3 → 0.2.4
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 +4 -4
- data/.rubocop.yml +0 -2
- data/README.md +54 -0
- data/crud_responder.gemspec +2 -2
- data/lib/crud_responder/version.rb +1 -1
- metadata +19 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea30ca09041d63698596e2b63ae437f5644117ae
|
4
|
+
data.tar.gz: 4f9a690ccfc8a24403963c62819f4fbcd7d0a0bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4dce5eaf2a58601ab686cbaa7f3bb5e9727e0e49a8794d5df652fed29110bea81474aab2999f6bcd93b138fa853b706ff0512b3c9e2025e00e73b152792742c
|
7
|
+
data.tar.gz: da2913826aeea78d96f7f7c93c4511e4b23afe1d53772b63ddc31614918e229207e57888926642e553efd611ac8cb69a640ada0edb7983a3c56473d29e9782ff
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -90,6 +90,22 @@ Or install it yourself as:
|
|
90
90
|
|
91
91
|
$ gem install crud_responder
|
92
92
|
|
93
|
+
Copy translations from gem's `config/locales` to your `config/locales`. Or, for example, create file `config/locales/crud_responder.en.yml` in your project with following content:
|
94
|
+
```yaml
|
95
|
+
en:
|
96
|
+
flash:
|
97
|
+
actions:
|
98
|
+
create:
|
99
|
+
notice: '%{resource_name} %{resource_desc} was successfully created.'
|
100
|
+
alert: '%{resource_name} %{resource_desc} cannot be created. %{errors}'
|
101
|
+
update:
|
102
|
+
notice: '%{resource_name} %{resource_desc} was successfully updated.'
|
103
|
+
alert: '%{resource_name} %{resource_desc} cannot be updated. %{errors}'
|
104
|
+
destroy:
|
105
|
+
notice: '%{resource_name} %{resource_desc} was successfully destroyed.'
|
106
|
+
alert: '%{resource_name} %{resource_desc} cannot be destroyed. %{errors}'
|
107
|
+
```
|
108
|
+
|
93
109
|
## Usage
|
94
110
|
|
95
111
|
Include `CrudResponder` into your `ApplicationController` (or whatever base controller you have)
|
@@ -173,6 +189,44 @@ Now your controllers are skinny again! Also, you are forced to think in terms of
|
|
173
189
|
* Support for pure API controllers (which is much simplier)
|
174
190
|
* Testing
|
175
191
|
|
192
|
+
Note about pure API controllers. I already use this idea:
|
193
|
+
```ruby
|
194
|
+
# somewhere in base controller for API
|
195
|
+
protected
|
196
|
+
|
197
|
+
def result(object, method = :save, options = {})
|
198
|
+
method = :destroy if caller[0][/`.*'/][1..-2] == 'destroy'
|
199
|
+
serializable_attrs = *options.fetch(:serializable_attrs, :id)
|
200
|
+
if object.send method
|
201
|
+
object_json(object, serializable_attrs)
|
202
|
+
respond_with object, location: (method == :destroy ? nil : object_url(object))
|
203
|
+
else
|
204
|
+
fail UnprocessableEntityError, object.errors.full_messages.to_sentence
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def object_url(object)
|
209
|
+
polymorphic_url(object)
|
210
|
+
rescue NoMethodError
|
211
|
+
"there is no show route for #{object.class.name} object"
|
212
|
+
end
|
213
|
+
|
214
|
+
def object_json(object, serializable_attrs)
|
215
|
+
object.instance_exec(serializable_attrs) do |attrs|
|
216
|
+
@_s_attrs = attrs
|
217
|
+
def to_json(*) # don't want to return the whole object on create/update
|
218
|
+
hash = {}
|
219
|
+
@_s_attrs.each do |attr|
|
220
|
+
hash[attr] = try(attr) if try(attr)
|
221
|
+
end
|
222
|
+
hash.any? ? JSON.generate(hash) : ''
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
```
|
227
|
+
I'm thinking of extracting this as well plus adding support for [ActiveModelSerializers](https://github.com/rails-api/active_model_serializers).
|
228
|
+
Any feedback is welcome.
|
229
|
+
|
176
230
|
## Development
|
177
231
|
|
178
232
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/crud_responder.gemspec
CHANGED
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "rspec", "~> 3"
|
25
|
-
spec.add_dependency "railties", "
|
26
|
-
spec.add_dependency "actionpack", "
|
25
|
+
spec.add_dependency "railties", ">= 4", "< 5.1"
|
26
|
+
spec.add_dependency "actionpack", ">= 4", "< 5.1"
|
27
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crud_responder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Antonyan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,30 +56,42 @@ dependencies:
|
|
56
56
|
name: railties
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '4'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '5.1'
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
|
-
- - "
|
69
|
+
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
71
|
version: '4'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5.1'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: actionpack
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- - "
|
79
|
+
- - ">="
|
74
80
|
- !ruby/object:Gem::Version
|
75
81
|
version: '4'
|
82
|
+
- - "<"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '5.1'
|
76
85
|
type: :runtime
|
77
86
|
prerelease: false
|
78
87
|
version_requirements: !ruby/object:Gem::Requirement
|
79
88
|
requirements:
|
80
|
-
- - "
|
89
|
+
- - ">="
|
81
90
|
- !ruby/object:Gem::Version
|
82
91
|
version: '4'
|
92
|
+
- - "<"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '5.1'
|
83
95
|
description: Don't repeat object.save, object.update, object.destroy and flash[:alert],
|
84
96
|
flash[:notice] in every controller. Use action's name to decide what to do
|
85
97
|
email:
|
@@ -125,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
137
|
version: '0'
|
126
138
|
requirements: []
|
127
139
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.5.1
|
129
141
|
signing_key:
|
130
142
|
specification_version: 4
|
131
143
|
summary: DRY out your controler actions for CRUD operations with flash messages
|