shaf 1.5.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/iana_link_relations.csv.gz +0 -0
  5. data/lib/shaf.rb +6 -0
  6. data/lib/shaf/alps/attribute_serializer.rb +41 -0
  7. data/lib/shaf/alps/json_serializer.rb +50 -0
  8. data/lib/shaf/alps/relation_serializer.rb +70 -0
  9. data/lib/shaf/api_doc/link_relations.rb +77 -0
  10. data/lib/shaf/app.rb +12 -5
  11. data/lib/shaf/authenticator.rb +56 -0
  12. data/lib/shaf/authenticator/base.rb +161 -0
  13. data/lib/shaf/authenticator/basic_auth.rb +25 -0
  14. data/lib/shaf/authenticator/challenge.rb +32 -0
  15. data/lib/shaf/authenticator/parameter.rb +31 -0
  16. data/lib/shaf/authenticator/request.rb +17 -0
  17. data/lib/shaf/command/console.rb +1 -1
  18. data/lib/shaf/command/generate.rb +5 -2
  19. data/lib/shaf/command/new.rb +20 -7
  20. data/lib/shaf/command/templates/Gemfile.erb +1 -0
  21. data/{templates/config/settings.yml → lib/shaf/command/templates/config/settings.yml.erb} +1 -5
  22. data/lib/shaf/errors.rb +11 -0
  23. data/lib/shaf/extensions.rb +3 -3
  24. data/lib/shaf/extensions/api_routes.rb +60 -0
  25. data/lib/shaf/extensions/authorize.rb +11 -9
  26. data/lib/shaf/extensions/log.rb +1 -1
  27. data/lib/shaf/extensions/resource_uris.rb +139 -63
  28. data/lib/shaf/extensions/symbolic_routes.rb +22 -19
  29. data/lib/shaf/formable.rb +1 -2
  30. data/lib/shaf/formable/form.rb +1 -1
  31. data/lib/shaf/generator.rb +2 -0
  32. data/lib/shaf/generator/base.rb +2 -3
  33. data/lib/shaf/generator/controller.rb +11 -7
  34. data/lib/shaf/generator/doc.rb +17 -0
  35. data/lib/shaf/generator/forms.rb +1 -0
  36. data/lib/shaf/generator/helper.rb +2 -1
  37. data/lib/shaf/generator/migration/base.rb +7 -3
  38. data/lib/shaf/generator/migration/type.rb +4 -26
  39. data/lib/shaf/generator/migration/types.rb +45 -16
  40. data/lib/shaf/generator/model.rb +1 -2
  41. data/lib/shaf/generator/profile.rb +52 -0
  42. data/lib/shaf/generator/serializer.rb +38 -73
  43. data/lib/shaf/generator/templates/api/policy.rb.erb +2 -2
  44. data/lib/shaf/generator/templates/api/profile.rb.erb +16 -0
  45. data/lib/shaf/generator/templates/api/serializer.rb.erb +2 -2
  46. data/lib/shaf/generator/templates/spec/integration_spec.rb.erb +1 -2
  47. data/lib/shaf/generator/templates/spec/serializer_spec.rb.erb +5 -5
  48. data/lib/shaf/helpers.rb +4 -0
  49. data/lib/shaf/helpers/authentication.rb +79 -0
  50. data/lib/shaf/helpers/cache_control.rb +1 -2
  51. data/lib/shaf/helpers/json_html.rb +58 -18
  52. data/lib/shaf/helpers/payload.rb +26 -41
  53. data/lib/shaf/helpers/vary.rb +8 -0
  54. data/lib/shaf/logger.rb +12 -0
  55. data/lib/shaf/parser.rb +65 -0
  56. data/lib/shaf/parser/base.rb +44 -0
  57. data/lib/shaf/parser/form_data.rb +15 -0
  58. data/lib/shaf/parser/json.rb +26 -0
  59. data/lib/shaf/profile.rb +115 -0
  60. data/lib/shaf/profile/attribute.rb +29 -0
  61. data/lib/shaf/profile/evaluator.rb +46 -0
  62. data/lib/shaf/profile/relation.rb +29 -0
  63. data/lib/shaf/profile/unique_id.rb +58 -0
  64. data/lib/shaf/profiles.rb +46 -0
  65. data/lib/shaf/profiles/shaf_basic.rb +20 -0
  66. data/lib/shaf/profiles/shaf_error.rb +49 -0
  67. data/lib/shaf/profiles/shaf_form.rb +110 -0
  68. data/lib/shaf/responder.rb +41 -2
  69. data/lib/shaf/responder/alps_json.rb +25 -0
  70. data/lib/shaf/responder/base.rb +20 -17
  71. data/lib/shaf/responder/hal.rb +63 -8
  72. data/lib/shaf/responder/html.rb +65 -9
  73. data/lib/shaf/responder/problem_json.rb +1 -1
  74. data/lib/shaf/serializer.rb +35 -0
  75. data/lib/shaf/settings.rb +25 -12
  76. data/lib/shaf/spec.rb +1 -0
  77. data/lib/shaf/spec/authenticator.rb +13 -0
  78. data/lib/shaf/spec/base.rb +1 -1
  79. data/lib/shaf/spec/http_method_utils.rb +1 -1
  80. data/lib/shaf/spec/integration_spec.rb +25 -13
  81. data/lib/shaf/spec/payload_utils.rb +2 -2
  82. data/lib/shaf/supported_http_methods.rb +15 -0
  83. data/lib/shaf/tasks/api_doc_task.rb +24 -3
  84. data/lib/shaf/tasks/routes_task.rb +14 -17
  85. data/lib/shaf/upgrade/manifest.rb +11 -2
  86. data/lib/shaf/upgrade/package.rb +78 -49
  87. data/lib/shaf/upgrade/version.rb +11 -10
  88. data/lib/shaf/utils.rb +19 -5
  89. data/lib/shaf/version.rb +3 -1
  90. data/lib/shaf/yard.rb +34 -0
  91. data/lib/shaf/yard/attribute_method_handler.rb +19 -0
  92. data/lib/shaf/yard/attribute_object.rb +30 -0
  93. data/lib/shaf/yard/base_method_handler.rb +30 -0
  94. data/lib/shaf/yard/link_method_handler.rb +39 -0
  95. data/lib/shaf/yard/link_object.rb +60 -0
  96. data/lib/shaf/yard/nested_attributes.rb +37 -0
  97. data/lib/shaf/yard/parser.rb +64 -0
  98. data/lib/shaf/yard/profile_method_handler.rb +51 -0
  99. data/lib/shaf/yard/profile_object.rb +21 -0
  100. data/lib/shaf/yard/resource_object.rb +55 -0
  101. data/lib/shaf/yard/serializer_handler.rb +27 -0
  102. data/templates/api/controllers/base_controller.rb +0 -10
  103. data/templates/api/controllers/docs_controller.rb +5 -3
  104. data/templates/api/controllers/root_controller.rb +7 -1
  105. data/templates/api/policies/base_policy.rb +2 -0
  106. data/templates/api/serializers/base_serializer.rb +1 -3
  107. data/templates/api/serializers/error_serializer.rb +1 -5
  108. data/templates/api/serializers/form_serializer.rb +1 -5
  109. data/templates/api/serializers/validation_error_serializer.rb +1 -5
  110. data/templates/config.ru +1 -1
  111. data/templates/config/bootstrap.rb +1 -2
  112. data/templates/config/directories.rb +52 -44
  113. data/templates/config/helpers.rb +1 -1
  114. data/templates/config/initializers.rb +52 -8
  115. data/templates/config/initializers/authentication.rb +18 -0
  116. data/templates/config/initializers/db_migrations.rb +2 -2
  117. data/templates/config/initializers/logging.rb +2 -2
  118. data/templates/frontend/assets/css/main.css +33 -1
  119. data/templates/frontend/views/headers.erb +20 -0
  120. data/templates/frontend/views/layout.erb +7 -1
  121. data/templates/frontend/views/payload.erb +1 -0
  122. data/templates/spec/spec_helper.rb +2 -0
  123. data/upgrades/0.5.0.tar.gz +0 -0
  124. data/upgrades/1.0.4.tar.gz +0 -0
  125. data/upgrades/1.1.0.tar.gz +0 -0
  126. data/upgrades/1.6.0.tar.gz +0 -0
  127. data/upgrades/1.6.1.tar.gz +0 -0
  128. data/upgrades/2.0.0.tar.gz +0 -0
  129. data/yard_templates/api_doc/doc_index/html/body.erb +3 -0
  130. data/yard_templates/api_doc/doc_index/setup.rb +8 -0
  131. data/yard_templates/api_doc/html/css/api-doc.css +222 -0
  132. data/yard_templates/api_doc/html/favicon.ico +0 -0
  133. data/yard_templates/api_doc/html/js/switch_tab.js +17 -0
  134. data/yard_templates/api_doc/html/setup.rb +59 -0
  135. data/yard_templates/api_doc/layout/html/footer.erb +3 -0
  136. data/yard_templates/api_doc/layout/html/header.erb +7 -0
  137. data/yard_templates/api_doc/layout/html/layout.erb +13 -0
  138. data/yard_templates/api_doc/layout/setup.rb +24 -0
  139. data/yard_templates/api_doc/profile/html/attributes.erb +10 -0
  140. data/yard_templates/api_doc/profile/html/profile.erb +6 -0
  141. data/yard_templates/api_doc/profile/html/relations.erb +10 -0
  142. data/yard_templates/api_doc/profile/setup.rb +38 -0
  143. data/yard_templates/api_doc/profile_attribute/html/attribute.erb +23 -0
  144. data/yard_templates/api_doc/profile_attribute/setup.rb +21 -0
  145. data/yard_templates/api_doc/profile_relation/html/relation.erb +37 -0
  146. data/yard_templates/api_doc/profile_relation/setup.rb +41 -0
  147. data/yard_templates/api_doc/resource/html/attributes.erb +10 -0
  148. data/yard_templates/api_doc/resource/html/profile.erb +14 -0
  149. data/yard_templates/api_doc/resource/html/relations.erb +10 -0
  150. data/yard_templates/api_doc/resource/html/resource.erb +5 -0
  151. data/yard_templates/api_doc/resource/setup.rb +56 -0
  152. data/yard_templates/api_doc/resource_attribute/html/attribute.erb +23 -0
  153. data/yard_templates/api_doc/resource_attribute/setup.rb +20 -0
  154. data/yard_templates/api_doc/resource_relation/html/relation.erb +47 -0
  155. data/yard_templates/api_doc/resource_relation/setup.rb +80 -0
  156. data/yard_templates/api_doc/setup.rb +31 -0
  157. data/yard_templates/api_doc/sidebar/html/profile_list.erb +8 -0
  158. data/yard_templates/api_doc/sidebar/html/search.erb +7 -0
  159. data/yard_templates/api_doc/sidebar/html/serializer_list.erb +8 -0
  160. data/yard_templates/api_doc/sidebar/html/sidebar.erb +13 -0
  161. data/yard_templates/api_doc/sidebar/setup.rb +56 -0
  162. metadata +140 -30
  163. metadata.gz.sig +0 -0
  164. data/lib/shaf/extensions/current_user.rb +0 -48
  165. data/lib/shaf/responder/hal_serializable.rb +0 -54
@@ -6,6 +6,9 @@ require 'open3'
6
6
  require 'fileutils'
7
7
  require 'tempfile'
8
8
  require 'yaml'
9
+ require 'file_transactions'
10
+
11
+ FT = FileTransactions
9
12
 
10
13
  module Shaf
11
14
  module Upgrade
@@ -23,8 +26,6 @@ module Shaf
23
26
  MANIFEST_FILENAME = 'manifest'.freeze
24
27
  IGNORE_FILE_PATTERNS = [/.rej\z/, /.orig\z/]
25
28
 
26
- attr_reader :version
27
-
28
29
  class << self
29
30
  def all
30
31
  target_versions.map(&method(:new))
@@ -53,6 +54,8 @@ module Shaf
53
54
  end
54
55
  end
55
56
 
57
+ attr_reader :version, :manifest
58
+
56
59
  def initialize(version, manifest = nil, files = {})
57
60
  @version = Version.new(version)
58
61
  @manifest = manifest
@@ -77,25 +80,32 @@ module Shaf
77
80
  end
78
81
 
79
82
  def apply(dir = nil)
80
- puts "Applying changes for version #{version}"
81
- [
82
- apply_patches(dir),
83
- apply_drops(dir),
84
- apply_additions,
85
- apply_substitutes(dir),
86
- ].all?
83
+ puts "\n ## Applying changes for Shaf version: #{version} ##"
84
+
85
+ FT.transaction do
86
+ result = [
87
+ apply_patches(dir),
88
+ apply_drops(dir),
89
+ apply_additions,
90
+ apply_substitutes(dir),
91
+ print_messages,
92
+ ]
93
+ raise UpgradeError, 'Upgrade failed' unless result.all?
94
+ end
95
+
96
+ true
87
97
  end
88
98
 
89
99
  def to_s
90
- str = "Shaf::Upgrade::Package for version #{@version}"
91
- return str if @manifest.nil?
92
- "#{str} (#{@manifest.stats_str})"
100
+ str = "Shaf::Upgrade::Package for version #{version}"
101
+ return str if manifest.nil?
102
+ "#{str} (#{manifest.stats_str})"
93
103
  end
94
104
 
95
105
  private
96
106
 
97
107
  def tarball
98
- file = File.join(UPGRADE_FILES_PATH, "#{@version}.tar.gz")
108
+ file = File.join(UPGRADE_FILES_PATH, "#{version}.tar.gz")
99
109
  return file if File.exist? file
100
110
  raise VersionNotFoundError
101
111
  end
@@ -114,24 +124,25 @@ module Shaf
114
124
  def parse_manifest(content)
115
125
  hash = YAML.safe_load(content)
116
126
  @manifest = Manifest.new(
117
- target_version: hash["target_version"],
118
- patches: hash["patches"],
119
- add: hash["add"],
120
- drop: hash["drop"],
121
- substitutes: hash["substitutes"]
127
+ target_version: hash['target_version'],
128
+ patches: hash['patches'],
129
+ add: hash['add'],
130
+ drop: hash['drop'],
131
+ substitutes: hash['substitutes'],
132
+ messages: hash['messages']
122
133
  )
123
134
  end
124
135
 
125
136
  def validate
126
- raise ManifestNotFoundError unless @manifest
127
- raise VersionConflictError unless @version == @manifest.target_version
137
+ raise ManifestNotFoundError unless manifest
138
+ raise VersionConflictError unless version == manifest.target_version
128
139
 
129
140
  from_file = @files.keys.to_set
130
141
 
131
- manifest_patches = @manifest.files[:patch].keys.to_set
142
+ manifest_patches = manifest.patches.keys.to_set
132
143
  raise MissingFileError if from_file < manifest_patches
133
144
 
134
- to_add = @manifest.files[:add].keys.to_set
145
+ to_add = manifest.additions.keys.to_set
135
146
  raise MissingFileError if from_file < to_add
136
147
 
137
148
  @files.each do |md5, content|
@@ -155,35 +166,38 @@ module Shaf
155
166
  end
156
167
 
157
168
  def apply_patches(dir = nil)
158
- files_in(dir).all? do |file|
159
- @manifest.patches_for(file).all? do |name|
169
+ files_in(dir).map do |file|
170
+ manifest.patches_for(file).map do |name|
160
171
  patch = @files[name]
161
172
  apply_patch(file, patch)
162
- end
163
- end
173
+ end.all?
174
+ end.all?
164
175
  end
165
176
 
166
177
  def apply_patch(file, patch)
167
- Open3.popen3('patch', file) do |i, o, e, t|
168
- i.write patch
169
- i.close
170
- puts o.read
171
- err = e.read
172
- puts err unless err.empty?
173
- t.value.success?.tap do |patch_succeeded|
174
- next if patch_succeeded
175
- STDERR.puts "Failed to apply patch for: #{file}\n"
178
+ result = nil
179
+
180
+ FT::ChangeFileCommand.execute(file) do
181
+ Open3.popen3('patch', file) do |i, o, e, t|
182
+ i.write patch
183
+ i.close
184
+ puts o.read
185
+ err = e.read
186
+ puts err unless err.empty?
187
+ result = t.value.success?
176
188
  end
177
189
  end
190
+
191
+ STDERR.puts "Failed to apply patch for: #{file}\n" unless result
192
+ result
178
193
  end
179
194
 
180
195
  def apply_additions
181
- puts '' unless @manifest.additions.empty?
182
- @manifest.additions.all? do |chksum, filename|
196
+ puts '' unless manifest.additions.empty?
197
+ manifest.additions.all? do |chksum, filename|
183
198
  content = @files[chksum]
184
- FileUtils.mkdir_p File.dirname(filename)
185
199
  puts "adding file: #{filename}"
186
- File.open(filename, 'w') { |file| file.write(content) }
200
+ FT::CreateFileCommand.execute(filename) { content }
187
201
  true
188
202
  rescue StandardError => e
189
203
  STDERR.puts "Failed to add '#{filename}': #{e.message}\n"
@@ -192,11 +206,11 @@ module Shaf
192
206
  end
193
207
 
194
208
  def apply_drops(dir = nil)
195
- puts '' unless @manifest.removals.empty?
209
+ puts '' unless manifest.removals.empty?
196
210
  files_in(dir).all? do |file|
197
- next true unless @manifest.drop?(file)
211
+ next true unless manifest.drop?(file)
198
212
  puts "removing file: #{file}"
199
- File.unlink(file)
213
+ FT::DeleteFileCommand.execute file
200
214
  true
201
215
  rescue StandardError => e
202
216
  STDERR.puts "Failed to unlink '#{file}': #{e.message}\n"
@@ -205,14 +219,14 @@ module Shaf
205
219
  end
206
220
 
207
221
  def apply_substitutes(dir = nil)
208
- puts '' unless @manifest.regexps.empty?
209
- files_in(dir).all? do |file|
210
- @manifest.regexps_for(file).all? do |name|
222
+ puts '' unless manifest.regexps.empty?
223
+ files_in(dir).map do |file|
224
+ manifest.regexps_for(file).map do |name|
211
225
  params = YAML.safe_load(@files[name])
212
226
  params.transform_keys!(&:to_sym)
213
227
  apply_substitute(file, params)
214
- end
215
- end
228
+ end.all?
229
+ end.all?
216
230
  end
217
231
 
218
232
  def apply_substitute(file, params)
@@ -221,14 +235,29 @@ module Shaf
221
235
  pattern = Regexp.new(params[:pattern])
222
236
  replacement = params[:replace]
223
237
 
238
+ changed = false
224
239
  tmp = Tempfile.open do |new_file|
225
240
  File.readlines(file).each do |line|
226
- new_file << line.gsub(pattern, replacement)
241
+ changed = line.gsub!(pattern, replacement) || changed
242
+ new_file << line
227
243
  end
228
244
  new_file
229
245
  end
230
246
 
231
- FileUtils.mv(tmp.path, file)
247
+ return true unless changed
248
+
249
+ puts "modifying file: #{file}"
250
+ FT::MoveFileCommand.new(from: tmp.path, to: file).execute
251
+ true
252
+ end
253
+
254
+ def print_messages
255
+ manifest.messages.each do |chksum|
256
+ message = @files[chksum]
257
+ puts "\n#{message}"
258
+ end
259
+
260
+ true
232
261
  end
233
262
  end
234
263
  end
@@ -8,7 +8,7 @@ module Shaf
8
8
  alias eql? ==
9
9
 
10
10
  class UpgradeVersionError < StandardError
11
- def initialize(message = "")
11
+ def initialize(message = '')
12
12
  super("Bad upgrade version: #{message}")
13
13
  end
14
14
  end
@@ -16,25 +16,26 @@ module Shaf
16
16
  def initialize(version)
17
17
  case version
18
18
  when Version
19
- @major, @minor, @patch = [:major, :minor, :patch].map { |m| version.send m }
19
+ @major, @minor, @patch = version.to_a
20
20
  when /\d+\.\d+(\.\d+)?/
21
21
  @major, @minor, @patch = split_version(version)
22
22
  else
23
- raise UpgradeVersionError.new(version)
23
+ raise UpgradeVersionError, version
24
24
  end
25
25
  end
26
26
 
27
27
  def <=>(other)
28
- case other
29
- when String
30
- compare_version(*split_version(other))
31
- when Version
32
- compare_version(other.major, other.minor, other.patch)
33
- end
28
+ return unless other
29
+ other = self.class.new(other)
30
+ compare_version(other.major, other.minor, other.patch)
34
31
  end
35
32
 
36
33
  def to_s
37
- [major, minor, patch].join('.')
34
+ to_a.join('.')
35
+ end
36
+
37
+ def to_a
38
+ [major, minor, patch]
38
39
  end
39
40
 
40
41
  private
data/lib/shaf/utils.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  require 'erb'
4
4
  require 'forwardable'
5
5
  require 'yaml'
6
+ require 'csv'
7
+ require 'zlib'
6
8
  require 'shaf/version'
7
9
 
8
10
  module Shaf
@@ -35,12 +37,19 @@ module Shaf
35
37
  noun[0..-2]
36
38
  end
37
39
 
38
- def symbolize(str)
39
- :"#{str}"
40
+ def symbol_string(str)
41
+ str.to_sym.inspect
40
42
  end
41
43
 
42
- def symbol_string(str)
43
- symbolize(str).inspect
44
+ def symbol_or_quoted_string(obj)
45
+ case obj
46
+ when Symbol
47
+ obj.inspect
48
+ when Numeric
49
+ obj
50
+ else
51
+ "'#{obj.to_s}'"
52
+ end
44
53
  end
45
54
 
46
55
  def environment
@@ -98,6 +107,11 @@ module Shaf
98
107
  end
99
108
  end
100
109
 
110
+ def iana_link_relations_csv
111
+ zip_file = File.join(gem_root, 'iana_link_relations.csv.gz')
112
+ Zlib::GzipReader.open(zip_file) { |content| CSV.new(content.read) }
113
+ end
114
+
101
115
  private
102
116
 
103
117
  def erb(content, binding: nil)
@@ -107,7 +121,7 @@ module Shaf
107
121
  end
108
122
  end
109
123
 
110
- def_delegators Utils, :pluralize, :singularize, :symbolize, :symbol_string, :gem_root, :rackify_header
124
+ def_delegators Utils, :pluralize, :singularize, :symbol_string, :gem_root, :rackify_header
111
125
 
112
126
  def project_root
113
127
  return @project_root if defined? @project_root
data/lib/shaf/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shaf
2
- VERSION = "1.5.1"
4
+ VERSION = '2.1.0'
3
5
  end
data/lib/shaf/yard.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yard'
4
+ require 'shaf/yard/serializer_handler'
5
+ require 'shaf/yard/attribute_method_handler'
6
+ require 'shaf/yard/link_method_handler'
7
+ require 'shaf/yard/profile_method_handler'
8
+ require 'shaf/yard/resource_object'
9
+ require 'shaf/yard/profile_object'
10
+ require 'shaf/yard/attribute_object'
11
+ require 'shaf/yard/link_object'
12
+ require 'shaf/yard/nested_attributes'
13
+ require 'shaf/yard/parser'
14
+
15
+ module Shaf
16
+ module Yard
17
+ CUSTOM_TAGS = [
18
+ ['Request Header', :request_header, :with_name],
19
+ ['Reponse Header', :response_header, :with_name],
20
+ ['Example Request', :example_request],
21
+ ['Example Response', :example_response],
22
+ ['Description', :description],
23
+ ['HTTP method', :http_method],
24
+ ['Attribute type', :type, :with_types]
25
+ ].freeze
26
+
27
+ CUSTOM_TAGS.each do |tag|
28
+ YARD::Tags::Library.define_tag(*tag)
29
+ end
30
+
31
+ TEMPLATE_PATH = File.join(Utils.gem_root, 'yard_templates').freeze
32
+ YARD::Templates::Engine.register_template_path TEMPLATE_PATH
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shaf/yard/base_method_handler'
4
+
5
+ module Shaf
6
+ module Yard
7
+ # Handles call to Shaf::Serializer::attribute
8
+ class AttributeMethodHandler < BaseMethodHandler
9
+ handles method_call(:attribute)
10
+
11
+ def object
12
+ AttributeObject.new(serializer_namespace, name).tap do |attr|
13
+ attr.dynamic = true
14
+ attr.name = name
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shaf
4
+ module Yard
5
+ class AttributeObject < ::YARD::CodeObjects::Base
6
+ attr_accessor :name
7
+
8
+ def documentation
9
+ profile_doc || 'Not documented'
10
+ end
11
+
12
+ def profile
13
+ return unless namespace.respond_to? :profile
14
+ @profile ||= namespace.profile
15
+ end
16
+
17
+ def value_types
18
+ Array(descriptor&.type).compact.map(&:to_s)
19
+ end
20
+
21
+ def profile_doc
22
+ descriptor&.doc
23
+ end
24
+
25
+ def descriptor
26
+ profile&.find_attribute(name)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shaf
4
+ module Yard
5
+ class BaseMethodHandler < ::YARD::Handlers::Ruby::Base
6
+ namespace_only
7
+
8
+ def process
9
+ return unless serializer_namespace
10
+
11
+ register object
12
+ end
13
+
14
+ def name
15
+ call_params.first.yield_self do |name|
16
+ # remove single colon. Sometimes symbols get the :, (e.g. :self)
17
+ name.sub(/\A:(?!:)/, '')
18
+ end
19
+ end
20
+
21
+ def object
22
+ raise NotImplementedError, "#{self} must implement #object"
23
+ end
24
+
25
+ def serializer_namespace
26
+ @serializer_namespace ||= YARD::Registry.at ResourceObject.path(namespace)
27
+ end
28
+ end
29
+ end
30
+ end