wallaby-core 0.2.9 → 0.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/wallaby/resources_controller.rb +20 -7
- data/app/security/ability.rb +1 -1
- data/config/routes.rb +21 -14
- data/lib/adaptors/wallaby/custom/default_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_decorator.rb +5 -17
- data/lib/adaptors/wallaby/custom/model_finder.rb +3 -3
- data/lib/adaptors/wallaby/custom/model_pagination_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_service_provider.rb +1 -1
- data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +12 -5
- data/lib/authorizers/wallaby/default_authorization_provider.rb +10 -1
- data/lib/authorizers/wallaby/model_authorizer.rb +41 -16
- data/lib/authorizers/wallaby/pundit_authorization_provider.rb +22 -8
- data/lib/concerns/wallaby/application_concern.rb +41 -71
- data/lib/concerns/wallaby/authentication_concern.rb +29 -127
- data/lib/concerns/wallaby/authorizable.rb +14 -57
- data/lib/concerns/wallaby/baseable.rb +24 -57
- data/lib/concerns/wallaby/configurable.rb +416 -0
- data/lib/concerns/wallaby/decoratable.rb +24 -60
- data/lib/concerns/wallaby/engineable.rb +29 -46
- data/lib/concerns/wallaby/fieldable.rb +45 -56
- data/lib/concerns/wallaby/paginatable.rb +20 -51
- data/lib/concerns/wallaby/prefixable.rb +24 -4
- data/lib/concerns/wallaby/resourcable.rb +130 -72
- data/lib/concerns/wallaby/resources_concern.rb +205 -305
- data/lib/concerns/wallaby/servicable.rb +8 -48
- data/lib/concerns/wallaby/urlable.rb +69 -0
- data/lib/decorators/wallaby/resource_decorator.rb +72 -34
- data/lib/errors/wallaby/class_not_found.rb +1 -2
- data/lib/errors/wallaby/forbidden.rb +1 -2
- data/lib/errors/wallaby/general_error.rb +1 -1
- data/lib/errors/wallaby/invalid_error.rb +1 -2
- data/lib/errors/wallaby/method_removed.rb +5 -0
- data/lib/errors/wallaby/model_not_found.rb +1 -2
- data/lib/errors/wallaby/not_authenticated.rb +1 -2
- data/lib/errors/wallaby/not_found.rb +1 -2
- data/lib/errors/wallaby/not_implemented.rb +1 -2
- data/lib/errors/wallaby/resource_not_found.rb +1 -2
- data/lib/errors/wallaby/unprocessable_entity.rb +1 -2
- data/lib/fields/wallaby/all_fields.rb +63 -0
- data/lib/forms/wallaby/form_builder.rb +2 -2
- data/lib/generators/wallaby/engine/application_generator.rb +33 -0
- data/lib/generators/wallaby/engine/authorizer/USAGE +20 -0
- data/lib/generators/wallaby/engine/authorizer/authorizer_generator.rb +19 -0
- data/lib/generators/wallaby/engine/authorizer/templates/authorizer.rb.erb +35 -0
- data/lib/generators/wallaby/engine/controller/USAGE +20 -0
- data/lib/generators/wallaby/engine/controller/controller_generator.rb +23 -0
- data/lib/generators/wallaby/engine/controller/templates/controller.rb.erb +130 -0
- data/lib/generators/wallaby/engine/decorator/USAGE +20 -0
- data/lib/generators/wallaby/engine/decorator/decorator_generator.rb +19 -0
- data/lib/generators/wallaby/engine/decorator/templates/decorator.rb.erb +5 -0
- data/lib/generators/wallaby/engine/install/USAGE +19 -0
- data/lib/generators/wallaby/engine/install/install_generator.rb +91 -0
- data/lib/generators/wallaby/engine/install/templates/application_authorizer.rb.erb +37 -0
- data/lib/generators/wallaby/engine/install/templates/application_controller.rb.erb +173 -0
- data/lib/generators/wallaby/engine/install/templates/application_decorator.rb.erb +7 -0
- data/lib/generators/wallaby/engine/install/templates/application_paginator.rb.erb +27 -0
- data/lib/generators/wallaby/engine/install/templates/application_servicer.rb.erb +47 -0
- data/lib/generators/wallaby/engine/install/templates/initializer.rb.erb +16 -0
- data/lib/generators/wallaby/engine/paginator/USAGE +20 -0
- data/lib/generators/wallaby/engine/paginator/paginator_generator.rb +19 -0
- data/lib/generators/wallaby/engine/paginator/templates/paginator.rb.erb +25 -0
- data/lib/generators/wallaby/engine/servicer/USAGE +20 -0
- data/lib/generators/wallaby/engine/servicer/servicer_generator.rb +19 -0
- data/lib/generators/wallaby/engine/servicer/templates/servicer.rb.erb +45 -0
- data/lib/helpers/wallaby/application_helper.rb +10 -59
- data/lib/helpers/wallaby/base_helper.rb +11 -11
- data/lib/helpers/wallaby/configuration_helper.rb +36 -4
- data/lib/helpers/wallaby/form_helper.rb +1 -1
- data/lib/helpers/wallaby/index_helper.rb +19 -9
- data/lib/helpers/wallaby/links_helper.rb +13 -80
- data/lib/helpers/wallaby/resources_helper.rb +39 -7
- data/lib/helpers/wallaby/secure_helper.rb +20 -19
- data/lib/interfaces/wallaby/mode.rb +8 -8
- data/lib/interfaces/wallaby/model_authorization_provider.rb +23 -22
- data/lib/interfaces/wallaby/model_decorator.rb +36 -48
- data/lib/interfaces/wallaby/model_finder.rb +3 -3
- data/lib/interfaces/wallaby/model_pagination_provider.rb +2 -6
- data/lib/interfaces/wallaby/model_service_provider.rb +4 -4
- data/lib/paginators/wallaby/model_paginator.rb +1 -1
- data/lib/responders/wallaby/json_api_responder.rb +10 -5
- data/lib/responders/wallaby/resources_responder.rb +7 -2
- data/lib/routes/wallaby/engines/base_route.rb +78 -0
- data/lib/routes/wallaby/engines/custom_app_route.rb +92 -0
- data/lib/routes/wallaby/engines/engine_route.rb +77 -0
- data/lib/routes/wallaby/resources_router.rb +100 -45
- data/lib/servicers/wallaby/model_servicer.rb +13 -13
- data/lib/services/wallaby/authorizer_finder.rb +23 -0
- data/lib/services/wallaby/class_finder.rb +42 -0
- data/lib/services/wallaby/controller_finder.rb +29 -0
- data/lib/services/wallaby/decorator_finder.rb +34 -0
- data/lib/services/wallaby/default_models_excluder.rb +45 -0
- data/lib/services/wallaby/engine_name_finder.rb +14 -11
- data/lib/services/wallaby/engine_url_for.rb +82 -37
- data/lib/services/wallaby/fields_regulator.rb +34 -0
- data/lib/services/wallaby/map/mode_mapper.rb +4 -4
- data/lib/services/wallaby/map/model_class_mapper.rb +1 -1
- data/lib/services/wallaby/model_class_filter.rb +29 -0
- data/lib/services/wallaby/paginator_finder.rb +24 -0
- data/lib/services/wallaby/prefixes_builder.rb +49 -8
- data/lib/services/wallaby/servicer_finder.rb +31 -0
- data/lib/services/wallaby/sorting/hash_builder.rb +9 -0
- data/lib/services/wallaby/sorting/link_builder.rb +7 -10
- data/lib/services/wallaby/sorting/next_builder.rb +1 -12
- data/lib/services/wallaby/sorting/single_builder.rb +1 -1
- data/lib/support/action_dispatch/routing/mapper.rb +29 -4
- data/lib/utils/wallaby/field_utils.rb +9 -8
- data/lib/utils/wallaby/inflector.rb +94 -0
- data/lib/utils/wallaby/locale.rb +2 -2
- data/lib/utils/wallaby/module_utils.rb +3 -10
- data/lib/utils/wallaby/utils.rb +21 -14
- data/lib/wallaby/class_array.rb +18 -13
- data/lib/wallaby/class_hash.rb +16 -14
- data/lib/wallaby/classifier.rb +4 -2
- data/lib/wallaby/configuration/features.rb +8 -2
- data/lib/wallaby/configuration/mapping.rb +66 -112
- data/lib/wallaby/configuration/metadata.rb +15 -12
- data/lib/wallaby/configuration/models.rb +27 -25
- data/lib/wallaby/configuration/pagination.rb +15 -19
- data/lib/wallaby/configuration/security.rb +88 -80
- data/lib/wallaby/configuration/sorting.rb +15 -17
- data/lib/wallaby/configuration.rb +58 -23
- data/lib/wallaby/constants.rb +21 -13
- data/lib/wallaby/core/version.rb +1 -1
- data/lib/wallaby/core.rb +34 -10
- data/lib/wallaby/deprecator.rb +81 -0
- data/lib/wallaby/engine.rb +1 -19
- data/lib/wallaby/guesser.rb +45 -0
- data/lib/wallaby/logger.rb +35 -13
- data/lib/wallaby/map.rb +14 -87
- data/lib/wallaby/preloader.rb +13 -25
- metadata +120 -15
- data/config/locales/wallaby_class.en.yml +0 -9
- data/lib/concerns/wallaby/defaultable.rb +0 -38
- data/lib/concerns/wallaby/shared_helpers.rb +0 -22
- data/lib/services/wallaby/map/model_class_collector.rb +0 -49
- data/lib/services/wallaby/type_renderer.rb +0 -40
- data/lib/utils/wallaby/model_utils.rb +0 -52
- data/lib/utils/wallaby/test_utils.rb +0 -34
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Wallaby
|
4
|
-
class Map
|
5
|
-
# To collect model classes that are configured to be handled by Wallaby
|
6
|
-
class ModelClassCollector
|
7
|
-
# @param configuration [Configuration]
|
8
|
-
# @param models [Array<Class>]
|
9
|
-
def initialize(configuration, models = nil)
|
10
|
-
@configuration = configuration
|
11
|
-
@models = ClassArray.new(models || [])
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [Array<Class>] model class
|
15
|
-
def collect
|
16
|
-
return @models - excluded_models if configured_models.blank?
|
17
|
-
|
18
|
-
invalid_models_check
|
19
|
-
configured_models
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
# Check if the models are valid, raise if invalid
|
25
|
-
def invalid_models_check
|
26
|
-
invalid_models = configured_models - @models
|
27
|
-
return if invalid_models.blank?
|
28
|
-
|
29
|
-
message = Locale.t 'errors.invalid.models', models: invalid_models.to_sentence
|
30
|
-
raise InvalidError, message
|
31
|
-
end
|
32
|
-
|
33
|
-
# @return [Wallaby::Configuration::Models]
|
34
|
-
def models
|
35
|
-
@configuration.models
|
36
|
-
end
|
37
|
-
|
38
|
-
# @return [Array<Class>] a list of models to exclude
|
39
|
-
def excluded_models
|
40
|
-
models.excludes
|
41
|
-
end
|
42
|
-
|
43
|
-
# @return [Array<Class>] a list of models to set
|
44
|
-
def configured_models
|
45
|
-
models.presence
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Wallaby
|
4
|
-
# Type renderer
|
5
|
-
class TypeRenderer
|
6
|
-
class << self
|
7
|
-
# Render partial
|
8
|
-
# @param view [ActionView]
|
9
|
-
# @param options [Hash]
|
10
|
-
# @param locals [Hash]
|
11
|
-
# @return [String] HTML
|
12
|
-
def render(view, options = {}, locals = {}, &block)
|
13
|
-
locals[:object] ||= locals[:form].try :object
|
14
|
-
check locals
|
15
|
-
complete locals, view.params[:action]
|
16
|
-
view.render options, locals, &block
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
# @param locals [Hash]
|
22
|
-
# @raise [ArgumentError] if form is set but blank
|
23
|
-
# @raise [ArgumentError] if field_name is not provided
|
24
|
-
# @raise [ArgumentError] if object is not decorated
|
25
|
-
def check(locals)
|
26
|
-
raise ArgumentError, Locale.t('errors.required', subject: 'form') if locals.key?(:form) && locals[:form].blank?
|
27
|
-
raise ArgumentError, Locale.t('errors.required', subject: 'field_name') if locals[:field_name].blank?
|
28
|
-
raise ArgumentError, 'Object is not decorated.' unless locals[:object].is_a? ResourceDecorator
|
29
|
-
end
|
30
|
-
|
31
|
-
# @param locals [Hash]
|
32
|
-
# @param action [String]
|
33
|
-
def complete(locals, action)
|
34
|
-
action_name = FORM_ACTIONS[action] || action
|
35
|
-
locals[:metadata] = locals[:object].public_send :"#{action_name}_metadata_of", locals[:field_name]
|
36
|
-
locals[:value] = locals[:object].public_send locals[:field_name]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Wallaby
|
4
|
-
# Model related utils
|
5
|
-
module ModelUtils
|
6
|
-
class << self
|
7
|
-
# Convert model class (e.g. `Namespace::Product`) into resources name (e.g. `namespace::products`)
|
8
|
-
# @param model_class [Class, String] model class
|
9
|
-
# @return [String] resources name
|
10
|
-
def to_resources_name(model_class)
|
11
|
-
return EMPTY_STRING if model_class.blank?
|
12
|
-
|
13
|
-
model_class.to_s.underscore.gsub(SLASH, COLONS).pluralize
|
14
|
-
end
|
15
|
-
|
16
|
-
# Produce model label (e.g. `Namespace / Product`) for model class (e.g. `Namespace::Product`)
|
17
|
-
# @param model_class [Class, String] model class
|
18
|
-
# @return [String] model label
|
19
|
-
def to_model_label(model_class)
|
20
|
-
# TODO: change to use i18n translation
|
21
|
-
return EMPTY_STRING if model_class.blank?
|
22
|
-
|
23
|
-
model_class_name = to_model_name model_class
|
24
|
-
model_class_name.titleize.gsub(SLASH, SPACE + SLASH + SPACE)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Convert resources name (e.g. `namespace::products`) into model class (e.g. `Namespace::Product`)
|
28
|
-
# @param resources_name [String] resources name
|
29
|
-
# @return [Class] model class
|
30
|
-
# @return [nil] when not found
|
31
|
-
def to_model_class(resources_name)
|
32
|
-
return if resources_name.blank?
|
33
|
-
|
34
|
-
class_name = to_model_name resources_name
|
35
|
-
# NOTE: DO NOT try to use const_defined? and const_get EVER.
|
36
|
-
# This is Rails, use constantize
|
37
|
-
class_name.constantize
|
38
|
-
rescue NameError
|
39
|
-
Logger.warn Locale.t('errors.not_found.model', model: class_name), sourcing: 2..10
|
40
|
-
end
|
41
|
-
|
42
|
-
# Convert resources name (e.g. `namespace::products`) into model name (e.g. `Namespace::Product`)
|
43
|
-
# @param resources_name [String] resources name
|
44
|
-
# @return [String] model name
|
45
|
-
def to_model_name(resources_name)
|
46
|
-
return EMPTY_STRING if resources_name.blank?
|
47
|
-
|
48
|
-
resources_name.to_s.singularize.gsub(COLONS, SLASH).camelize
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Wallaby
|
4
|
-
# Utils for test
|
5
|
-
module TestUtils
|
6
|
-
class << self
|
7
|
-
# @param context
|
8
|
-
# @param controller_class [Class]
|
9
|
-
def around_crud(context, controller_class = nil)
|
10
|
-
context.before do
|
11
|
-
controller_class ||= described_class
|
12
|
-
controller_path = controller_class.controller_path
|
13
|
-
Wallaby::TestUtils.draw(routes, controller_path)
|
14
|
-
end
|
15
|
-
|
16
|
-
context.after { Rails.application.reload_routes! }
|
17
|
-
end
|
18
|
-
|
19
|
-
# @param routes
|
20
|
-
# @param controller_path [String]
|
21
|
-
def draw(routes, controller_path)
|
22
|
-
routes.draw do
|
23
|
-
get ':resources', to: "#{controller_path}#index", as: :resources
|
24
|
-
get ':resources/:id', to: "#{controller_path}#show", as: :resource
|
25
|
-
get ':resources/new', to: "#{controller_path}#new"
|
26
|
-
get ':resources/:id/edit', to: "#{controller_path}#edit"
|
27
|
-
post ':resources', to: "#{controller_path}#create"
|
28
|
-
patch ':resources/:id', to: "#{controller_path}#update"
|
29
|
-
delete ':resources/:id', to: "#{controller_path}#destroy"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|