linked_rails 0.0.4.pre.gb254a2893 → 0.0.4.pre.gc3dfc6914

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a9f365ba2a3373bce2eaeaa94f02a9c00f7210c5daa4d1793be61bb235c15a6
4
- data.tar.gz: a95518605eccf13bf50eb4eaa86ff37b8d397c0c6d074f064b1835054cac9298
3
+ metadata.gz: 4c46a1b1dd79f52ab737125d44fbf850d58ce90cfedfda01fc41f09f23479afd
4
+ data.tar.gz: 21772f28097f492ea3593f79e0c1ecaddaacdb91e04e62ac3c08497aacb1afbb
5
5
  SHA512:
6
- metadata.gz: '0629170f7ef4b431900c358f7aa5e3ce78c2345ada4a472f3385884973051cc81aa73fe3211b19e4c9d1be03fc2e42555426fa0d31d5b9e9d53c748a98527615'
7
- data.tar.gz: 29cc55d690cd807975a4b04e2e1b6e8b2f6de81a957382a1bcc49feca9b42f17a25655c7a9552c52584257a4dc1412587838a8fe272866c7cd10b902fe8e0de2
6
+ metadata.gz: d17d949a1683172351c183f24be5174d36a96dba396a417a58448c5d72a22a5e833d7db8ca0056ec08cc25ddbc2ef5ac5da02a4bd7598b279336fb46fe95c47f
7
+ data.tar.gz: ddb938f6a9d7c3b3bc148c5bc6153318f0508eb6c57f101ee47434c900709538caf3dde57ae00b0813b95a09ef109d534b6c2fc4d2447e1ee5bc4c5d7e0ab5fe
@@ -98,8 +98,6 @@ 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)
103
101
  end
104
102
 
105
103
  def resource_response_body(iri, rack_body, status)
@@ -163,17 +161,13 @@ module LinkedRails
163
161
 
164
162
  resource_response(
165
163
  iri,
166
- body: response_from_resource_body(include, iri, resource, status),
164
+ body: include && status == 200 ? resource_body(resource) : nil,
167
165
  cache: resource_cache_control(resource.try(:cacheable?), status, resource_policy),
168
166
  language: I18n.locale,
169
167
  status: status
170
168
  )
171
169
  end
172
170
 
173
- def response_from_resource_body(include, _iri, resource, status)
174
- include && status == 200 ? resource_body(resource) : nil
175
- end
176
-
177
171
  def term_from_vocab(iri)
178
172
  vocab = Vocab.for(iri)
179
173
  tag = iri.to_s.split(vocab.to_s).last
@@ -251,7 +245,7 @@ module LinkedRails
251
245
 
252
246
  def sanitized_relative_path(iri) # rubocop:disable Metrics/AbcSize
253
247
  iri.path = "#{iri.path}/" unless iri.path&.ends_with?('/')
254
- uri = URI(LinkedRails.iri.path.chomp('/').present? ? iri.to_s.split("#{LinkedRails.iri.path}/").last : iri)
248
+ uri = URI(LinkedRails.iri.path.present? ? iri.to_s.split("#{LinkedRails.iri.path}/").last : iri)
255
249
 
256
250
  [uri.path, uri.query].compact.join('?')
257
251
  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.chomp('/')}/#{target_path}" if target_path.present?
190
+ base.path = "#{base.path}/#{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,9 +8,8 @@ module LinkedRails
8
8
  include LinkedRails::Model
9
9
 
10
10
  attr_accessor :collection, :filter
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
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
14
13
  delegate :count, to: :members
15
14
 
16
15
  alias id iri
@@ -43,7 +42,7 @@ module LinkedRails
43
42
  end
44
43
 
45
44
  def preview_includes
46
- include_members ? {members: {}, member_sequence: :members} : %i[member_sequence]
45
+ include_members ? {member_sequence: :members} : %i[member_sequence]
47
46
  end
48
47
 
49
48
  def title
@@ -4,11 +4,7 @@ module LinkedRails
4
4
  class Form
5
5
  class Field
6
6
  class FileInput < Field
7
- attr_writer :max_size
8
-
9
- def max_size
10
- @max_size.respond_to?(:call) ? @max_size.call : @max_size
11
- end
7
+ attr_accessor :max_size
12
8
  end
13
9
  end
14
10
  end
@@ -52,7 +52,13 @@ module LinkedRails
52
52
  private
53
53
 
54
54
  def attr_column(name)
55
- model_class.column_for_attribute(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)
56
62
  end
57
63
 
58
64
  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
- URL.as_href(LinkedRails.iri) => web_manifest.to_json
12
+ LinkedRails.iri.to_s => 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.chomp('/')}/sw.js",
141
+ src: "#{scope}/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, URL.as_href(iri))
164
+ Storage.hdel(:persistent, :manifest, iri)
165
165
  end
166
166
 
167
167
  def move(from, to)
168
168
  Storage.hset(
169
169
  :persistent,
170
- :redirect_prefix,
171
- URL.as_href(from) => URL.as_href(to)
170
+ :redirect,
171
+ "#{from}*" => to
172
172
  )
173
173
 
174
- data = Storage.hget(:persistent, :manifest, URL.as_href(from))
174
+ data = Storage.hget(:persistent, :manifest, from)
175
175
 
176
- Storage.hset(:persistent, :manifest, URL.as_href(to), data) if data
176
+ Storage.hset(:persistent, :manifest, 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.try(:menu_sequence)
84
+ parent.menu_sequence
85
85
  end
86
86
  end
87
87
  end
@@ -49,8 +49,9 @@ module LinkedRails
49
49
  end
50
50
 
51
51
  def menu_item(tag, options) # rubocop:disable Metrics/AbcSize
52
- return unless show_menu_item?(tag, options)
53
-
52
+ if options[:policy].present?
53
+ return unless resource_policy(options[:policy_resource]).send(options[:policy], *options[:policy_arguments])
54
+ end
54
55
  options[:label_params] ||= {}
55
56
  options[:label_params][:default] ||= ["menus.default.#{tag}".to_sym, tag.to_s.capitalize]
56
57
  options[:label] ||= default_label(tag, options)
@@ -59,10 +60,6 @@ module LinkedRails
59
60
  LinkedRails.menus_item_class.new(resource: resource, tag: tag, parent: self, **options)
60
61
  end
61
62
 
62
- def policy_verdict(policy, options)
63
- policy.send(options[:policy], *options[:policy_arguments])
64
- end
65
-
66
63
  def resource_policy(policy_resource)
67
64
  policy_resource ||= resource
68
65
  policy_resource = instance_exec(&policy_resource) if policy_resource.respond_to?(:call)
@@ -72,14 +69,6 @@ module LinkedRails
72
69
  @resource_policy[policy_resource] ||= Pundit.policy(user_context, policy_resource)
73
70
  end
74
71
 
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
-
83
72
  def iri_template
84
73
  base_template = resource.send(resource.try(:singular_resource?) ? :singular_iri_template : :iri_template)
85
74
 
@@ -8,7 +8,6 @@ module LinkedRails
8
8
  policy = Pundit.policy!(user_context, child_resource)
9
9
  verdict = policy.create?
10
10
  @message = policy.message
11
- @action_status = policy.action_status
12
11
  verdict
13
12
  end
14
13
 
@@ -17,7 +17,6 @@ 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
21
20
  end
22
21
  end
23
22
  end
@@ -8,7 +8,7 @@ module LinkedRails
8
8
  resource: iri,
9
9
  resourceType: resource_type
10
10
  }
11
- id = Storage.xadd(:stream, LinkedRails.cache_stream, entry)
11
+ id = Storage.xadd(:stream, entry)
12
12
 
13
13
  raise('No message id returned, implies failure') if id.blank?
14
14
  end
@@ -58,10 +58,7 @@ module LinkedRails
58
58
  end
59
59
 
60
60
  def new_resource_from_parent
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
61
+ return requested_resource.child_resource if requested_resource.is_a?(Collection)
65
62
 
66
63
  parent_resource.build_child(
67
64
  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, SystemStackError
41
+ rescue ActionController::RoutingError
42
42
  EMPTY_IRI_OPTS.dup
43
43
  end
44
44
 
@@ -17,6 +17,8 @@ module LinkedRails
17
17
  true
18
18
  end
19
19
 
20
+ private
21
+
20
22
  def publish_create
21
23
  publish_message('io.ontola.transactions.Created')
22
24
  end
@@ -29,14 +31,14 @@ module LinkedRails
29
31
  publish_message('io.ontola.transactions.Deleted')
30
32
  end
31
33
 
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
+
40
42
  def should_publish_changes
41
43
  cacheable? && !Rails.env.test?
42
44
  end
@@ -62,7 +62,6 @@ 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 || '/'
66
65
  iri
67
66
  end
68
67
 
@@ -118,13 +118,9 @@ module LinkedRails
118
118
  end
119
119
 
120
120
  def parse_attribute(klass, field_options, value)
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]
121
+ parsed_value = parse_enum_attribute(klass, field_options.key, value) || value
126
122
 
127
- (parse_enum_attribute(klass, field_options.key, value) || value).to_s
123
+ [field_options.key, parsed_value.to_s]
128
124
  end
129
125
 
130
126
  def parse_enum_attribute(klass, key, value)
@@ -137,15 +133,9 @@ module LinkedRails
137
133
 
138
134
  def parse_iri_param(iri, reflection)
139
135
  key = foreign_key_for_reflection(reflection)
140
- return unless key
136
+ value = parse_iri_param_value(iri, reflection) if key
141
137
 
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
138
+ [key, value.to_s] if value
149
139
  end
150
140
 
151
141
  def parse_iri_param_value(iri, reflection)
@@ -11,8 +11,7 @@ module LinkedRails
11
11
  }.freeze
12
12
  KEYS = {
13
13
  manifest: 'cache:Manifest',
14
- redirect_exact: 'cache:Redirect:Exact',
15
- redirect_prefix: 'cache:Redirect:Prefix'
14
+ redirect: 'cache:Redirect'
16
15
  }.freeze
17
16
 
18
17
  class << self
data/lib/linked_rails.rb CHANGED
@@ -54,10 +54,8 @@ 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(**args)
58
- opts = {scheme: LinkedRails.scheme, host: LinkedRails.host}.merge(args)
59
- opts[:path] = opts[:path].presence || '/'
60
- RDF::URI.new(**opts)
57
+ def iri(**opts)
58
+ RDF::URI.new(**{scheme: LinkedRails.scheme, host: LinkedRails.host}.merge(opts))
61
59
  end
62
60
  end
63
61
 
@@ -108,5 +106,4 @@ require 'linked_rails/routes'
108
106
  require 'linked_rails/serializer'
109
107
  require 'linked_rails/translate'
110
108
  require 'linked_rails/railtie'
111
- require 'linked_rails/url'
112
109
  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.gb254a2893
4
+ version: 0.0.4.pre.gc3dfc6914
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-30 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_response
@@ -429,7 +429,6 @@ 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
433
432
  - lib/linked_rails/version.rb
434
433
  - lib/linked_rails/vocab.rb
435
434
  - lib/nill_class_renderer.rb
@@ -1,11 +0,0 @@
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