linked_rails 0.0.4.pre.g2c6c26e86 → 0.0.4.pre.g3aeec2263

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: 625693a3e58e4d005b413c33c0d9a7a46718a2780d8e04cf700338064388e38c
4
- data.tar.gz: 3425709177e527cf2e7e66eb29d68c92862aad3fea333b36afeb93a3b51aeac8
3
+ metadata.gz: 0ce41ff4f34f22c35a736959cad35b9a42f3f03938449f918bf492907cdc6337
4
+ data.tar.gz: 86ab4fec516df9fc474a637e6ada4b6466abdbc03b565bbc46d0942026a89cac
5
5
  SHA512:
6
- metadata.gz: e006633be69326549671449c41daba02fea267aede7f8a5488fd31e8e72287bf745cb8a515391898caca13642957bfb7602f9bd143f3e49744fad4fe533f5b09
7
- data.tar.gz: 3476439c758b232542a529a1502b7bc9f8469f7841ccb4c16404195742afce86cc5d71f5f59fa4f90cfc4326bde07533e79359d12f45bf8cf81bc6b51dcbcdfc
6
+ metadata.gz: f4ab1bb7933a05fc0377f588ff8fa6340470341f0a45c977008a0fa2b3c226db5da304449b4da5a8fe20da66bc544e3928ce8aaa02d228b0ff9b6f50ed25075c
7
+ data.tar.gz: 0b9c3322d6fb05f2f18e8e777661b276cf9c68c4c540a5b7a66837412888c0876e19d923744d93bc10830d565af5ac0ca458da63ab5aa344ca0f645a221c8949
@@ -144,9 +144,14 @@ module LinkedRails
144
144
  end
145
145
 
146
146
  def resource_status(resource_policy)
147
- raise(LinkedRails::Errors::Forbidden.new(query: :show?)) unless resource_policy.show?
147
+ return 200 if resource_policy.show?
148
148
 
149
- 200
149
+ raise(
150
+ LinkedRails::Errors::Forbidden.new(
151
+ action_status: resource_policy.try(:action_status),
152
+ query: :show?
153
+ )
154
+ )
150
155
  end
151
156
 
152
157
  def response_for_wrong_host(opts)
@@ -61,15 +61,17 @@ module LinkedRails
61
61
  end
62
62
 
63
63
  def object
64
- @object = list.instance_exec(&@object) if @object.respond_to?(:call)
65
-
66
- @object || resource
64
+ object_from_var || resource
67
65
  end
68
66
 
69
67
  def object_iri
70
68
  object&.iri&.anonymous? ? anonymous_object_iri : object&.iri
71
69
  end
72
70
 
71
+ def object_root_relative_iri
72
+ RDF::URI(object_iri.to_s.split(LinkedRails.iri.to_s).second)
73
+ end
74
+
73
75
  def parent
74
76
  return @parent if instance_variable_defined?(:@parent)
75
77
 
@@ -152,6 +154,12 @@ module LinkedRails
152
154
  LinkedRails.translate(:action, :label, self)
153
155
  end
154
156
 
157
+ def object_from_var
158
+ return @object unless @object.respond_to?(:call)
159
+
160
+ @object = list.instance_exec(&@object)
161
+ end
162
+
155
163
  def policy_expired?
156
164
  @policy_expired ||= policy && resource_policy.try(:expired?)
157
165
  end
@@ -12,8 +12,8 @@ module LinkedRails
12
12
  alias parent action
13
13
  delegate :object, to: :action
14
14
 
15
- def iri
16
- action.object_iri
15
+ def root_relative_iri
16
+ action.object_root_relative_iri
17
17
  end
18
18
 
19
19
  class << self
@@ -30,7 +30,10 @@ module LinkedRails
30
30
 
31
31
  parent = parent_from_params!(params, user_context)
32
32
 
33
- new(action: parent) if parent.object.anonymous_iri?
33
+ object = parent&.object
34
+ object.instance_variable_set(:@iri, parent.object_iri)
35
+ object.instance_variable_set(:@root_relative_iri, parent.object_root_relative_iri)
36
+ object
34
37
  end
35
38
  end
36
39
  end
@@ -76,19 +76,19 @@ module LinkedRails
76
76
  end
77
77
 
78
78
  def iris_from_scope?
79
- members_query.is_a?(ActiveRecord::Relation) && !polymorphic_collection?
79
+ members_query.is_a?(ActiveRecord::Relation) && !polymorphic_collection?(members_query.klass)
80
80
  end
81
81
 
82
82
  def members_array
83
83
  members_query.to_a
84
84
  end
85
85
 
86
- def polymorphic_collection?
87
- column = association_class.inheritance_column
88
- polymorphic = association_class.columns_hash.include?(column)
86
+ def polymorphic_collection?(klass)
87
+ column = klass.inheritance_column
88
+ polymorphic = klass.columns_hash.include?(column)
89
89
  return false unless polymorphic
90
90
 
91
- return true if association_class.descends_from_active_record?
91
+ return true if klass.descends_from_active_record?
92
92
 
93
93
  members_query.where_values_hash.include?(column) &&
94
94
  members_query.where_values_hash[column] != association_class.to_s
@@ -120,7 +120,7 @@ module LinkedRails
120
120
 
121
121
  def has_many(key, **opts)
122
122
  opts[:input_field] = Form::Field::AssociationInput
123
- opts[:max_count] = 99
123
+ opts[:max_count] ||= 99
124
124
  field(key, **opts)
125
125
  end
126
126
 
@@ -13,6 +13,7 @@ module LinkedRails
13
13
  end
14
14
  attribute :serialized_iri_template, predicate: Vocab.ontola[:iriTemplate]
15
15
  attribute :iri_template_opts, predicate: Vocab.ontola[:iriTemplateOpts]
16
+ attribute :download_urls, predicate: Vocab.schema.downloadUrl
16
17
  attribute :default_type, predicate: Vocab.ontola[:defaultType], &:type
17
18
  attribute :display, predicate: Vocab.ontola[:collectionDisplay] do |object|
18
19
  Vocab.ontola["collectionDisplay/#{object.display || :default}"]
@@ -3,7 +3,7 @@
3
3
  module LinkedRails
4
4
  module Errors
5
5
  class Forbidden < StandardError
6
- attr_reader :query, :record, :policy, :action
6
+ attr_reader :query, :record, :policy, :action, :action_status
7
7
 
8
8
  # @param [Hash] options
9
9
  # @option options [String] query The action of the request
@@ -16,6 +16,7 @@ module LinkedRails
16
16
  @record = options[:record]
17
17
  @policy = options[:policy]
18
18
  @action = @query[-1] == '?' ? @query[0..-2] : @query
19
+ @action_status = options[:action_status]
19
20
  @message = options[:message]
20
21
 
21
22
  raise StandardError if @query.blank? && @message.blank?
@@ -8,7 +8,9 @@ module LinkedRails
8
8
  end
9
9
 
10
10
  def invalidate_collection_delta(collection)
11
- [Vocab.sp[:Variable], Vocab.ontola[:baseCollection], collection.iri, delta_iri(:invalidate)]
11
+ iri = collection.is_a?(RDF::Resource) ? collection : collection.iri
12
+
13
+ [Vocab.sp[:Variable], Vocab.ontola[:baseCollection], iri, delta_iri(:invalidate)]
12
14
  end
13
15
 
14
16
  def invalidate_parent_collections_delta(resource)
@@ -46,6 +46,8 @@ module LinkedRails
46
46
  default_filters: {},
47
47
  # collection_class [Array<Hash>] The default sortings applied to the collection.
48
48
  default_sortings: [{key: Vocab.schema.dateCreated, direction: :desc}],
49
+ # download_urls [Array<URI>] URLs for downloading the content of this collection
50
+ download_urls: [],
49
51
  # include_members [Boolean] Whether to include the members of this collection.
50
52
  include_members: false,
51
53
  # iri_template_keys [Array<Sym>] Custom query keys for the iri template
@@ -70,7 +72,9 @@ module LinkedRails
70
72
 
71
73
  module ClassMethods
72
74
  def collection_iri(**opts)
73
- LinkedRails.iri(path: collection_root_relative_iri(**opts))
75
+ fragment = opts.delete(:fragment)
76
+
77
+ LinkedRails.iri(path: collection_root_relative_iri(**opts), fragment: fragment)
74
78
  end
75
79
 
76
80
  # Sets the defaults for all collections for this class.
@@ -10,7 +10,7 @@ module LinkedRails
10
10
  end
11
11
 
12
12
  def anonymous_iri?
13
- self.class < ActiveRecord::Base && new_record?
13
+ self.class < ActiveRecord::Base && new_record? && @iri.blank?
14
14
  end
15
15
 
16
16
  # @return [RDF::URI].
@@ -44,7 +44,12 @@ module LinkedRails
44
44
 
45
45
  # @return [RDF::URI]
46
46
  def root_relative_iri(**opts)
47
- RDF::URI(expand_iri_template(**iri_opts.merge(opts)))
47
+ return @root_relative_iri if opts.blank? && @root_relative_iri.present?
48
+
49
+ root_relative_iri = RDF::URI(expand_iri_template(**iri_opts.merge(opts)))
50
+ @root_relative_iri = root_relative_iri if opts.blank?
51
+
52
+ root_relative_iri
48
53
  end
49
54
 
50
55
  # @return [String, Symbol]
@@ -6,16 +6,16 @@ module LinkedRails
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  def menus(user_context = nil)
9
- menu_list(user_context).menus
9
+ menu_list(user_context)&.menus
10
10
  end
11
11
 
12
12
  def menu(tag, user_context = nil)
13
- menu_list(user_context).menu(tag)
13
+ menu_list(user_context)&.menu(tag)
14
14
  end
15
15
 
16
16
  def menu_list(user_context = nil)
17
17
  @menu_list ||= {}
18
- @menu_list[user_context] ||= self.class.menu_class.new(resource: self, user_context: user_context)
18
+ @menu_list[user_context] ||= self.class.menu_class&.new(resource: self, user_context: user_context)
19
19
  end
20
20
 
21
21
  module ClassMethods
@@ -118,9 +118,13 @@ module LinkedRails
118
118
  end
119
119
 
120
120
  def parse_attribute(klass, field_options, value)
121
- parsed_value = parse_enum_attribute(klass, field_options.key, value) || 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]
122
126
 
123
- [field_options.key, parsed_value.to_s]
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
- value = parse_iri_param_value(iri, reflection) if key
140
+ return unless key
137
141
 
138
- [key, value.to_s] if value
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)
@@ -15,10 +15,10 @@ module LinkedRails
15
15
 
16
16
  module ClassMethods
17
17
  def action_triples(object, _params)
18
- if object.iri.anonymous? && !object.try(:singular_resource?)
19
- []
20
- else
18
+ if named_object?(object) || object.try(:singular_resource?)
21
19
  object.try(:action_triples) || []
20
+ else
21
+ []
22
22
  end
23
23
  end
24
24
  end
@@ -115,7 +115,13 @@ module LinkedRails
115
115
  collection_name = "#{name.to_s.singularize}_collection"
116
116
  opts[:association] ||= name
117
117
  opts[:polymorphic] ||= true
118
- opts[:if] ||= method(:named_object?)
118
+
119
+ action_object = opts.delete(:action_object)
120
+ opts[:if] ||= -> (object) {
121
+ return action_object if object.iri.try(:path)&.end_with?('/action_object')
122
+
123
+ named_object?(object)
124
+ }
119
125
 
120
126
  collection_opts = {}
121
127
  collection_opts[:page_size] = opts.delete(:page_size) if opts.key?(:page_size)
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.g2c6c26e86
4
+ version: 0.0.4.pre.g3aeec2263
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-26 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_response
@@ -305,7 +305,6 @@ files:
305
305
  - app/policies/linked_rails/ontology_policy.rb
306
306
  - app/policies/linked_rails/sequence_policy.rb
307
307
  - app/serializers/linked_rails/actions/item_serializer.rb
308
- - app/serializers/linked_rails/actions/object_serializer.rb
309
308
  - app/serializers/linked_rails/collection/filter_field_serializer.rb
310
309
  - app/serializers/linked_rails/collection/filter_option_serializer.rb
311
310
  - app/serializers/linked_rails/collection/filter_serializer.rb
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LinkedRails
4
- module Actions
5
- class ObjectSerializer < LinkedRails.serializer_parent_class
6
- has_one :object, predicate: Vocab.owl.sameAs
7
- end
8
- end
9
- end