shaf 1.2.2 → 1.3.0

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: 80966929b3dbd95660efc1734f58af69073d1fe2d52279ebd167e6f94e57084c
4
- data.tar.gz: ffbeb725dbb8442a589c6dc50129e19207145f0d159284e4a4f09e04ad995cf0
3
+ metadata.gz: 319f7f6a1725c5e3e5d9ab293531dc72cced237cf5967d2beb3ef3f47c5be8e7
4
+ data.tar.gz: 4f37d5e9c0424c31c6dda4ec2c5e628920963d01dd61d367681504cd6f50f0e0
5
5
  SHA512:
6
- metadata.gz: abdc53f555ca5143ed1d7cd8aa475910ae19c4d285104cfa5f576f4b53e4fe6d2666978dbd7158b7440cfaab6ae07ff53a939ce098f6140d68ad070d8558a3b3
7
- data.tar.gz: e881b178f16a2938e5e65163e21c0dcf3a83e714e284bc7c7bff596277681f1059bd47f405a9a0709eea6169bd35caf39fe9aa34b34911b2954c96c09e92b12f
6
+ metadata.gz: 3431790d086472d8cbac8ec9e51ed8fb02ddc4a402ec993a5ed7d17ea1eb048e89902693b3c4c3f88a3630c226fddc175dd4c0024136cac4adb43cd4d2869531
7
+ data.tar.gz: 004321671f62d6578e35c42ed1a1b3b1345bc9308743710dc5cc645195303af8235e30d4288ec6f8048c3ad7ab04ca6087912d27ea983b5ecc45768b997b6347
@@ -1 +1,4 @@
1
- V�A� ͑���,\Z�U�!�^ϸlpw:ٶAF�#4��iH�8���S��I�?c"r��p��vB�.��{�y�%6���%�M7�4�k[zkG���q�YРb���:T"�v����H� ��-�KWv��Z@�_`mh����� 8��^�*O���]QU]kl���1#j�vΑl�������R�]dΜ�=>zī0��E��' �������KN3�^qQ3�p"��@�&=������� =�xo�iN�8�I �:H��
1
+ x��=����3.�
2
+ p?�2,x�)���F# �
3
+
4
+ OWO���א�ൠ4T�pDkZ�|ߌJ�;��,�ZgB|i:�8���l�y��Ԣ\u�.Ԛ]%D��,z y���Pr�<���B+���XC�p�,yޝԒ�wM�1�<x�M�KvK�H�VӤ��iC<;e �F��0#�G]3r�;{X�͕)<�Gң���I�
data.tar.gz.sig CHANGED
Binary file
@@ -7,5 +7,5 @@ require 'shaf/errors'
7
7
  require 'shaf/formable'
8
8
  require 'shaf/extensions'
9
9
  require 'shaf/helpers'
10
- require 'shaf/doc_model'
10
+ require 'shaf/resource_doc'
11
11
  require 'shaf/upgrade'
@@ -40,7 +40,7 @@ module Shaf
40
40
  @embeds[strip_curie(name)] = comment unless comment.empty?
41
41
  end
42
42
 
43
- def has_enough_info?
43
+ def valid?
44
44
  return false unless model
45
45
  attributes.merge(links).merge(curies).any?
46
46
  end
@@ -70,12 +70,17 @@ module Shaf
70
70
  hash.to_yaml
71
71
  end
72
72
 
73
+ def markdown
74
+ generate_markdown!
75
+ @md[:doc]
76
+ end
77
+
73
78
  def to_html
79
+ options = {autolink: true, fenced_code_blocks: true}
80
+ markdown_renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, options)
81
+ html = markdown_renderer.render markdown
74
82
  # For some reason redcarpet don't like to surround my markdown code blocks
75
83
  # with <pre> tags, so let's fix that here.
76
- options = {autolink: true, fenced_code_blocks: true}
77
- markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, options)
78
- html = markdown.render(generate_markdown!)
79
84
  html.gsub!("<code>", "<pre><code>")
80
85
  html.gsub!("</code>", "</code></pre>")
81
86
  html
@@ -103,26 +108,26 @@ module Shaf
103
108
  end
104
109
 
105
110
  def generate_title!
106
- @md[:doc] = "##%s\n" % model.capitalize
111
+ @md[:doc] = "# #{model.capitalize}\n"
107
112
  @md[:title] = model.capitalize
108
113
  end
109
114
 
110
115
  def generate_policy!
111
116
  return if policy.nil?
112
- @md[:doc] << "###Policy\n#{policy}\n"
117
+ @md[:doc] << "## Policy\n#{policy}\n"
113
118
  @md[:policy] = policy
114
119
  end
115
120
 
116
121
  def generate_section!(key:, heading:, sub_title: "")
117
122
  list = send(key)
118
- @md[:doc] << "####{heading}\n"
123
+ @md[:doc] << "## #{heading}\n"
119
124
  @md[key] = {}
120
125
  if list.empty?
121
126
  @md[:doc] << "This resource does not have any documented #{heading.downcase}\n"
122
127
  else
123
- sub_title << ": " unless sub_title.empty?
128
+ sub_title += ": " unless sub_title.empty?
124
129
  list.each do |name, comment|
125
- @md[:doc] << "#######{sub_title}#{name.tr('_', '-')}\n#{comment.to_s}\n"
130
+ @md[:doc] << "- *#{sub_title}#{name.tr('_', '-')}*\n #{comment.to_s.gsub("\n", "\n ")}\n\n"
126
131
  @md[key][name] = comment.to_s.chomp
127
132
  end
128
133
  end
@@ -24,10 +24,23 @@ module Shaf
24
24
 
25
25
  def call
26
26
  in_project_root do
27
- upgrade_packages.each { |package| apply(package) }
27
+ upgrade_packages.each do |package|
28
+ next if skip? package
29
+
30
+ if package.version == current_failed_version
31
+ print_previous_failed_warning package.version
32
+ else
33
+ apply!(package)
34
+ end
35
+
36
+ write_shaf_version(package.version)
37
+ end
38
+
28
39
  puts "\nProject is up-to-date! Shaf version: #{current_version}"
29
40
  end
30
41
  rescue UpgradeFailedError => e
42
+ write_shaf_upgrade_failure e.version
43
+
31
44
  puts <<~ERR
32
45
 
33
46
  Failed to upgrade project to version #{e.version}
@@ -35,13 +48,12 @@ module Shaf
35
48
  For more info see:
36
49
  https://github.com/sammyhenningsson/shaf/blob/master/doc/UPGRADE.md
37
50
  ERR
51
+
52
+ raise
38
53
  end
39
54
 
40
- def apply(package)
41
- unless skip? package
42
- package.load.apply or raise UpgradeFailedError.new(package.version)
43
- end
44
- write_shaf_version package.version.to_s
55
+ def apply!(package)
56
+ package.load.apply or raise UpgradeFailedError.new(package.version)
45
57
  rescue Errno::ENOENT
46
58
  raise UpgradeFailedError,
47
59
  "Failed to execute system command 'patch'. Make sure that 'patch' installed!" \
@@ -70,6 +82,19 @@ module Shaf
70
82
  def target_version
71
83
  Shaf::Upgrade::Version.new(ENV.fetch('UPGRADE_TARGET', '99.9.9'))
72
84
  end
85
+
86
+ def current_failed_version
87
+ version = read_shaf_upgrade_failure_version
88
+ Shaf::Upgrade::Version.new(version) if version
89
+ end
90
+
91
+ def print_previous_failed_warning(version)
92
+ puts <<~MSG
93
+ Previous upgrade to version #{version} failed!
94
+ Assuming all files has been fixed manually and continuing with
95
+ upgrade.
96
+ MSG
97
+ end
73
98
  end
74
99
  end
75
100
  end
@@ -69,7 +69,7 @@ module Shaf
69
69
  end
70
70
 
71
71
  def links
72
- %w(collection self doc:edit-form doc:delete)
72
+ %w(collection self edit-form doc:delete)
73
73
  end
74
74
 
75
75
  def curies_with_doc
@@ -108,7 +108,8 @@ module Shaf
108
108
  "Send a POST request to this uri to create a new #{name}",
109
109
  method: "GET or POST",
110
110
  uri: "/#{plural_name}",
111
- uri_helper: "#{plural_name}_uri"
111
+ uri_helper: "#{plural_name}_uri",
112
+ kwargs: ', embed_depth: 0'
112
113
  )
113
114
  end
114
115
 
@@ -123,7 +124,7 @@ module Shaf
123
124
 
124
125
  def edit_link
125
126
  link(
126
- rel: "doc:edit-form",
127
+ rel: "edit-form",
127
128
  desc: "Link to a form to edit this resource",
128
129
  uri: "/#{plural_name}/5/edit",
129
130
  uri_helper: "edit_#{name}_uri(resource)"
@@ -132,30 +133,31 @@ module Shaf
132
133
 
133
134
  def delete_link
134
135
  link(
135
- rel: "doc:delete",
136
+ rel: "delete",
136
137
  desc: "Link to delete this #{name}",
137
138
  method: "DELETE",
138
139
  uri: "/#{plural_name}/5",
139
- uri_helper: "#{name}_uri(resource)"
140
+ uri_helper: "#{name}_uri(resource)",
141
+ kwargs: ", curie: :doc"
140
142
  )
141
143
  end
142
144
 
143
145
  def create_link
144
146
  link(
145
- rel: "doc:create-form",
147
+ rel: "create-form",
146
148
  desc: "Link to a form used to create new #{name} resources",
147
149
  uri: "/#{plural_name}/form",
148
150
  uri_helper: "new_#{name}_uri"
149
151
  )
150
152
  end
151
153
 
152
- def link(rel:, method: "GET", desc:, uri:, uri_helper:)
154
+ def link(rel:, method: "GET", desc:, uri:, uri_helper:, kwargs: "")
153
155
  <<~EOS.split("\n")
154
156
  # Auto generated doc:
155
157
  # #{desc}.
156
158
  # Method: #{method}
157
159
  #{example(method, uri)}
158
- link #{Utils.symbol_string(rel)} do
160
+ link #{Utils.symbol_string(rel)}#{kwargs} do
159
161
  #{uri_helper}
160
162
  end
161
163
  EOS
@@ -188,7 +190,7 @@ module Shaf
188
190
  curie(:doc) { doc_curie_uri('#{name}') }
189
191
 
190
192
  link :self, #{plural_name}_uri
191
- link :'doc:up', root_uri
193
+ link :up, root_uri
192
194
 
193
195
  #{create_link.join("\n ")}
194
196
  end
@@ -34,8 +34,8 @@ describe <%= model_class_name %>, type: :integration do
34
34
  it "can create <%= plural_name %>" do
35
35
  get <%= plural_name %>_uri
36
36
 
37
- _(link_rels).must_include(:'doc:create-form')
38
- follow_rel :'doc:create-form'
37
+ _(link_rels).must_include(:'create-form')
38
+ follow_rel :'create-form'
39
39
  _(links[:self][:href]).must_equal new_<%= name %>_uri
40
40
  _(attributes[:href]).must_equal <%= plural_name %>_uri
41
41
  _(attributes[:method]).must_equal "POST"
@@ -72,8 +72,8 @@ describe <%= model_class_name %>, type: :integration do
72
72
  get <%= name %>_uri(<%= name %>)
73
73
  _(status).must_equal 200
74
74
 
75
- _(link_rels).must_include(:'doc:edit-form')
76
- follow_rel :'doc:edit-form'
75
+ _(link_rels).must_include(:'edit-form')
76
+ follow_rel :'edit-form'
77
77
 
78
78
  _(links[:self][:href]).must_equal edit_<%= name %>_uri(<%= name %>)
79
79
  _(attributes[:href]).must_equal <%= name %>_uri(<%= name %>)
@@ -0,0 +1,70 @@
1
+ require 'yaml'
2
+
3
+ module Shaf
4
+ class ResourceDoc
5
+ class << self
6
+ def find(name)
7
+ unless docs[name]
8
+ properties = load(name) or return
9
+ docs[name] = new(name, properties)
10
+ end
11
+ docs[name]
12
+ end
13
+
14
+ def find!(name)
15
+ find(name) or raise(Errors::NotFoundError, "No documentation for #{name}")
16
+ end
17
+
18
+ private
19
+
20
+ def docs
21
+ @docs ||= {}
22
+ end
23
+
24
+ def load(name)
25
+ file = File.join(Settings.documents_dir, "#{name}.yml")
26
+ return YAML.load(File.read(file)) if File.exist? file
27
+ end
28
+ end
29
+
30
+ attr_reader :name, :attributes, :links, :curies, :embeds
31
+
32
+ def initialize(name, properties = {})
33
+ @name = name
34
+ @attributes = properties.fetch('attributes', {})
35
+ @links = properties.fetch('links', {})
36
+ @curies = properties.fetch('curies', {})
37
+ @embeds = properties.fetch('embeds', {})
38
+ end
39
+
40
+ def to_s
41
+ JSON.pretty_generate(
42
+ attributes: attributes,
43
+ links: links,
44
+ curies: curies,
45
+ embeds: embeds,
46
+ )
47
+ end
48
+
49
+ def attribute(attr)
50
+ attr_doc = attributes[attr.to_s]
51
+ return attr_doc if attr_doc
52
+ raise Errors::NotFoundError,
53
+ "No documentation for #{name} attribute '#{attr}'"
54
+ end
55
+
56
+ def link(rel)
57
+ link_doc = links[rel.to_s]
58
+ return link_doc if link_doc
59
+ raise Errors::NotFoundError,
60
+ "No documentation for #{name} link relation '#{rel}'"
61
+ end
62
+
63
+ def embedded(name)
64
+ embed_doc = embeds[name.to_s]
65
+ return embed_doc if embed_doc
66
+ raise Errors::NotFoundError,
67
+ "No documentation for #{name} embedded '#{name}'"
68
+ end
69
+ end
70
+ end
@@ -28,7 +28,7 @@ module Shaf
28
28
  files = Dir.glob(File.join(source_dir, "*.rb"))
29
29
  files.each do |file|
30
30
  read_file file do |doc|
31
- next unless doc.has_enough_info?
31
+ next unless doc.valid?
32
32
  doc.write_html @html_output_dir
33
33
  doc.write_yaml @yaml_output_dir
34
34
  end
@@ -106,19 +106,19 @@ module Shaf
106
106
  end
107
107
 
108
108
  def attribute(line)
109
- line[/\A\s*attribute[^s]\s*\(?:(\w+)/, 1]
109
+ line[/\A\s*attribute\s+\(?:(\w+)/, 1]
110
110
  end
111
111
 
112
112
  def link(line)
113
- line[/\A\s*link\s*\(?:?['"]?([-:\w]+)['"]?/, 1]
113
+ line[/\A\s*link\s+\(?:?['"]?([-:\w]+)['"]?/, 1]
114
114
  end
115
115
 
116
116
  def curie(line)
117
- line[/\A\s*curie\s*\(?:'?([-\w]+)'?/, 1]
117
+ line[/\A\s*curie\s+\(?:'?([-\w]+)'?/, 1]
118
118
  end
119
119
 
120
120
  def embed(line)
121
- line[/\A\s*embed\s*\(?:'?([-:\w]+)'?/, 1]
121
+ line[/\A\s*embed\s+\(?:'?([-:\w]+)'?/, 1]
122
122
  end
123
123
  end
124
124
  end
@@ -77,7 +77,7 @@ module Shaf
77
77
  end
78
78
 
79
79
  def apply(dir = nil)
80
- puts "Applying changes for version #{version}" if ENV["VERBOSE"] == "1"
80
+ puts "Applying changes for version #{version}"
81
81
  [
82
82
  apply_patches(dir),
83
83
  apply_drops(dir),
@@ -25,9 +25,10 @@ module Shaf
25
25
  end
26
26
 
27
27
  def <=>(other)
28
- if other.is_a? String
28
+ case other
29
+ when String
29
30
  compare_version(*split_version(other))
30
- else
31
+ when Version
31
32
  compare_version(other.major, other.minor, other.patch)
32
33
  end
33
34
  end
@@ -159,7 +159,10 @@ module Shaf
159
159
  end
160
160
 
161
161
  def write_shaf_file(data = {})
162
- data = read_shaf_file.merge(data)
162
+ write_shaf_file! read_shaf_file.merge(data)
163
+ end
164
+
165
+ def write_shaf_file!(data = {})
163
166
  File.write SHAF_VERSION_FILE,
164
167
  YAML.dump(data)
165
168
  end
@@ -168,8 +171,19 @@ module Shaf
168
171
  read_shaf_file['version']
169
172
  end
170
173
 
174
+ def read_shaf_upgrade_failure_version
175
+ read_shaf_file['failed_upgrade']
176
+ end
177
+
171
178
  def write_shaf_version(version = nil)
172
- write_shaf_file('version' => version || Shaf::VERSION)
179
+ version ||= Shaf::VERSION
180
+ data = read_shaf_file.merge('version' => version.to_s)
181
+ data.delete('failed_upgrade')
182
+ write_shaf_file! data
183
+ end
184
+
185
+ def write_shaf_upgrade_failure(version)
186
+ write_shaf_file 'failed_upgrade' => version.to_s
173
187
  end
174
188
  end
175
189
  end
@@ -1,3 +1,3 @@
1
1
  module Shaf
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -3,17 +3,19 @@ class DocsController < BaseController
3
3
  register_uri :doc_curie, '/doc/:resource/rels/{rel}'
4
4
  register_uri :documentation, '/doc/:resource'
5
5
 
6
- get :doc_curie_uri do
6
+ before_action do
7
7
  cache_control(:private, http_cache_max_age: :long)
8
- doc.link(params[:rel])
9
8
  end
10
9
 
11
- get :documentation_uri do
12
- cache_control(:private, http_cache_max_age: :long)
13
- doc.to_s
10
+ get :doc_curie_path do
11
+ respond_with doc, path: request.path_info, rel: params[:rel]
12
+ end
13
+
14
+ get :documentation_path do
15
+ respond_with doc, path: request.path_info
14
16
  end
15
17
 
16
18
  def doc
17
- Shaf::DocModel.find!(params[:resource])
19
+ Shaf::ResourceDoc.find!(params[:resource])
18
20
  end
19
21
  end
@@ -0,0 +1,24 @@
1
+ class DocumentationSerializer < BaseSerializer
2
+ model Shaf::ResourceDoc
3
+
4
+ link :self do
5
+ options[:path]
6
+ end
7
+
8
+ link :up do
9
+ next unless options[:rel] || options[:attribute]
10
+ documentation_path(resource.name)
11
+ end
12
+
13
+ post_serialize do |hash|
14
+ if rel = options[:rel]
15
+ hash[rel] = resource.link(rel)
16
+ elsif attr = options[:attribute]
17
+ hash[attr] = resource.attribute(attr)
18
+ else
19
+ hash[:attributes] = resource.attributes
20
+ hash[:rels] = resource.links
21
+ hash[:embeds] = resource.embeds
22
+ end
23
+ end
24
+ end
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="UTF-8">
5
- <title>Shaba<%= @page_title && " | #{@page_title}" %></title>
5
+ <title>Shaf API<%= @page_title && " | #{@page_title}" %></title>
6
6
  <link rel="stylesheet" type="text/css" href="/css/main.css">
7
7
  </head>
8
8
  <body>
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sammy Henningsson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  ZMhjYR7sRczGJx+GxGU2EaR0bjRsPVlC4ywtFxoOfRG3WaJcpWGEoAoMJX6Z0bRv
31
31
  M40=
32
32
  -----END CERTIFICATE-----
33
- date: 2019-10-04 00:00:00.000000000 Z
33
+ date: 2019-10-24 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: minitest
@@ -161,7 +161,6 @@ files:
161
161
  - lib/shaf/command/test/runner.rb
162
162
  - lib/shaf/command/upgrade.rb
163
163
  - lib/shaf/command/version.rb
164
- - lib/shaf/doc_model.rb
165
164
  - lib/shaf/errors.rb
166
165
  - lib/shaf/extensions.rb
167
166
  - lib/shaf/extensions/authorize.rb
@@ -213,6 +212,7 @@ files:
213
212
  - lib/shaf/rake/db.rb
214
213
  - lib/shaf/rake/test.rb
215
214
  - lib/shaf/registrable_factory.rb
215
+ - lib/shaf/resource_doc.rb
216
216
  - lib/shaf/router.rb
217
217
  - lib/shaf/settings.rb
218
218
  - lib/shaf/spec.rb
@@ -244,6 +244,7 @@ files:
244
244
  - templates/api/controllers/root_controller.rb
245
245
  - templates/api/policies/base_policy.rb
246
246
  - templates/api/serializers/base_serializer.rb
247
+ - templates/api/serializers/documentation_serializer.rb
247
248
  - templates/api/serializers/error_serializer.rb
248
249
  - templates/api/serializers/form_serializer.rb
249
250
  - templates/api/serializers/root_serializer.rb
@@ -271,12 +272,14 @@ files:
271
272
  - templates/spec/spec_helper.rb
272
273
  - upgrades/0.4.0.tar.gz
273
274
  - upgrades/0.5.0.tar.gz
275
+ - upgrades/0.5.1.tar.gz
274
276
  - upgrades/0.6.0.tar.gz
275
277
  - upgrades/1.0.0.tar.gz
276
278
  - upgrades/1.0.4.tar.gz
277
279
  - upgrades/1.1.0.tar.gz
278
280
  - upgrades/1.2.0.tar.gz
279
281
  - upgrades/1.2.1.tar.gz
282
+ - upgrades/1.3.0.tar.gz
280
283
  homepage:
281
284
  licenses:
282
285
  - MIT
metadata.gz.sig CHANGED
Binary file
@@ -1,54 +0,0 @@
1
- require 'yaml'
2
-
3
- module Shaf
4
- class DocModel
5
- class << self
6
- def find(name)
7
- @@docs ||= {}
8
- @@docs[name] ||= load(name)
9
- new(name) if @@docs[name]
10
- end
11
-
12
- def find!(name)
13
- find(name) or raise(Errors::NotFoundError, "No documentation for #{name}")
14
- end
15
-
16
- private
17
-
18
- def load(name)
19
- file = File.join(Settings.documents_dir, "#{name}.yml")
20
- return YAML.load(File.read(file)) if File.exist? file
21
- end
22
- end
23
-
24
- def initialize(name)
25
- @name = name
26
- end
27
-
28
- def to_s
29
- return "#{@name} not found" unless @@docs[@name]
30
- JSON.pretty_generate(@@docs[@name])
31
- end
32
-
33
- def attribute(attr)
34
- attr_doc = @@docs.dig(@name, 'attributes', attr.to_s)
35
- return attr_doc if attr_doc
36
- raise Errors::NotFoundError,
37
- "No documentation for #{@name} attribute '#{attr}'"
38
- end
39
-
40
- def link(rel)
41
- link_doc = @@docs.dig(@name, 'links', rel.to_s)
42
- return link_doc if link_doc
43
- raise Errors::NotFoundError,
44
- "No documentation for #{@name} link relation '#{rel}'"
45
- end
46
-
47
- def embedded(name)
48
- embed_doc = @@docs.dig(@name, 'embeds', name.to_s)
49
- return embed_doc if embed_doc
50
- raise Errors::NotFoundError,
51
- "No documentation for #{@name} embedded '#{name}'"
52
- end
53
- end
54
- end