linked_rails 0.0.4.pre.g72bb595fe → 0.0.4.pre.g222bfeeca
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/linked_rails/bulk_controller.rb +3 -1
- data/app/models/linked_rails/actions/item.rb +1 -1
- data/app/models/linked_rails/collection/view.rb +9 -8
- data/app/models/linked_rails/form/field/file_input.rb +5 -1
- data/app/models/linked_rails/form/field_factory.rb +1 -7
- data/app/models/linked_rails/manifest.rb +7 -7
- data/app/models/linked_rails/menus/item.rb +1 -1
- data/app/models/linked_rails/menus/list.rb +14 -3
- data/app/policies/linked_rails/collection_policy.rb +1 -0
- data/app/serializers/linked_rails/collection/view_serializer.rb +1 -0
- data/lib/linked_rails/helpers/resource_helper.rb +4 -1
- data/lib/linked_rails/iri_mapper.rb +1 -1
- data/lib/linked_rails/model/collections.rb +3 -1
- data/lib/linked_rails/model/iri.rb +1 -0
- data/lib/linked_rails/params_parser.rb +14 -4
- data/lib/linked_rails/url.rb +11 -0
- data/lib/linked_rails.rb +5 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd9b4e8c03eaa18c8caf50b78d32ce0308439d18dcfe4ad712b029e6110afba2
|
4
|
+
data.tar.gz: 47b2df4167fb6731b4adbbd5aa49174c882ad9fa5e3031319f3a853ea29caa08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6720e547504da1983928e5d27dbcbfda727aaf5f69467dfa1a9e0b056ea1b678243d4e26484db3939069eedd9bed415a086e85f003deeb72983534fde939e79e
|
7
|
+
data.tar.gz: 07cbdab89b3ef4184ff48e8bafe5d4c50da244d934da82ba71c86aaa518ed9efc47820de8d097524659f0f8b49943b34f1edb8b102179fe2e622d8507ce25b85
|
@@ -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)
|
@@ -249,7 +251,7 @@ module LinkedRails
|
|
249
251
|
|
250
252
|
def sanitized_relative_path(iri) # rubocop:disable Metrics/AbcSize
|
251
253
|
iri.path = "#{iri.path}/" unless iri.path&.ends_with?('/')
|
252
|
-
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)
|
253
255
|
|
254
256
|
[uri.path, uri.query].compact.join('?')
|
255
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, :
|
12
|
-
:parent, :policy, :total_page_count, :unfiltered_collection, :user_context,
|
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
|
@@ -75,19 +76,19 @@ module LinkedRails
|
|
75
76
|
end
|
76
77
|
|
77
78
|
def iris_from_scope?
|
78
|
-
members_query.is_a?(ActiveRecord::Relation) && !polymorphic_collection?
|
79
|
+
members_query.is_a?(ActiveRecord::Relation) && !polymorphic_collection?(members_query.klass)
|
79
80
|
end
|
80
81
|
|
81
82
|
def members_array
|
82
83
|
members_query.to_a
|
83
84
|
end
|
84
85
|
|
85
|
-
def polymorphic_collection?
|
86
|
-
column =
|
87
|
-
polymorphic =
|
86
|
+
def polymorphic_collection?(klass)
|
87
|
+
column = klass.inheritance_column
|
88
|
+
polymorphic = klass.columns_hash.include?(column)
|
88
89
|
return false unless polymorphic
|
89
90
|
|
90
|
-
return true if
|
91
|
+
return true if klass.descends_from_active_record?
|
91
92
|
|
92
93
|
members_query.where_values_hash.include?(column) &&
|
93
94
|
members_query.where_values_hash[column] != association_class.to_s
|
@@ -52,13 +52,7 @@ module LinkedRails
|
|
52
52
|
private
|
53
53
|
|
54
54
|
def attr_column(name)
|
55
|
-
|
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
|
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
170
|
:redirect_prefix,
|
171
|
-
from => to
|
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
|
@@ -49,9 +49,8 @@ module LinkedRails
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def menu_item(tag, options) # rubocop:disable Metrics/AbcSize
|
52
|
-
|
53
|
-
|
54
|
-
end
|
52
|
+
return unless show_menu_item?(tag, options)
|
53
|
+
|
55
54
|
options[:label_params] ||= {}
|
56
55
|
options[:label_params][:default] ||= ["menus.default.#{tag}".to_sym, tag.to_s.capitalize]
|
57
56
|
options[:label] ||= default_label(tag, options)
|
@@ -60,6 +59,10 @@ module LinkedRails
|
|
60
59
|
LinkedRails.menus_item_class.new(resource: resource, tag: tag, parent: self, **options)
|
61
60
|
end
|
62
61
|
|
62
|
+
def policy_verdict(policy, options)
|
63
|
+
policy.send(options[:policy], *options[:policy_arguments])
|
64
|
+
end
|
65
|
+
|
63
66
|
def resource_policy(policy_resource)
|
64
67
|
policy_resource ||= resource
|
65
68
|
policy_resource = instance_exec(&policy_resource) if policy_resource.respond_to?(:call)
|
@@ -69,6 +72,14 @@ module LinkedRails
|
|
69
72
|
@resource_policy[policy_resource] ||= Pundit.policy(user_context, policy_resource)
|
70
73
|
end
|
71
74
|
|
75
|
+
def show_menu_item?(_tag, options)
|
76
|
+
return true if options[:policy].blank?
|
77
|
+
|
78
|
+
policy = resource_policy(options[:policy_resource])
|
79
|
+
|
80
|
+
policy_verdict(policy, options)
|
81
|
+
end
|
82
|
+
|
72
83
|
def iri_template
|
73
84
|
base_template = resource.send(resource.try(:singular_resource?) ? :singular_iri_template : :iri_template)
|
74
85
|
|
@@ -58,7 +58,10 @@ module LinkedRails
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def new_resource_from_parent
|
61
|
-
|
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
|
|
@@ -70,7 +70,9 @@ module LinkedRails
|
|
70
70
|
|
71
71
|
module ClassMethods
|
72
72
|
def collection_iri(**opts)
|
73
|
-
|
73
|
+
fragment = opts.delete(:fragment)
|
74
|
+
|
75
|
+
LinkedRails.iri(path: collection_root_relative_iri(**opts), fragment: fragment)
|
74
76
|
end
|
75
77
|
|
76
78
|
# Sets the defaults for all collections for this class.
|
@@ -118,9 +118,13 @@ module LinkedRails
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def parse_attribute(klass, field_options, value)
|
121
|
-
|
121
|
+
[field_options.key, parse_attribute_value(klass, field_options, value)]
|
122
|
+
end
|
123
|
+
|
124
|
+
def parse_attribute_value(klass, field_options, value)
|
125
|
+
return nil if value == Vocab.libro[:null]
|
122
126
|
|
123
|
-
|
127
|
+
(parse_enum_attribute(klass, field_options.key, value) || value).to_s
|
124
128
|
end
|
125
129
|
|
126
130
|
def parse_enum_attribute(klass, key, value)
|
@@ -133,9 +137,15 @@ module LinkedRails
|
|
133
137
|
|
134
138
|
def parse_iri_param(iri, reflection)
|
135
139
|
key = foreign_key_for_reflection(reflection)
|
136
|
-
|
140
|
+
return unless key
|
137
141
|
|
138
|
-
|
142
|
+
if iri == Vocab.libro[:null]
|
143
|
+
[key, nil]
|
144
|
+
else
|
145
|
+
value = parse_iri_param_value(iri, reflection)
|
146
|
+
|
147
|
+
[key, value.to_s] if value
|
148
|
+
end
|
139
149
|
end
|
140
150
|
|
141
151
|
def parse_iri_param_value(iri, reflection)
|
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(**
|
58
|
-
|
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.
|
4
|
+
version: 0.0.4.pre.g222bfeeca
|
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-
|
11
|
+
date: 2022-08-31 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
|