shaf 2.1.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/shaf/app.rb +27 -9
  4. data/lib/shaf/command/base.rb +4 -0
  5. data/lib/shaf/command/new.rb +5 -1
  6. data/lib/shaf/command/server.rb +5 -1
  7. data/lib/shaf/command/templates/config/settings.yml.erb +9 -8
  8. data/lib/shaf/extensions/resource_uris.rb +37 -155
  9. data/lib/shaf/extensions/symbolic_routes.rb +5 -18
  10. data/lib/shaf/formable/builder.rb +58 -19
  11. data/lib/shaf/formable/form.rb +13 -10
  12. data/lib/shaf/formable.rb +10 -23
  13. data/lib/shaf/generator/base.rb +82 -0
  14. data/lib/shaf/generator/controller.rb +19 -35
  15. data/lib/shaf/generator/forms.rb +10 -14
  16. data/lib/shaf/generator/migration/add_column.rb +0 -4
  17. data/lib/shaf/generator/migration/add_index.rb +0 -4
  18. data/lib/shaf/generator/migration/base.rb +8 -0
  19. data/lib/shaf/generator/migration/create_table.rb +0 -4
  20. data/lib/shaf/generator/migration/drop_column.rb +0 -4
  21. data/lib/shaf/generator/migration/rename_column.rb +0 -4
  22. data/lib/shaf/generator/model.rb +29 -14
  23. data/lib/shaf/generator/policy.rb +8 -14
  24. data/lib/shaf/generator/profile.rb +9 -14
  25. data/lib/shaf/generator/scaffold.rb +6 -9
  26. data/lib/shaf/generator/serializer.rb +31 -30
  27. data/lib/shaf/generator/templates/api/controller.rb.erb +13 -13
  28. data/lib/shaf/generator/templates/api/forms.rb.erb +2 -2
  29. data/lib/shaf/generator/templates/api/model.rb.erb +1 -1
  30. data/lib/shaf/generator/templates/api/profile.rb.erb +1 -1
  31. data/lib/shaf/generator/templates/api/serializer.rb.erb +1 -1
  32. data/lib/shaf/generator/templates/spec/integration_spec.rb.erb +14 -14
  33. data/lib/shaf/helpers/paginate.rb +1 -1
  34. data/lib/shaf/link_relations.rb +77 -0
  35. data/lib/shaf/profile.rb +8 -8
  36. data/lib/shaf/registrable_factory.rb +62 -32
  37. data/lib/shaf/responder/problem_json.rb +1 -1
  38. data/lib/shaf/router.rb +65 -12
  39. data/lib/shaf/spec/integration_spec.rb +1 -1
  40. data/lib/shaf/tasks.rb +0 -1
  41. data/lib/shaf/upgrade/package.rb +5 -7
  42. data/lib/shaf/utils.rb +2 -2
  43. data/lib/shaf/version.rb +1 -1
  44. data/lib/shaf/yard/link_object.rb +2 -3
  45. data/templates/Rakefile +0 -6
  46. data/templates/api/controllers/base_controller.rb +0 -2
  47. data/templates/api/serializers/root_serializer.rb +0 -11
  48. data/templates/config/initializers/middleware.rb +6 -0
  49. data/templates/spec/spec_helper.rb +4 -1
  50. data/upgrades/3.0.0.tar.gz +0 -0
  51. data/yard_templates/api_doc/profile_attribute/html/attribute.erb +2 -1
  52. data/yard_templates/api_doc/resource_attribute/html/attribute.erb +2 -1
  53. data/yard_templates/api_doc/sidebar/html/profile_list.erb +2 -1
  54. data/yard_templates/api_doc/sidebar/html/serializer_list.erb +2 -1
  55. data.tar.gz.sig +0 -0
  56. metadata +34 -36
  57. metadata.gz.sig +0 -0
  58. data/lib/shaf/api_doc/comment.rb +0 -27
  59. data/lib/shaf/api_doc/document.rb +0 -137
  60. data/lib/shaf/api_doc/link_relations.rb +0 -77
  61. data/lib/shaf/middleware.rb +0 -1
  62. data/lib/shaf/tasks/api_doc_task.rb +0 -146
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'net/http'
4
- require 'tempfile'
5
- require 'uri'
6
- require 'csv'
7
-
8
- module Shaf
9
- module ApiDoc
10
- class LinkRelations
11
- class LinkRelation
12
- attr_reader :name, :description, :reference, :notes
13
-
14
- def initialize(name, description, reference, notes)
15
- @name = name.to_sym
16
- @description = description.freeze
17
- @reference = reference.freeze
18
- @notes = notes.freeze
19
- end
20
- end
21
-
22
- class << self
23
- IANA_URL = URI('https://www.iana.org/assignments/link-relations/link-relations-1.csv')
24
-
25
- def all
26
- relations.values
27
- end
28
-
29
- def [](key)
30
- relations[key]
31
- end
32
-
33
- def []=(key, value)
34
- relations[key] = value
35
- end
36
-
37
- def add(link_relation)
38
- relations[link_relation.name] = link_relation
39
- end
40
-
41
- def load_iana
42
- csv.each do |name, desc, ref, notes|
43
- next if name == 'Relation Name'
44
- add LinkRelation.new(name, desc, ref, notes)
45
- end
46
- end
47
-
48
- private
49
-
50
- def relations
51
- @relations ||= {}
52
- end
53
-
54
- def tmp_file_name
55
- File.join(Dir.tmpdir, 'shaf_iana_link_relations')
56
- end
57
-
58
- def csv
59
- if File.readable? tmp_file_name
60
- content = File.read(tmp_file_name)
61
- return CSV.new(content)
62
- end
63
-
64
- response = Net::HTTP.get_response(IANA_URL)
65
-
66
- if response.code.to_i == 200
67
- content = response.body
68
- File.open(tmp_file_name, 'w') { |file| file.write(content) }
69
- CSV.new(content)
70
- else
71
- Utils.iana_link_relations_csv
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1 +0,0 @@
1
- require 'shaf/middleware/request_id'
@@ -1,146 +0,0 @@
1
- module Shaf
2
- module Tasks
3
- class ApiDocTask
4
- include Rake::DSL
5
-
6
- attr_accessor :document_class, :source_dir, :html_output_dir, :yaml_output_dir
7
-
8
- def initialize
9
- return show_deprecation_message if RUBY_VERSION >= '3.0.0'
10
-
11
- require 'shaf/api_doc/document'
12
- require 'shaf/api_doc/comment'
13
-
14
- yield self if block_given?
15
- validate_attributes!
16
- @document_class ||= ApiDoc::Document
17
- define_tasks
18
- end
19
-
20
- def validate_attributes!
21
- raise "source_dir must be set!" unless source_dir
22
- raise "html_output_dir must be configured in ApiDocTask" unless html_output_dir
23
- raise "yaml_output_dir must be configured in ApiDocTask" unless yaml_output_dir
24
- end
25
-
26
- def define_tasks
27
- namespace :doc do
28
- desc "Generate API documentation"
29
- task :generate do
30
- show_deprecation_message
31
-
32
- files = Dir.glob(File.join(source_dir, "*.rb"))
33
- files.each do |file|
34
- read_file file do |doc|
35
- next unless doc.valid?
36
- doc.write_html @html_output_dir
37
- doc.write_yaml @yaml_output_dir
38
- end
39
- end
40
- end
41
-
42
- desc "Remove generated documentation"
43
- task :clean do
44
- [
45
- Dir.glob(File.join(@yaml_output_dir, "*.yml")),
46
- Dir.glob(File.join(@html_output_dir, "*.html"))
47
- ].flatten.each do |file|
48
- File.unlink file
49
- end
50
- end
51
- end
52
- end
53
-
54
- def show_deprecation_message
55
- ruby3_msg = <<~RUBY3 if RUBY_VERSION >= '3.0.0'
56
-
57
- Due to errors with the Redcarpet gem it's not possible to use this deprecated rake task with Ruby >= 3.0.0
58
- If you need to continue with this task please use an older version of Ruby.
59
- RUBY3
60
-
61
- puts <<~MSG
62
- This way of generating documentation is DEPRECATED.#{ruby3_msg}
63
-
64
- Please move the documentation comments into profiles instead and run:
65
- shaf generate doc
66
- See https://github.com/sammyhenningsson/shaf/blob/main/doc/DOCUMENTATION.md for more info
67
-
68
- MSG
69
- end
70
-
71
- def read_file(file)
72
- doc = document_class.new
73
- comment = ApiDoc::Comment.new
74
-
75
- File.readlines(file).each do |line|
76
- next if empty_line?(line)
77
-
78
- if c = comment(line)
79
- comment << c
80
- next
81
- end
82
-
83
- parse_line(line, doc, comment)
84
- comment = ApiDoc::Comment.new
85
- end
86
-
87
- return doc unless block_given?
88
- yield doc
89
- end
90
-
91
- def parse_line(line, doc, comment)
92
- if model = model(line)
93
- doc.model = model
94
- elsif serializer_class = serializer_class(line)
95
- doc.serializer_class = serializer_class
96
- elsif policy = policy(line)
97
- doc.policy = policy
98
- elsif attr = attribute(line)
99
- doc.attribute(attr, comment)
100
- elsif rel = link(line)
101
- doc.link(rel, comment)
102
- elsif rel = curie(line)
103
- doc.curie(rel, comment)
104
- elsif name = embed(line)
105
- doc.embedded(name, comment)
106
- end
107
- end
108
-
109
- def empty_line?(line)
110
- true if line[/\A[#\s*]*\Z/]
111
- end
112
-
113
- def serializer_class(line)
114
- line[/\A\s*class\s*(\w+)\Z/, 1]
115
- end
116
-
117
- def model(line)
118
- line[/\A\s*model\s*(?:::)?(\w+)/, 1]
119
- end
120
-
121
- def policy(line)
122
- line[/\A\s*policy\s*(?:::)?(\w+)/, 1]
123
- end
124
-
125
- def comment(line)
126
- line[/\A\s*#(.*)/, 1]
127
- end
128
-
129
- def attribute(line)
130
- line[/\A\s*attribute\s+\(?:(\w+)/, 1]
131
- end
132
-
133
- def link(line)
134
- line[/\A\s*link\s+\(?:?['"]?([-:\w]+)['"]?/, 1]
135
- end
136
-
137
- def curie(line)
138
- line[/\A\s*curie\s+\(?:'?([-\w]+)'?/, 1]
139
- end
140
-
141
- def embed(line)
142
- line[/\A\s*embed\s+\(?:'?([-:\w]+)'?/, 1]
143
- end
144
- end
145
- end
146
- end