jsonapi-rails-generator 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +6 -0
- data/lib/generators/jsonapi/type/USAGE +5 -0
- data/lib/generators/jsonapi/type/templates/type.rb.erb +14 -0
- data/lib/generators/jsonapi/type/type_generator.rb +49 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8f2fcab7b51d4259694c600c95a910b168352ff4268572c541ccb757087ae76f
|
4
|
+
data.tar.gz: b20853e4353a68f4aa32e767884750d5ad73f1bb9ebea6e2c74e67891152e8b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d8605c960285bed206ea87cc3c99d3596c8a30961631b520a2a185aa77cf5f900a5f1f64876a9fd65b69ead3c04fc4f6a5bd29d45f63617e5a0ac5e60131eb6
|
7
|
+
data.tar.gz: ee4fe467b544522faee9c22f73952e04369646377d4d2bedf9f58fee1ff2af1051dce7df06511f213085ba3efab37bc8dd474b35185e49df0b2e2fe1e89223f0
|
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= serializable_class_name %> < JSONAPI::Resource
|
3
|
+
immutable
|
4
|
+
<% attr_names.each do |attr| -%>
|
5
|
+
attribute :<%= attr %>
|
6
|
+
<% end -%>
|
7
|
+
<% has_one_rel_names.each do |rel| -%>
|
8
|
+
has_one :<%= rel %>
|
9
|
+
<% end -%>
|
10
|
+
<% has_many_rel_names.each do |rel| -%>
|
11
|
+
has_many :<%= rel %>
|
12
|
+
<% end -%>
|
13
|
+
end
|
14
|
+
<% end -%>
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Jsonapi
|
2
|
+
class TypeGenerator < ::Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
# TODO(beauby): Implement generator-level whitelisting.
|
6
|
+
# TODO(beauby): Implement versioning.
|
7
|
+
|
8
|
+
def copy_serializable_file
|
9
|
+
template 'type.rb.erb',
|
10
|
+
File.join('app/resources', class_path,
|
11
|
+
"#{serializable_file_name}.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def serializable_file_name
|
17
|
+
"#{file_name}_resouce"
|
18
|
+
end
|
19
|
+
|
20
|
+
def serializable_class_name
|
21
|
+
(class_path + [serializable_file_name]).map!(&:camelize).join("::")
|
22
|
+
end
|
23
|
+
|
24
|
+
def model_klass
|
25
|
+
# TODO(beauby): Ensure the model class exists.
|
26
|
+
class_name.safe_constantize
|
27
|
+
end
|
28
|
+
|
29
|
+
def type
|
30
|
+
model_klass.model_name.plural
|
31
|
+
end
|
32
|
+
|
33
|
+
def attr_names
|
34
|
+
attrs = model_klass.new.attribute_names - ['id']
|
35
|
+
fk_attrs = model_klass.reflect_on_all_associations(:belongs_to)
|
36
|
+
.map(&:foreign_key)
|
37
|
+
attrs - fk_attrs
|
38
|
+
end
|
39
|
+
|
40
|
+
def has_one_rel_names
|
41
|
+
model_klass.reflect_on_all_associations(:has_one).map(&:name) +
|
42
|
+
model_klass.reflect_on_all_associations(:belongs_to).map(&:name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def has_many_rel_names
|
46
|
+
model_klass.reflect_on_all_associations(:has_many).map(&:name)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsonapi-rails-generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hooopo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.6
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '11.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '11.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: with_model
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Efficient, convenient, non-intrusive JSONAPI framework for Rails.
|
98
|
+
email:
|
99
|
+
- hoooopo@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- README.md
|
105
|
+
- lib/generators/jsonapi/type/USAGE
|
106
|
+
- lib/generators/jsonapi/type/templates/type.rb.erb
|
107
|
+
- lib/generators/jsonapi/type/type_generator.rb
|
108
|
+
homepage: https://github.com/jsonapi-rb/jsonapi-rails
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubygems_version: 3.0.3
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: jsonapi-resource integrations for Rails.
|
131
|
+
test_files: []
|