linked_rails 0.0.4.pre.ge09501794 → 0.0.4.pre.gfabf7e9f5

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: 44eff5276df3db721ed2fc9af75cbe30654a5a39eced5d2d5fc43ee3edf8c565
4
- data.tar.gz: 83f29fa2699f9de8f76e96638cadc37769a175ddadb074058a7cf390925aa5d3
3
+ metadata.gz: d12d8552b0abb2f55672ba9a5b2ae4e2c82b8b0ecd9a58b034cd71065991918f
4
+ data.tar.gz: be43a26a2c5fcae83ac4811b0e79fb9903bdba722e45e9e385a90a1e4c6534de
5
5
  SHA512:
6
- metadata.gz: dea2b33a380c08e58594fe8b97da2c85c02ab40cef2c489e91ac03798391daa1b645b218286d534bf97e57a7f9574cad8158454281c31fdcfb92926c19f634af
7
- data.tar.gz: 056a449612b7c80ebce2b127e8f6242bd5b3738a58a374e5760b70f65d380a8d7fd6b3d2bd30737e20308deab63b953d359de0836f199c1f143df6222e973d05
6
+ metadata.gz: 4db097ca23b358535b5d6db20c947046633e347a7e9cd68402bb1bf6ed4ad4d8b05290a59d1ff53523c77d7c0b1c42ad93b9cfbf468c86d60adbd2aa52be9870
7
+ data.tar.gz: 3e5c0add9dd97d2ab2764043231a0999af174e92ea197c59c68cbbc35c916edbe7169dc32d4e45d90f17e9dd77513f52c99352825c2193a1db50ba74767c2490
@@ -98,6 +98,8 @@ module LinkedRails
98
98
  params = param.permit(:include, :iri)
99
99
  params[:iri] = URI(params[:iri])
100
100
  params
101
+ rescue URI::InvalidURIError
102
+ params.except(:iri)
101
103
  end
102
104
 
103
105
  def resource_response_body(iri, rack_body, status)
@@ -161,13 +163,17 @@ module LinkedRails
161
163
 
162
164
  resource_response(
163
165
  iri,
164
- body: include && status == 200 ? resource_body(resource) : nil,
166
+ body: response_from_resource_body(include, iri, resource, status),
165
167
  cache: resource_cache_control(resource.try(:cacheable?), status, resource_policy),
166
168
  language: I18n.locale,
167
169
  status: status
168
170
  )
169
171
  end
170
172
 
173
+ def response_from_resource_body(include, _iri, resource, status)
174
+ include && status == 200 ? resource_body(resource) : nil
175
+ end
176
+
171
177
  def term_from_vocab(iri)
172
178
  vocab = Vocab.for(iri)
173
179
  tag = iri.to_s.split(vocab.to_s).last
@@ -245,7 +251,7 @@ module LinkedRails
245
251
 
246
252
  def sanitized_relative_path(iri) # rubocop:disable Metrics/AbcSize
247
253
  iri.path = "#{iri.path}/" unless iri.path&.ends_with?('/')
248
- uri = URI(LinkedRails.iri.path.present? ? iri.to_s.split("#{LinkedRails.iri.path}/").last : iri)
254
+ uri = URI(LinkedRails.iri.path.chomp('/').present? ? iri.to_s.split("#{LinkedRails.iri.path}/").last : iri)
249
255
 
250
256
  [uri.path, uri.query].compact.join('?')
251
257
  end
@@ -187,7 +187,7 @@ module LinkedRails
187
187
 
188
188
  def target_url_fallback # rubocop:disable Metrics/AbcSize
189
189
  base = (resource.try(:singular_resource?) ? resource.singular_iri : resource.iri).dup
190
- base.path = "#{base.path}/#{target_path}" if target_path.present?
190
+ base.path = "#{base.path.chomp('/')}/#{target_path}" if target_path.present?
191
191
  base.query = Rack::Utils.parse_nested_query(base.query).merge(target_query).to_param if target_query.present?
192
192
  base
193
193
  end
@@ -8,8 +8,9 @@ module LinkedRails
8
8
  include LinkedRails::Model
9
9
 
10
10
  attr_accessor :collection, :filter
11
- delegate :apply_scope, :association_base, :association_class, :default_page_size, :display, :include_members,
12
- :parent, :policy, :total_page_count, :unfiltered_collection, :user_context, to: :collection
11
+ delegate :apply_scope, :association_base, :association_class, :child_resource, :default_page_size, :display,
12
+ :include_members,:parent, :policy, :total_page_count, :unfiltered_collection, :user_context,
13
+ to: :collection
13
14
  delegate :count, to: :members
14
15
 
15
16
  alias id iri
@@ -42,7 +43,7 @@ module LinkedRails
42
43
  end
43
44
 
44
45
  def preview_includes
45
- include_members ? {member_sequence: :members} : %i[member_sequence]
46
+ include_members ? {members: {}, member_sequence: :members} : %i[member_sequence]
46
47
  end
47
48
 
48
49
  def title
@@ -52,13 +52,7 @@ module LinkedRails
52
52
  private
53
53
 
54
54
  def attr_column(name)
55
- column_model =
56
- if model_class.is_delegated_attribute?(name)
57
- model_class.class_for_delegated_attribute(name)
58
- else
59
- model_class
60
- end
61
- column_model.column_for_attribute(name)
55
+ model_class.column_for_attribute(name)
62
56
  end
63
57
 
64
58
  def attr_to_datatype # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
@@ -9,7 +9,7 @@ module LinkedRails
9
9
  Storage.hset(
10
10
  :persistent,
11
11
  :manifest,
12
- LinkedRails.iri.to_s => web_manifest.to_json
12
+ URL.as_href(LinkedRails.iri) => web_manifest.to_json
13
13
  )
14
14
  end
15
15
 
@@ -41,7 +41,7 @@ module LinkedRails
41
41
  def blob_preview_iri
42
42
  return unless ActiveStorage::Blob.service.present?
43
43
 
44
- LinkedRails.iri(path: 'rails/active_storage/blobs/redirect/{signed_id}/preview')
44
+ "#{LinkedRails.iri(path: 'rails/active_storage/blobs/redirect')}/{signed_id}/preview"
45
45
  end
46
46
 
47
47
  def blob_upload_iri
@@ -138,7 +138,7 @@ module LinkedRails
138
138
 
139
139
  def web_manifest_sw_section
140
140
  {
141
- src: "#{scope}/sw.js",
141
+ src: "#{scope.chomp('/')}/sw.js",
142
142
  scope: scope
143
143
  }
144
144
  end
@@ -161,19 +161,19 @@ module LinkedRails
161
161
 
162
162
  class << self
163
163
  def destroy(iri)
164
- Storage.hdel(:persistent, :manifest, iri)
164
+ Storage.hdel(:persistent, :manifest, URL.as_href(iri))
165
165
  end
166
166
 
167
167
  def move(from, to)
168
168
  Storage.hset(
169
169
  :persistent,
170
- :redirect,
171
- "#{from}*" => to
170
+ :redirect_prefix,
171
+ URL.as_href(from) => URL.as_href(to)
172
172
  )
173
173
 
174
- data = Storage.hget(:persistent, :manifest, from)
174
+ data = Storage.hget(:persistent, :manifest, URL.as_href(from))
175
175
 
176
- Storage.hset(:persistent, :manifest, to, data) if data
176
+ Storage.hset(:persistent, :manifest, URL.as_href(to), data) if data
177
177
 
178
178
  destroy(from)
179
179
  end
@@ -81,7 +81,7 @@ module LinkedRails
81
81
  parent = parent_from_params(params, user_context)
82
82
  return if parent.blank?
83
83
 
84
- parent.menu_sequence
84
+ parent.try(:menu_sequence)
85
85
  end
86
86
  end
87
87
  end
@@ -17,6 +17,7 @@ module LinkedRails
17
17
  has_one :collection, predicate: Vocab.as.partOf
18
18
  has_one :unfiltered_collection, predicate: Vocab.ontola[:baseCollection]
19
19
  has_one :member_sequence, predicate: Vocab.as.items
20
+ has_many :members
20
21
  end
21
22
  end
22
23
  end
@@ -58,7 +58,10 @@ module LinkedRails
58
58
  end
59
59
 
60
60
  def new_resource_from_parent
61
- return requested_resource.child_resource if requested_resource.is_a?(Collection)
61
+ if requested_resource.is_a?(LinkedRails.collection_class) ||
62
+ requested_resource.is_a?(LinkedRails.collection_view_class)
63
+ return requested_resource.child_resource
64
+ end
62
65
 
63
66
  parent_resource.build_child(
64
67
  controller_class,
@@ -38,7 +38,7 @@ module LinkedRails
38
38
  params = Rails.application.routes.recognize_path(iri.to_s, method: method)
39
39
 
40
40
  route_params_to_opts(params.merge(query), iri.to_s)
41
- rescue ActionController::RoutingError
41
+ rescue ActionController::RoutingError, SystemStackError
42
42
  EMPTY_IRI_OPTS.dup
43
43
  end
44
44
 
@@ -17,8 +17,6 @@ module LinkedRails
17
17
  true
18
18
  end
19
19
 
20
- private
21
-
22
20
  def publish_create
23
21
  publish_message('io.ontola.transactions.Created')
24
22
  end
@@ -31,14 +29,14 @@ module LinkedRails
31
29
  publish_message('io.ontola.transactions.Deleted')
32
30
  end
33
31
 
32
+ private
33
+
34
34
  def publish_message(type)
35
35
  LinkedRails::InvalidationStreamWorker.perform_now(type, iri.to_s, self.class.iri.to_s)
36
36
  rescue StandardError
37
37
  LinkedRails::InvalidationStreamWorker.perform_later(type, iri.to_s, self.class.iri.to_s)
38
38
  end
39
39
 
40
- private
41
-
42
40
  def should_publish_changes
43
41
  cacheable? && !Rails.env.test?
44
42
  end
@@ -62,6 +62,7 @@ module LinkedRails
62
62
  iri = root_relative_iri.dup
63
63
  iri.scheme = LinkedRails.scheme
64
64
  iri.host = LinkedRails.host
65
+ iri.path = iri.path.presence || '/'
65
66
  iri
66
67
  end
67
68
 
@@ -11,7 +11,8 @@ module LinkedRails
11
11
  }.freeze
12
12
  KEYS = {
13
13
  manifest: 'cache:Manifest',
14
- redirect: 'cache:Redirect'
14
+ redirect_exact: 'cache:Redirect:Exact',
15
+ redirect_prefix: 'cache:Redirect:Prefix'
15
16
  }.freeze
16
17
 
17
18
  class << self
@@ -0,0 +1,11 @@
1
+ module LinkedRails
2
+ class URL
3
+ class << self
4
+ def as_href(url)
5
+ uri = URI(url)
6
+ uri.path = uri.path.presence || '/'
7
+ uri.to_s
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/linked_rails.rb CHANGED
@@ -54,8 +54,10 @@ module LinkedRails
54
54
  @@scheme ||= Rails.application.routes.default_url_options[:protocol] || :http # rubocop:disable Style/ClassVars
55
55
  end
56
56
 
57
- def iri(**opts)
58
- RDF::URI.new(**{scheme: LinkedRails.scheme, host: LinkedRails.host}.merge(opts))
57
+ def iri(**args)
58
+ opts = {scheme: LinkedRails.scheme, host: LinkedRails.host}.merge(args)
59
+ opts[:path] = opts[:path].presence || '/'
60
+ RDF::URI.new(**opts)
59
61
  end
60
62
  end
61
63
 
@@ -106,4 +108,5 @@ require 'linked_rails/routes'
106
108
  require 'linked_rails/serializer'
107
109
  require 'linked_rails/translate'
108
110
  require 'linked_rails/railtie'
111
+ require 'linked_rails/url'
109
112
  require 'linked_rails/storage'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linked_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.pre.ge09501794
4
+ version: 0.0.4.pre.gfabf7e9f5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Dingemans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-10 00:00:00.000000000 Z
11
+ date: 2022-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_response
@@ -429,6 +429,7 @@ files:
429
429
  - lib/linked_rails/translate.rb
430
430
  - lib/linked_rails/types/iri_type.rb
431
431
  - lib/linked_rails/uri_template.rb
432
+ - lib/linked_rails/url.rb
432
433
  - lib/linked_rails/version.rb
433
434
  - lib/linked_rails/vocab.rb
434
435
  - lib/nill_class_renderer.rb