dry_crud_jsonapi 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1490f7eb09162ab497f07102570cb567d8cc78a65cadef8355ec15035ec4ed9c
4
- data.tar.gz: 8b276f30b7e1d35b7beea7b45e5b2f0a948dd840c5666856df8830b463fac9d0
3
+ metadata.gz: 3ba9fed331231bc710503c905431aa7d91d4f6531043d46facc3c861880b2b61
4
+ data.tar.gz: 0df2ef97101b003ce94691d59ed8eb7c1a83a9bdab1d3ee0c4c07d16783a27f8
5
5
  SHA512:
6
- metadata.gz: 3a0fb63797bc84039904c6746beac40d3d45442c111b8315e3fc4c09db2576fb4545e8a95ff5ff9e49063dcf20617bd2d021c7404b764263a4b4789fa5fe4f0e
7
- data.tar.gz: 0cfc9a0403b4f8e635b064a1d1901bd35dd009d33a2f20caab7121af86ddd38c81b5608dde3d6f819deca8651b389c65b077ac4a6ffe3b4bf5791597f8e744f7
6
+ metadata.gz: 104efeb700cdeb4a476849522c0860ce26f53f78f8529775f1faaf4869e7e52a452cf5e209ad5457eb2197244283c333435df22efb9df07eaa4d1b069bac0321
7
+ data.tar.gz: b57b228afd04b38d7b8f7d611c059cc632896599d00ceba872cdf5151529b882fd698076dacf21c32aa3f39c81ad96415fc1f55e57e5edb6947640ae58240be5
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # DryCrudJsonapi
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dry_crud_jsonapi`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This Gem adds a json:api to a rails application which is build with [`dry_crud`].
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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/dzubi/dry_crud_jsonapi.
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(for_type(:has_one)).each do |reflection|
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(for_type(:belongs_to)).each do |reflection|
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(for_type(type)).each do |reflection|
63
+ reflections(type).each do |reflection|
64
64
  define_conditional(:has_many, reflection.name) do
65
- link(:related) do
66
- @controller.rescued_polymorphic_path([@object, reflection.name])
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.select do |reflection|
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
@@ -1,3 +1,3 @@
1
1
  module DryCrudJsonapi
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  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.0
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-01-17 00:00:00.000000000 Z
11
+ date: 2019-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler