acts_responsible 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/acts_responsible.rb +19 -0
- data/lib/acts_responsible/core.rb +42 -0
- data/lib/acts_responsible/templates/application/_error.json.rabl +3 -0
- data/lib/acts_responsible/templates/application/response.json.rabl +11 -0
- data/lib/acts_responsible/version.rb +3 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1669e05d3269e0ffb9b5ecf35ba727f571e09c1a
|
4
|
+
data.tar.gz: c57a006f18a768035260dd372a8f3bcb7520ef4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ecdfbf7202c1d6a6fa957b1248a38a590a92c871119b39f4ea6b0c8d5e8ded595a05fe0b582c743694f8eb78244b21adde55814e23ce0560f94f770e24dd7fc
|
7
|
+
data.tar.gz: 82e560c6615670f6c0fa32a9fa461827517fe7a4a4106e12ecbc8f504d86d48ab68bd055d6b6e7f3fc42452b8621413659bcfd2a468cf7ac32087564c69f4d8d
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Daniel Lichty
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# ActsResponsible
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'acts_responsible'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install acts_responsible
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/acts_responsible/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'acts_responsible/core'
|
2
|
+
|
3
|
+
module ActsResponsible
|
4
|
+
def responsible?
|
5
|
+
self.included_modules.include?(ActsResponsible::Core)
|
6
|
+
end
|
7
|
+
|
8
|
+
def acts_responsible(prefix)
|
9
|
+
class_attribute :responsible_config
|
10
|
+
|
11
|
+
self.responsible_config = { prefix: prefix }
|
12
|
+
|
13
|
+
return if responsible?
|
14
|
+
|
15
|
+
include ActsResponsible::Core
|
16
|
+
|
17
|
+
append_view_path(File.dirname(__FILE__) + '/acts_responsible/templates')
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ActsResponsible
|
2
|
+
module Core
|
3
|
+
|
4
|
+
def render_response(data, data_key, template, options={})
|
5
|
+
prefix = self.responsible_config[:prefix]
|
6
|
+
|
7
|
+
@responsibility ||= {}
|
8
|
+
@responsibility.merge!({
|
9
|
+
data_key: data_key,
|
10
|
+
data: data,
|
11
|
+
metadata: options.delete(:meta),
|
12
|
+
partial: "#{prefix}/#{template}"
|
13
|
+
})
|
14
|
+
render "response", options
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_empty_response(options={})
|
18
|
+
render_response(nil, nil, nil, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def render_error(status, errors=[], options={})
|
22
|
+
@responsibility ||= {}
|
23
|
+
response_errors = []
|
24
|
+
|
25
|
+
if errors.is_a? ActiveModel::Errors
|
26
|
+
errors.keys.each do |field|
|
27
|
+
errors.full_messages_for(field).each do |message|
|
28
|
+
response_errors << {field: field, detail: message}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
response_errors = Array.wrap(errors)
|
33
|
+
end
|
34
|
+
|
35
|
+
@responsibility[:errors] = response_errors
|
36
|
+
|
37
|
+
options[:status] = status
|
38
|
+
render_empty_response options
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
node 'meta' do
|
2
|
+
@responsibility[:metadata]
|
3
|
+
end if @responsibility[:metadata].present? && @responsibility[:metadata].is_a?(Hash)
|
4
|
+
|
5
|
+
node(@responsibility[:data_key] || 'data') do
|
6
|
+
partial @responsibility[:partial], object: @responsibility[:data]
|
7
|
+
end if @responsibility[:data] && @responsibility[:partial]
|
8
|
+
|
9
|
+
node 'errors' do
|
10
|
+
partial 'application/error', object: @responsibility[:errors]
|
11
|
+
end if @responsibility[:errors].present?
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_responsible
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Lichty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
description: Use your own models' custom RABL templates and render JSON responses
|
42
|
+
that follow the structure set out by JSON API (jsonapi.org).
|
43
|
+
email:
|
44
|
+
- dan@lichty.ca
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/acts_responsible.rb
|
53
|
+
- lib/acts_responsible/core.rb
|
54
|
+
- lib/acts_responsible/templates/application/_error.json.rabl
|
55
|
+
- lib/acts_responsible/templates/application/response.json.rabl
|
56
|
+
- lib/acts_responsible/version.rb
|
57
|
+
homepage: http://rubygems.org/gems/acts_responsible
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.4.1
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: JSON API-(jsonapi.org)-compliant rendering of RABL templates
|
81
|
+
test_files: []
|