linked_rails 0.0.4.pre.g8c045be3a → 0.0.4.pre.g9e3bcac55
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 +4 -4
- data/app/models/linked_rails/actions/item.rb +14 -6
- data/app/models/linked_rails/actions/object.rb +5 -3
- data/app/models/linked_rails/collection/view.rb +6 -6
- data/app/models/linked_rails/form/field/file_input.rb +5 -1
- data/app/models/linked_rails/menus/list.rb +14 -3
- data/app/policies/linked_rails/collection_policy.rb +1 -0
- data/lib/linked_rails/helpers/delta_helper.rb +3 -1
- data/lib/linked_rails/model/collections.rb +3 -1
- data/lib/linked_rails/params_parser.rb +14 -4
- data/lib/linked_rails/serializer/actionable.rb +3 -3
- data/lib/linked_rails/serializer.rb +7 -1
- metadata +2 -3
- data/app/serializers/linked_rails/actions/object_serializer.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c66380d7f4ca34d26bae943972d7db0bf4df315bee70c2f676dff5a67e9b8d48
|
4
|
+
data.tar.gz: 1e914271f291b9498bb12c8cbf98acc9641b8730e8e4538887bde8e3a03e36b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c9c6d3dd7e7938372aa92f714513f9d3b5374710362afa3a9c6df6a1e683706909c98459c302d3fab7a40d8e604119ad7889190e3c92652fc33da18aa9c7a42
|
7
|
+
data.tar.gz: 6d78dad18fe110f9c52d42db45d58f5ca06eb74301b6684d63f447f8c0f33b440e78bca7067e4ea6f0f7a300baf6966006d9e5f87ff7bd11d042c2bc0e30961c
|
@@ -61,13 +61,15 @@ module LinkedRails
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def object
|
64
|
-
|
65
|
-
|
66
|
-
@object || resource
|
64
|
+
object_from_var || resource
|
67
65
|
end
|
68
66
|
|
69
67
|
def object_iri
|
70
|
-
|
68
|
+
iri_with_root(object_root_relative_iri)
|
69
|
+
end
|
70
|
+
|
71
|
+
def object_root_relative_iri
|
72
|
+
object&.iri&.anonymous? ? anonymous_object_root_relative_iri : object&.root_relative_iri
|
71
73
|
end
|
72
74
|
|
73
75
|
def parent
|
@@ -138,8 +140,8 @@ module LinkedRails
|
|
138
140
|
|
139
141
|
private
|
140
142
|
|
141
|
-
def
|
142
|
-
object_iri =
|
143
|
+
def anonymous_object_root_relative_iri
|
144
|
+
object_iri = root_relative_iri.dup
|
143
145
|
object_iri.path += '/action_object'
|
144
146
|
object_iri
|
145
147
|
end
|
@@ -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
|
16
|
-
action.
|
15
|
+
def root_relative_iri
|
16
|
+
action.object_root_relative_iri
|
17
17
|
end
|
18
18
|
|
19
19
|
class << self
|
@@ -30,7 +30,9 @@ module LinkedRails
|
|
30
30
|
|
31
31
|
parent = parent_from_params!(params, user_context)
|
32
32
|
|
33
|
-
|
33
|
+
object = parent&.object
|
34
|
+
object.instance_variable_set(:@iri, parent.object_iri)
|
35
|
+
object
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -43,7 +43,7 @@ module LinkedRails
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def preview_includes
|
46
|
-
include_members ? {members: {}, member_sequence: :members} : %i[member_sequence
|
46
|
+
include_members ? {members: {}, member_sequence: :members} : %i[member_sequence]
|
47
47
|
end
|
48
48
|
|
49
49
|
def title
|
@@ -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 =
|
88
|
-
polymorphic =
|
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
|
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
|
@@ -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
|
|
@@ -8,7 +8,9 @@ module LinkedRails
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def invalidate_collection_delta(collection)
|
11
|
-
|
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)
|
@@ -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)
|
@@ -15,10 +15,10 @@ module LinkedRails
|
|
15
15
|
|
16
16
|
module ClassMethods
|
17
17
|
def action_triples(object, _params)
|
18
|
-
if object
|
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
|
-
|
118
|
+
|
119
|
+
action_object = opts.delete(:action_object)
|
120
|
+
opts[:if] ||= -> (object) {
|
121
|
+
return action_object if object.iri.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.
|
4
|
+
version: 0.0.4.pre.g9e3bcac55
|
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-09-08 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
|