snfoil-rails 1.1.1 → 1.1.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/snfoil/all/all_generator.rb +9 -2
  3. data/lib/generators/snfoil/context/context_generator.rb +7 -2
  4. data/lib/generators/snfoil/context/templates/context.erb +15 -1
  5. data/lib/generators/snfoil/controller/controller_generator.rb +7 -2
  6. data/lib/generators/snfoil/controller/templates/controller.erb +4 -4
  7. data/lib/generators/snfoil/{jsonapi_deserializer/jsonapi_deserializer_generator.rb → deserializer/deserializer_generator.rb} +20 -4
  8. data/lib/generators/snfoil/deserializer/templates/json.erb +15 -0
  9. data/lib/generators/snfoil/deserializer/templates/jsonapi.erb +15 -0
  10. data/lib/generators/snfoil/policy/policy_generator.rb +7 -2
  11. data/lib/generators/snfoil/policy/templates/policy.erb +10 -13
  12. data/lib/generators/snfoil/searcher/searcher_generator.rb +7 -2
  13. data/lib/generators/snfoil/searcher/templates/searcher.erb +6 -2
  14. data/lib/generators/snfoil/{jsonapi_serializer/jsonapi_serializer_generator.rb → serializer/serializer_generator.rb} +9 -4
  15. data/lib/generators/snfoil/serializer/templates/serializer.erb +18 -0
  16. data/lib/snfoil/rails/api/create.rb +1 -1
  17. data/lib/snfoil/rails/api/destroy.rb +1 -1
  18. data/lib/snfoil/rails/api/index.rb +1 -1
  19. data/lib/snfoil/rails/api/show.rb +1 -1
  20. data/lib/snfoil/rails/api/update.rb +1 -1
  21. data/lib/snfoil/rails/api_controller.rb +1 -1
  22. data/lib/snfoil/rails/concerns/inject_deserialized.rb +1 -1
  23. data/lib/snfoil/rails/concerns/inject_id.rb +1 -1
  24. data/lib/snfoil/rails/concerns/inject_include.rb +1 -1
  25. data/lib/snfoil/rails/concerns/inject_request_id.rb +1 -1
  26. data/lib/snfoil/rails/concerns/inject_request_params.rb +1 -1
  27. data/lib/snfoil/rails/concerns/process_pagination.rb +1 -1
  28. data/lib/snfoil/rails/engine.rb +1 -1
  29. data/lib/snfoil/rails/searcher.rb +1 -1
  30. data/lib/snfoil/rails/version.rb +2 -2
  31. metadata +8 -8
  32. data/lib/generators/snfoil/controller/templates/api_controller.erb +0 -14
  33. data/lib/generators/snfoil/jsonapi_deserializer/templates/jsonapi_deserializer.erb +0 -12
  34. data/lib/generators/snfoil/jsonapi_serializer/templates/jsonapi_serializer.erb +0 -20
  35. /data/lib/generators/snfoil/{jsonapi_deserializer → deserializer}/USAGE +0 -0
  36. /data/lib/generators/snfoil/{jsonapi_serializer → serializer}/USAGE +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2775609a8022b5d2ce38d53bc265f26e30504748235e93102b4e5197ffed9f3
4
- data.tar.gz: 7bd4df8cbd82f669857a26b373e923b71ee2e57f0b0cdd92fe7f1b11c515feb6
3
+ metadata.gz: 4a0c8626c47b7239591baba976eecbad1f19b3945c20d494f7c696c51c864c1b
4
+ data.tar.gz: 71d34c2b2a60a1cf30f7bd7e03bb9863a14a35de2172866f9f9b9b3ec197b885
5
5
  SHA512:
6
- metadata.gz: 3293333e0b487dd54d2428b79ec1140a5a9bb9cb6f9b1f4da4dc1722f1cb4c2dfc36903f4c690878a63ec3a0e0ff41b275a00c9ae7ca1c501a82724c5cff4cc4
7
- data.tar.gz: d7f6c54c4a3e1280cf92087dae0faed02d243ed033b33a4ecc2d8a44dfc121558e1fd71a09f5de3068d6a98c7dde719400bc1965edb2946b8b60291b69495330
6
+ metadata.gz: cdd56a1d2f025ebbb8badc3ebbbf411359d3bd7a5aa35e95adedfcacb147bc5754fb82a09d8a07135d9e33878df947bc11d4b6491ca2eda3c87124333a5441b7
7
+ data.tar.gz: 350c57c9e5617ef2336a2dd1e85e25dd3526937bec46d546116849db1ed2b84e062d02d02473c0e1d781fb7963c1f7760651d47b0d55f0aaf6314d37ad72fb77
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,7 +15,12 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module SnFoil
18
- class AllGenerator < Rails::Generators::Base
18
+ class AllGenerator < ::Rails::Generators::Base
19
+ def self.base_name
20
+ 'snfoil'
21
+ end
22
+
23
+ namespace 'snfoil:all'
19
24
  source_root File.expand_path('templates', __dir__)
20
25
 
21
26
  argument :model, type: :string
@@ -24,6 +29,8 @@ module SnFoil
24
29
  class_option(:skip_model, desc: 'Skip Model Creation', type: :boolean, default: false)
25
30
 
26
31
  def add_model
32
+ return if options[:skip_model]
33
+
27
34
  rails_command "generate model #{call_args.join(' ')}", call_options
28
35
  end
29
36
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,7 +15,12 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module SnFoil
18
- class ContextGenerator < Rails::Generators::Base
18
+ class ContextGenerator < ::Rails::Generators::Base
19
+ def self.base_name
20
+ 'snfoil'
21
+ end
22
+
23
+ namespace 'snfoil:context'
19
24
  source_root File.expand_path('templates', __dir__)
20
25
 
21
26
  argument :model, type: :string
@@ -1,9 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class <%= class_modules %><%= class_name %>Context
4
- include SnFoil::Context
4
+ include SnFoil::CRUD::Context
5
5
 
6
6
  model <%= class_name %>
7
7
  searcher <%= class_name.pluralize %>Searcher
8
8
  policy <%= class_name %>Policy
9
+
10
+ # #create #update #destroy #show #index are already defined by SnFoil::CRUD::Context
11
+ # you can override their behavior by editing their hooks. Example:
12
+ # after_create do |options|
13
+ # # do something after create
14
+ # options # return options in hooks
15
+ # end
16
+ #
17
+ # or you can define your own workflows
18
+ # action :expire do |options|
19
+ # # expire the object
20
+ #
21
+ # options
22
+ # end
9
23
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,7 +15,12 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module SnFoil
18
- class ControllerGenerator < Rails::Generators::Base
18
+ class ControllerGenerator < ::Rails::Generators::Base
19
+ def self.base_name
20
+ 'snfoil'
21
+ end
22
+
23
+ namespace 'snfoil:controller'
19
24
  source_root File.expand_path('templates', __dir__)
20
25
 
21
26
  argument :model, type: :string
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class <%= class_modules %><%= class_name %>Controller < SnFoil::Controller::Base
4
- context <%= name.singularize.camelcase %>Context
5
- serializer <%= name.singularize.camelcase %>JsonapiSerializer
6
- deserializer <%= name.singularize.camelcase %>JsonapiDeserializer
3
+ class <%= class_modules %><%= class_name %>Controller < SnFoil::Rails::APIController
4
+ context <%= class_name.singularize %>Context
5
+ serializer <%= class_name.singularize %>Serializer
6
+ deserializer <%= class_name.singularize %>Deserializer
7
7
 
8
8
  # SnFoil::Controller requires current_entity or current_user defined to properly scope
9
9
  # all queries, otherwise data leaks could occur
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,12 +15,18 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module SnFoil
18
- class JsonapiDeserializerGenerator < Rails::Generators::Base
18
+ class DeserializerGenerator < ::Rails::Generators::Base
19
+ def self.base_name
20
+ 'snfoil'
21
+ end
22
+
23
+ namespace 'snfoil:deserializer'
19
24
  source_root File.expand_path('templates', __dir__)
20
25
 
21
26
  argument :model, type: :string
22
27
 
23
- class_option :path, desc: 'Base path for file', type: :string, default: 'app/jsonapi_deserializers'
28
+ class_option :type, desc: 'Generate JSON or JSONAPI deserializer', type: :string, default: 'json'
29
+ class_option :path, desc: 'Base path for file', type: :string, default: 'app/deserializers'
24
30
 
25
31
  def add_app_file
26
32
  file_name = if modules.empty?
@@ -29,7 +35,7 @@ module SnFoil
29
35
  "#{modules.join('/')}/#{name}"
30
36
  end
31
37
 
32
- template('jsonapi_deserializer.erb', "#{options[:path]}/#{file_name}_jsonapi_deserializer.rb")
38
+ template('deserializer.erb', "#{options[:path]}/#{file_name}_deserializer.rb")
33
39
  end
34
40
 
35
41
  private
@@ -38,6 +44,16 @@ module SnFoil
38
44
  @name ||= model.split('/').last.underscore.singularize
39
45
  end
40
46
 
47
+ def template_name
48
+ @template_name ||= if options[:type] == 'json'
49
+ 'json.erb'
50
+ elsif options[:type] == 'jsonapi'
51
+ 'jsonapi.erb'
52
+ else
53
+ raise ArgumentError, "Unknown deserializer type: #{options[:type]}"
54
+ end
55
+ end
56
+
41
57
  def class_name
42
58
  @class_name ||= name.camelize
43
59
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= class_modules %><%= class_name %>Deserializer
4
+ include SnFoil::Deserializer::JSON
5
+
6
+ # Underline the keys in the payload
7
+ key_transform :underscore
8
+
9
+ # Add attributes of the model you want to serializer with the following syntax
10
+ attributes :id
11
+
12
+ # Add relationships with the following syntax
13
+ # belongs_to :store, serializer: StoreSerializer
14
+ # has_many :locations, serializer: LocationSerializer
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= class_modules %><%= class_name %>Deserializer
4
+ include SnFoil::Deserializer::JSONAPI
5
+
6
+ # Underline the keys in the payload
7
+ key_transform :underscore
8
+
9
+ # Add attributes of the model you want to serializer with the following syntax
10
+ attributes :id
11
+
12
+ # Add relationships with the following syntax
13
+ # belongs_to :store, serializer: StoreSerializer
14
+ # has_many :locations, serializer: LocationSerializer
15
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,7 +15,12 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module SnFoil
18
- class PolicyGenerator < Rails::Generators::Base
18
+ class PolicyGenerator < ::Rails::Generators::Base
19
+ def self.base_name
20
+ 'snfoil'
21
+ end
22
+
23
+ namespace 'snfoil:policy'
19
24
  source_root File.expand_path('templates', __dir__)
20
25
 
21
26
  argument :model, type: :string
@@ -2,21 +2,18 @@
2
2
 
3
3
  class <%= class_modules %><%= class_name %>Policy
4
4
  include SnFoil::Policy
5
- # A SnFoil::Policy is just a Pundit policy (https://github.com/varvet/pundit)
6
- # with some defaults
7
- # Available methods: show?, create?, update?, destroy?, index?, associate?
8
5
 
9
- # def show?
10
- # true
11
- # end
6
+ # Example policy for <%= class_name %> entity.
7
+ # permission :create?, with: :active_and_owner?
12
8
 
13
- # class Scope
14
- # # available read-only attributes
15
- # # - scope: the default scope passed into the policy (ex: an ActiveRecord::Relation)
16
- # # - entity: the object that the scope is build around (ex: a User)
9
+ # permission :update?, with: :active_and_owner?
17
10
 
18
- # def resolve
19
- # # the new default scope
20
- # end
11
+ # permission :destroy? do
12
+ # entity.archived_at.nil? &&
13
+ # (record.user_id == entity.id || entity.is_admin?)
14
+ # end
15
+
16
+ # def active_and_owner?
17
+ # entity.archived_at.nil? && record.user_id == entity.id
21
18
  # end
22
19
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,7 +15,12 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module SnFoil
18
- class SearcherGenerator < Rails::Generators::Base
18
+ class SearcherGenerator < ::Rails::Generators::Base
19
+ def self.base_name
20
+ 'snfoil'
21
+ end
22
+
23
+ namespace 'snfoil:searcher'
19
24
  source_root File.expand_path('templates', __dir__)
20
25
 
21
26
  argument :model, type: :string
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class <%= class_modules %><%= class_name %>Searcher
4
- include SnFoil::Searcher
4
+ include SnFoil::Rails::Searcher
5
5
 
6
6
  model <%= class_name.singularize %>
7
- end
7
+
8
+ # filter do |scope, params|
9
+ # scope.where(archived_at: nil)
10
+ # end
11
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,12 +15,17 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module SnFoil
18
- class JsonapiSerializerGenerator < Rails::Generators::Base
18
+ class SerializerGenerator < ::Rails::Generators::Base
19
+ def self.base_name
20
+ 'snfoil'
21
+ end
22
+
23
+ namespace 'snfoil:serializer'
19
24
  source_root File.expand_path('templates', __dir__)
20
25
 
21
26
  argument :model, type: :string
22
27
 
23
- class_option :path, desc: 'Base path for file', type: :string, default: 'app/jsonapi_serializers'
28
+ class_option :path, desc: 'Base path for file', type: :string, default: 'app/serializers'
24
29
 
25
30
  def add_app_file
26
31
  file_name = if modules.empty?
@@ -29,7 +34,7 @@ module SnFoil
29
34
  "#{modules.join('/')}/#{name}"
30
35
  end
31
36
 
32
- template('jsonapi_serializer.erb', "#{options[:path]}/#{file_name}_jsonapi_serializer.rb")
37
+ template('serializer.erb', "#{options[:path]}/#{file_name}_serializer.rb")
33
38
  end
34
39
 
35
40
  private
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= class_modules %><%= class_name %>Serializer
4
+ # SnFoil no longer ships with a serializer, it is recommended to use your favorite and implement
5
+ # the serialize method in your controller.
6
+ #
7
+ # example: Blueprinter
8
+ # class <%= class_modules %><%= class_name %>Serializer < Blueprinter::Base
9
+ # identifier :id
10
+ # fields :name, :description, :created_at, :updated_at
11
+ # end
12
+ #
13
+ # example: Alba
14
+ # class <%= class_modules %><%= class_name %>Serializer
15
+ # include Alba::Resource
16
+ # attributes :id, :name, :description, :created_at, :updated_at
17
+ # end
18
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2021 Matthew Howes
3
+ # Copyright 2025 Matthew Howes
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -16,6 +16,6 @@
16
16
 
17
17
  module SnFoil
18
18
  module Rails
19
- VERSION = '1.1.1'
19
+ VERSION = '1.1.4'
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snfoil-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Howes
@@ -87,20 +87,20 @@ files:
87
87
  - lib/generators/snfoil/context/templates/context.erb
88
88
  - lib/generators/snfoil/controller/USAGE
89
89
  - lib/generators/snfoil/controller/controller_generator.rb
90
- - lib/generators/snfoil/controller/templates/api_controller.erb
91
90
  - lib/generators/snfoil/controller/templates/controller.erb
92
- - lib/generators/snfoil/jsonapi_deserializer/USAGE
93
- - lib/generators/snfoil/jsonapi_deserializer/jsonapi_deserializer_generator.rb
94
- - lib/generators/snfoil/jsonapi_deserializer/templates/jsonapi_deserializer.erb
95
- - lib/generators/snfoil/jsonapi_serializer/USAGE
96
- - lib/generators/snfoil/jsonapi_serializer/jsonapi_serializer_generator.rb
97
- - lib/generators/snfoil/jsonapi_serializer/templates/jsonapi_serializer.erb
91
+ - lib/generators/snfoil/deserializer/USAGE
92
+ - lib/generators/snfoil/deserializer/deserializer_generator.rb
93
+ - lib/generators/snfoil/deserializer/templates/json.erb
94
+ - lib/generators/snfoil/deserializer/templates/jsonapi.erb
98
95
  - lib/generators/snfoil/policy/USAGE
99
96
  - lib/generators/snfoil/policy/policy_generator.rb
100
97
  - lib/generators/snfoil/policy/templates/policy.erb
101
98
  - lib/generators/snfoil/searcher/USAGE
102
99
  - lib/generators/snfoil/searcher/searcher_generator.rb
103
100
  - lib/generators/snfoil/searcher/templates/searcher.erb
101
+ - lib/generators/snfoil/serializer/USAGE
102
+ - lib/generators/snfoil/serializer/serializer_generator.rb
103
+ - lib/generators/snfoil/serializer/templates/serializer.erb
104
104
  - lib/snfoil/rails.rb
105
105
  - lib/snfoil/rails/api/create.rb
106
106
  - lib/snfoil/rails/api/destroy.rb
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class <%= class_modules %><%= class_name %>Controller < SnFoil::Controller::API
4
- context <%= class_name.singularize %>Context
5
- serializer <%= class_name.singularize %>JsonapiSerializer
6
- deserializer <%= class_name.singularize %>JsonapiDeserializer
7
-
8
- # SnFoil::Controller requires current_entity or current_user defined to properly scope
9
- # all queries, otherwise data leaks could occur
10
- #
11
- # def current_entity
12
- # # logic to find authenticated user
13
- # end
14
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class <%= class_modules %><%= class_name %>JsonapiDeserializer
4
- include SnFoil::JsonapiDeserializer
5
-
6
- # Add attributes of the model you want to serializer with the following syntax
7
- attributes :id
8
-
9
- # Add relationships with the following syntax
10
- # belongs_to :store, serializer: Jsonapi::StoreJsonapiSerializer
11
- # has_many :locations, serializer: Jsonapi::LocationJsonapiSerializer
12
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class <%= class_modules %><%= class_name %>JsonapiSerializer
4
- include SnFoil::JsonapiSerializer
5
-
6
- set_id :id
7
- set_type :<%= name.pluralize.dasherize %>
8
-
9
- # SnFoil::JsonapiSerializer is just a wrapper for jsonapi-serializer (https://github.com/jsonapi-serializer/jsonapi-serializer)
10
- # with some defaults added in
11
-
12
- # Add attributes of the model you want to serializer with the following syntax
13
- # attributes :name
14
- # :description
15
- # :logo_url
16
-
17
- # Add relationships with the following syntax
18
- # belongs_to :store, serializer: Jsonapi::StoreJsonapiSerializer
19
- # has_many :locations, serializer: Jsonapi::LocationJsonapiSerializer
20
- end