linked_rails 0.0.4.pre.g1faca9643 → 0.0.4.pre.g2c6c26e86

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: 7bcaf6bc87f6e88d1626c597fea7cf0361c4f1a9ee572715996fdc8d03984775
4
- data.tar.gz: 23b91ff76861c82af758a145a57da5ceb1f454d846fe2a96a3b091dd70a2f725
3
+ metadata.gz: 625693a3e58e4d005b413c33c0d9a7a46718a2780d8e04cf700338064388e38c
4
+ data.tar.gz: 3425709177e527cf2e7e66eb29d68c92862aad3fea333b36afeb93a3b51aeac8
5
5
  SHA512:
6
- metadata.gz: 7a0c7d898e9c886863e8ef882fc2b95a24fb6ce59fb5a9a608556d7e374741a529bc8a672f1d69367b8845c6c77ef477c7a2093591b9e9af4fe487b5c30a5511
7
- data.tar.gz: fe4952657dd9897c0fd430ff679f75d1d71423ec27f9f610ab2e43fb4e77fe9885873d1756989f80dd67e0d7953cfe0e3d926bd2711a87e8b7b591258456cc4e
6
+ metadata.gz: e006633be69326549671449c41daba02fea267aede7f8a5488fd31e8e72287bf745cb8a515391898caca13642957bfb7602f9bd143f3e49744fad4fe533f5b09
7
+ data.tar.gz: 3476439c758b232542a529a1502b7bc9f8469f7841ccb4c16404195742afce86cc5d71f5f59fa4f90cfc4326bde07533e79359d12f45bf8cf81bc6b51dcbcdfc
@@ -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)
@@ -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
@@ -4,7 +4,11 @@ module LinkedRails
4
4
  class Form
5
5
  class Field
6
6
  class FileInput < Field
7
- attr_accessor :max_size
7
+ attr_writer :max_size
8
+
9
+ def max_size
10
+ @max_size.respond_to?(:call) ? @max_size.call : @max_size
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -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
@@ -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
@@ -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
@@ -49,9 +49,8 @@ module LinkedRails
49
49
  end
50
50
 
51
51
  def menu_item(tag, options) # rubocop:disable Metrics/AbcSize
52
- if options[:policy].present?
53
- return unless resource_policy(options[:policy_resource]).send(options[:policy], *options[:policy_arguments])
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
 
@@ -8,6 +8,7 @@ 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
11
12
  verdict
12
13
  end
13
14
 
@@ -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
 
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.g1faca9643
4
+ version: 0.0.4.pre.g2c6c26e86
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-15 00:00:00.000000000 Z
11
+ date: 2022-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_response