wallaby-core 0.3.0.beta1 → 0.3.0.beta2
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/lib/concerns/wallaby/configurable.rb +1 -1
- data/lib/concerns/wallaby/decoratable.rb +10 -5
- data/lib/decorators/wallaby/resource_decorator.rb +19 -0
- data/lib/forms/wallaby/form_builder.rb +1 -1
- data/lib/helpers/wallaby/links_helper.rb +8 -8
- data/lib/responders/wallaby/resources_responder.rb +3 -1
- data/lib/services/wallaby/map/mode_mapper.rb +1 -1
- data/lib/wallaby/core/version.rb +1 -1
- data/lib/wallaby/engine.rb +1 -1
- data/lib/wallaby/preloader.rb +4 -2
- metadata +14 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86ff434d6a25fa665cb828cc1a1839166f386a71dff24afacb7a114402a81f50
|
4
|
+
data.tar.gz: 1a923d492ef62f597608a9c49f8a1341fe59687e8c4668749f3ad25d7a1b1c71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73183959d1177a5d707baae5c698e57f6e5ca47fe4b248e1014402dbe95c9015418d3d6d46194161c38543745c685a99bfacb73c197a1972e85beec758d8598c
|
7
|
+
data.tar.gz: ffdeeb4e9df6b63f281912c21acb758e0a7bb9d8863d38a5e081b5c81cbfed5bf4942910ebf8d03fcef2c90cb8cd66f3bf0d9763302f59ae084003ea4f82dfb3
|
@@ -23,11 +23,7 @@ module Wallaby
|
|
23
23
|
# @return [ResourceDecorator] current resource decorator for this request
|
24
24
|
def current_decorator
|
25
25
|
@current_decorator ||=
|
26
|
-
|
27
|
-
script_name: script_name,
|
28
|
-
model_class: current_model_class,
|
29
|
-
current_controller_class: wallaby_controller
|
30
|
-
).execute.tap do |decorator|
|
26
|
+
decorator_of(current_model_class).tap do |decorator|
|
31
27
|
Logger.debug %(Current decorator: #{decorator}), sourcing: false
|
32
28
|
end
|
33
29
|
end
|
@@ -39,6 +35,15 @@ module Wallaby
|
|
39
35
|
current_model_decorator.try(:"#{action_name}_fields")
|
40
36
|
end
|
41
37
|
|
38
|
+
# Get the decorator of a klass
|
39
|
+
def decorator_of(klass)
|
40
|
+
DecoratorFinder.new(
|
41
|
+
script_name: script_name,
|
42
|
+
model_class: klass,
|
43
|
+
current_controller_class: wallaby_controller
|
44
|
+
).execute
|
45
|
+
end
|
46
|
+
|
42
47
|
# Wrap resource(s) with decorator(s).
|
43
48
|
# @param resource [Object, Enumerable]
|
44
49
|
# @return [ResourceDecorator, Enumerable<Wallaby::ResourceDecorator>] decorator(s)
|
@@ -99,6 +99,13 @@ module Wallaby
|
|
99
99
|
@h ||= superclass.try(:h) || ResourcesController.helpers
|
100
100
|
end
|
101
101
|
|
102
|
+
# @!attribute [w] readonly
|
103
|
+
attr_writer :readonly
|
104
|
+
|
105
|
+
def readonly?
|
106
|
+
@readonly
|
107
|
+
end
|
108
|
+
|
102
109
|
# Delegate missing method to {.model_decorator}
|
103
110
|
def method_missing(method_id, *args, &block)
|
104
111
|
return if ModelDecorator::MISSING_METHODS_RELATED_TO_FIELDS.match?(method_id.to_s) && model_decorator.blank?
|
@@ -179,6 +186,12 @@ module Wallaby
|
|
179
186
|
resource.try(:model_name) || ActiveModel::Name.new(model_class)
|
180
187
|
end
|
181
188
|
|
189
|
+
# @see https://github.com/rails/rails/compare/v7.0.2.4..7-0-stable#diff-44b94eca66c7497711821a8e6bcdfde4684bb7b8efa15e64da6532449f03ef0bR441
|
190
|
+
# @note This overwritten method is a response to the above change
|
191
|
+
def to_model
|
192
|
+
self
|
193
|
+
end
|
194
|
+
|
182
195
|
# @note this method is for the Rails form helper methods to recognize non-ActiveModel models
|
183
196
|
# @return [nil] if no primary key
|
184
197
|
# @return [Array<String>] primary key
|
@@ -187,6 +200,12 @@ module Wallaby
|
|
187
200
|
key ? [key] : nil
|
188
201
|
end
|
189
202
|
|
203
|
+
# @return [true, false] if resource responds to method `.readonly?`
|
204
|
+
# @return [false] otherwise
|
205
|
+
def readonly?
|
206
|
+
resource.try(:readonly?) || self.class.try(:readonly?)
|
207
|
+
end
|
208
|
+
|
190
209
|
# Delegate missing method to {#resource}
|
191
210
|
def method_missing(method_id, *args, &block)
|
192
211
|
if resource.respond_to?(method_id)
|
@@ -15,7 +15,7 @@ module Wallaby
|
|
15
15
|
# @return [String] anchor link to index page for a given model class
|
16
16
|
# @return [nil] if user's not authorized
|
17
17
|
def index_link(model_class, options: {}, url_params: {}, html_options: {}, &block)
|
18
|
-
return if unauthorized?
|
18
|
+
return if unauthorized?(:index, model_class)
|
19
19
|
|
20
20
|
html_options, block = LinkOptionsNormalizer.normalize(
|
21
21
|
html_options, block,
|
@@ -38,7 +38,7 @@ module Wallaby
|
|
38
38
|
# @return [String, nil] anchor element
|
39
39
|
# @return [nil] if user's not authorized
|
40
40
|
def new_link(model_class, options: {}, url_params: {}, html_options: {}, &block)
|
41
|
-
return if unauthorized?
|
41
|
+
return if unauthorized?(:new, model_class) || decorator_of(model_class).readonly?
|
42
42
|
|
43
43
|
html_options, block = LinkOptionsNormalizer.normalize(
|
44
44
|
html_options, block,
|
@@ -73,9 +73,9 @@ module Wallaby
|
|
73
73
|
)
|
74
74
|
|
75
75
|
default = (options[:readonly] && block.call) || nil
|
76
|
-
return default if unauthorized?
|
76
|
+
return default if unauthorized?(:show, extract(resource))
|
77
77
|
|
78
|
-
url = options[:url] || show_path(resource, url_params: url_params)
|
78
|
+
url = options[:url] || show_path(resource.itself, url_params: url_params)
|
79
79
|
link_to url, html_options, &block
|
80
80
|
end
|
81
81
|
|
@@ -100,9 +100,9 @@ module Wallaby
|
|
100
100
|
)
|
101
101
|
|
102
102
|
default = (options[:readonly] && block.call) || nil
|
103
|
-
return default if unauthorized?
|
103
|
+
return default if unauthorized?(:edit, extract(resource)) || resource.try(:readonly?)
|
104
104
|
|
105
|
-
url = options[:url] || edit_path(resource, url_params: url_params)
|
105
|
+
url = options[:url] || edit_path(resource.itself, url_params: url_params)
|
106
106
|
link_to url, html_options, &block
|
107
107
|
end
|
108
108
|
|
@@ -119,7 +119,7 @@ module Wallaby
|
|
119
119
|
# @return [String, nil] anchor element
|
120
120
|
# @return [nil] if user's not authorized
|
121
121
|
def delete_link(resource, options: {}, url_params: {}, html_options: {}, &block)
|
122
|
-
return if unauthorized?
|
122
|
+
return if unauthorized?(:destroy, extract(resource)) || resource.try(:readonly?)
|
123
123
|
|
124
124
|
html_options, block = LinkOptionsNormalizer.normalize(
|
125
125
|
html_options, block, class: 'resource__destroy', block: -> { wt 'links.delete' }
|
@@ -128,7 +128,7 @@ module Wallaby
|
|
128
128
|
html_options[:method] ||= :delete
|
129
129
|
(html_options[:data] ||= {})[:confirm] ||= wt 'links.confirm.delete'
|
130
130
|
|
131
|
-
url = options[:url] || show_path(resource, url_params: url_params)
|
131
|
+
url = options[:url] || show_path(resource.itself, url_params: url_params)
|
132
132
|
link_to url, html_options, &block
|
133
133
|
end
|
134
134
|
|
@@ -17,7 +17,9 @@ module Wallaby
|
|
17
17
|
|
18
18
|
# @return [String] file name with export timestamp
|
19
19
|
def file_name_to_export
|
20
|
-
timestamp = Time.zone.now.
|
20
|
+
timestamp = Time.zone.now.try do |t|
|
21
|
+
t.respond_to?(:to_fs) ? t.to_fs(:number) : t.to_s(:number)
|
22
|
+
end
|
21
23
|
filename =
|
22
24
|
(request.params[:resources] || controller.controller_path)
|
23
25
|
.gsub(/#{SLASH}|#{COLONS}/o, HYPHEN)
|
@@ -16,7 +16,7 @@ module Wallaby
|
|
16
16
|
next if class_names.blank?
|
17
17
|
|
18
18
|
class_names.each_with_object(hash) do |mode_name, map|
|
19
|
-
mode_name.model_finder.new.all.each do |model_class|
|
19
|
+
mode_name.model_finder.new.all.each do |model_class| # rubocop:disable Rails/FindEach
|
20
20
|
map[model_class] = mode_name
|
21
21
|
end
|
22
22
|
end
|
data/lib/wallaby/core/version.rb
CHANGED
data/lib/wallaby/engine.rb
CHANGED
@@ -5,7 +5,7 @@ module Wallaby
|
|
5
5
|
class Engine < ::Rails::Engine
|
6
6
|
initializer 'wallaby.development.reload' do |_|
|
7
7
|
# NOTE: Rails reload! will hit here
|
8
|
-
# @see
|
8
|
+
# @see https://rmosolgo.github.io/ruby/rails/2017/04/12/watching-files-during-rails-development.html
|
9
9
|
config.to_prepare do
|
10
10
|
Map.clear if Rails.env.development? || Rails.configuration.eager_load
|
11
11
|
end
|
data/lib/wallaby/preloader.rb
CHANGED
@@ -15,7 +15,7 @@ module Wallaby
|
|
15
15
|
# Require models under {Configuration#model_paths}
|
16
16
|
# @see #model_file_paths
|
17
17
|
def require_models
|
18
|
-
new.model_file_paths.each { |path| require_dependency(path) }
|
18
|
+
new.model_file_paths.each { |path| require_dependency(path) } # rubocop:disable Rails/RequireDependency, Lint/RedundantCopDisableDirective
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -30,7 +30,9 @@ module Wallaby
|
|
30
30
|
# @!attribute [r] eager_load_paths
|
31
31
|
# @return [Array<String, Pathname>]
|
32
32
|
def eager_load_paths # :nodoc:
|
33
|
-
@eager_load_paths ||=
|
33
|
+
@eager_load_paths ||=
|
34
|
+
Rails.configuration.paths['app'].expanded
|
35
|
+
.concat(Rails.configuration.eager_load_paths)
|
34
36
|
end
|
35
37
|
|
36
38
|
# @!attribute [w] model_paths
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wallaby-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0.
|
4
|
+
version: 0.3.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tian Chen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -16,40 +16,34 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 7.1.0
|
19
|
+
version: 6.0.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 7.1.0
|
26
|
+
version: 6.0.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: railties
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
33
|
+
version: 6.0.0
|
40
34
|
- - "<"
|
41
35
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
36
|
+
version: 8.0.0
|
43
37
|
type: :runtime
|
44
38
|
prerelease: false
|
45
39
|
version_requirements: !ruby/object:Gem::Requirement
|
46
40
|
requirements:
|
47
41
|
- - ">="
|
48
42
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
43
|
+
version: 6.0.0
|
50
44
|
- - "<"
|
51
45
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
46
|
+
version: 8.0.0
|
53
47
|
- !ruby/object:Gem::Dependency
|
54
48
|
name: parslet
|
55
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -331,7 +325,7 @@ metadata:
|
|
331
325
|
source_code_uri: https://github.com/wallaby-rails/wallaby-core
|
332
326
|
changelog_uri: https://github.com/wallaby-rails/wallaby-core/blob/master/CHANGELOG.md
|
333
327
|
rubygems_mfa_required: 'true'
|
334
|
-
post_install_message:
|
328
|
+
post_install_message:
|
335
329
|
rdoc_options: []
|
336
330
|
require_paths:
|
337
331
|
- lib
|
@@ -342,12 +336,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
342
336
|
version: '0'
|
343
337
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
344
338
|
requirements:
|
345
|
-
- - "
|
339
|
+
- - ">="
|
346
340
|
- !ruby/object:Gem::Version
|
347
|
-
version:
|
341
|
+
version: '0'
|
348
342
|
requirements: []
|
349
|
-
rubygems_version: 3.
|
350
|
-
signing_key:
|
343
|
+
rubygems_version: 3.5.5
|
344
|
+
signing_key:
|
351
345
|
specification_version: 4
|
352
346
|
summary: The core of Wallaby
|
353
347
|
test_files: []
|