dry_crud_jsonapi 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -4
- data/app/domain/dry_crud_jsonapi/serializer.rb +6 -13
- data/lib/dry_crud_jsonapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ba9fed331231bc710503c905431aa7d91d4f6531043d46facc3c861880b2b61
|
4
|
+
data.tar.gz: 0df2ef97101b003ce94691d59ed8eb7c1a83a9bdab1d3ee0c4c07d16783a27f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 104efeb700cdeb4a476849522c0860ce26f53f78f8529775f1faaf4869e7e52a452cf5e209ad5457eb2197244283c333435df22efb9df07eaa4d1b069bac0321
|
7
|
+
data.tar.gz: b57b228afd04b38d7b8f7d611c059cc632896599d00ceba872cdf5151529b882fd698076dacf21c32aa3f39c81ad96415fc1f55e57e5edb6947640ae58240be5
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# DryCrudJsonapi
|
2
2
|
|
3
|
-
|
3
|
+
This Gem adds a json:api to a rails application which is build with [`dry_crud`].
|
4
4
|
|
5
|
-
|
5
|
+
Currently only read operations are implmeneted.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,21 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Include the module `DryCrudJsonapi` in all controller you want to expose on the json:api
|
26
|
+
|
27
|
+
class EmployeesController < CrudController
|
28
|
+
include DryCrudJsonapi
|
29
|
+
|
30
|
+
...
|
31
|
+
end
|
32
|
+
|
33
|
+
The controller must implement (or inherit) at least the following methods:
|
34
|
+
|
35
|
+
* `model_class`
|
36
|
+
* `entry`
|
37
|
+
* `entries`
|
38
|
+
|
39
|
+
Consult the [`dry_crud`] sourcecode about how these work, or just inherit your controller from `dry_crud`'s `CrudController`.
|
26
40
|
|
27
41
|
## Development
|
28
42
|
|
@@ -32,8 +46,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
46
|
|
33
47
|
## Contributing
|
34
48
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/puzzle/dry_crud_jsonapi.
|
36
50
|
|
37
51
|
## License
|
38
52
|
|
39
53
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
54
|
+
|
55
|
+
|
56
|
+
[`dry_crud`]: https://github.com/codez/dry_crud
|
@@ -44,7 +44,7 @@ module DryCrudJsonapi
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def define_has_one_relations
|
47
|
-
reflections(
|
47
|
+
reflections(:has_one).each do |reflection|
|
48
48
|
define_conditional(:has_one, reflection.name.to_s) do
|
49
49
|
data { @object.send(reflection.name) }
|
50
50
|
end
|
@@ -52,7 +52,7 @@ module DryCrudJsonapi
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def define_belongs_to_relations
|
55
|
-
reflections(
|
55
|
+
reflections(:belongs_to).each do |reflection|
|
56
56
|
define_conditional(:belongs_to, reflection.name.to_s) do
|
57
57
|
data { @object.send(reflection.name) }
|
58
58
|
end
|
@@ -60,11 +60,10 @@ module DryCrudJsonapi
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def define_has_many_relations(type)
|
63
|
-
reflections(
|
63
|
+
reflections(type).each do |reflection|
|
64
64
|
define_conditional(:has_many, reflection.name) do
|
65
|
-
|
66
|
-
|
67
|
-
end
|
65
|
+
path = @controller.rescued_polymorphic_path([@object, reflection.name])
|
66
|
+
link(:related) { path } if path
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
@@ -80,15 +79,9 @@ module DryCrudJsonapi
|
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
83
|
-
def for_type(type)
|
84
|
-
"ActiveRecord::Reflection::#{type.to_s.camelcase}Reflection".constantize
|
85
|
-
end
|
86
|
-
|
87
82
|
def reflections(type)
|
88
83
|
@reflections ||= {}
|
89
|
-
@reflections[type] ||= model_class.reflect_on_all_associations
|
90
|
-
reflection.is_a?(type)
|
91
|
-
end
|
84
|
+
@reflections[type] ||= model_class.reflect_on_all_associations(type)
|
92
85
|
end
|
93
86
|
end
|
94
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry_crud_jsonapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Illi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|