wallaby-core 0.1.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +31 -0
- data/app/controllers/wallaby/application_controller.rb +84 -0
- data/app/controllers/wallaby/resources_controller.rb +381 -0
- data/app/controllers/wallaby/secure_controller.rb +81 -0
- data/app/security/ability.rb +13 -0
- data/config/locales/wallaby.en.yml +140 -0
- data/config/locales/wallaby_class.en.yml +30 -0
- data/config/routes.rb +39 -0
- data/lib/adaptors/wallaby/custom.rb +7 -0
- data/lib/adaptors/wallaby/custom/default_provider.rb +9 -0
- data/lib/adaptors/wallaby/custom/model_decorator.rb +71 -0
- data/lib/adaptors/wallaby/custom/model_finder.rb +13 -0
- data/lib/adaptors/wallaby/custom/model_pagination_provider.rb +14 -0
- data/lib/adaptors/wallaby/custom/model_service_provider.rb +48 -0
- data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +72 -0
- data/lib/authorizers/wallaby/default_authorization_provider.rb +58 -0
- data/lib/authorizers/wallaby/model_authorizer.rb +100 -0
- data/lib/authorizers/wallaby/pundit_authorization_provider.rb +89 -0
- data/lib/concerns/wallaby/authorizable.rb +103 -0
- data/lib/concerns/wallaby/baseable.rb +36 -0
- data/lib/concerns/wallaby/decoratable.rb +101 -0
- data/lib/concerns/wallaby/defaultable.rb +38 -0
- data/lib/concerns/wallaby/engineable.rb +61 -0
- data/lib/concerns/wallaby/fieldable.rb +78 -0
- data/lib/concerns/wallaby/paginatable.rb +72 -0
- data/lib/concerns/wallaby/rails_overridden_methods.rb +42 -0
- data/lib/concerns/wallaby/resourcable.rb +149 -0
- data/lib/concerns/wallaby/servicable.rb +68 -0
- data/lib/concerns/wallaby/shared_helpers.rb +22 -0
- data/lib/concerns/wallaby/themeable.rb +40 -0
- data/lib/decorators/wallaby/resource_decorator.rb +189 -0
- data/lib/errors/wallaby/cell_handling.rb +6 -0
- data/lib/errors/wallaby/forbidden.rb +6 -0
- data/lib/errors/wallaby/general_error.rb +6 -0
- data/lib/errors/wallaby/invalid_error.rb +6 -0
- data/lib/errors/wallaby/model_not_found.rb +11 -0
- data/lib/errors/wallaby/not_authenticated.rb +6 -0
- data/lib/errors/wallaby/not_found.rb +6 -0
- data/lib/errors/wallaby/not_implemented.rb +6 -0
- data/lib/errors/wallaby/resource_not_found.rb +11 -0
- data/lib/errors/wallaby/unprocessable_entity.rb +6 -0
- data/lib/forms/wallaby/form_builder.rb +60 -0
- data/lib/helpers/wallaby/application_helper.rb +79 -0
- data/lib/helpers/wallaby/base_helper.rb +65 -0
- data/lib/helpers/wallaby/configuration_helper.rb +18 -0
- data/lib/helpers/wallaby/form_helper.rb +62 -0
- data/lib/helpers/wallaby/index_helper.rb +84 -0
- data/lib/helpers/wallaby/links_helper.rb +213 -0
- data/lib/helpers/wallaby/resources_helper.rb +52 -0
- data/lib/helpers/wallaby/secure_helper.rb +54 -0
- data/lib/helpers/wallaby/styling_helper.rb +82 -0
- data/lib/interfaces/wallaby/mode.rb +72 -0
- data/lib/interfaces/wallaby/model_authorization_provider.rb +99 -0
- data/lib/interfaces/wallaby/model_decorator.rb +168 -0
- data/lib/interfaces/wallaby/model_finder.rb +12 -0
- data/lib/interfaces/wallaby/model_pagination_provider.rb +107 -0
- data/lib/interfaces/wallaby/model_service_provider.rb +84 -0
- data/lib/paginators/wallaby/model_paginator.rb +115 -0
- data/lib/paginators/wallaby/resource_paginator.rb +12 -0
- data/lib/parsers/wallaby/parser.rb +34 -0
- data/lib/renderers/wallaby/cell.rb +137 -0
- data/lib/renderers/wallaby/cell_resolver.rb +89 -0
- data/lib/renderers/wallaby/custom_lookup_context.rb +64 -0
- data/lib/renderers/wallaby/custom_partial_renderer.rb +33 -0
- data/lib/renderers/wallaby/custom_renderer.rb +16 -0
- data/lib/responders/wallaby/json_api_responder.rb +101 -0
- data/lib/responders/wallaby/resources_responder.rb +28 -0
- data/lib/routes/wallaby/resources_router.rb +72 -0
- data/lib/servicers/wallaby/model_servicer.rb +154 -0
- data/lib/services/wallaby/engine_name_finder.rb +22 -0
- data/lib/services/wallaby/engine_url_for.rb +46 -0
- data/lib/services/wallaby/link_options_normalizer.rb +19 -0
- data/lib/services/wallaby/map/mode_mapper.rb +27 -0
- data/lib/services/wallaby/map/model_class_collector.rb +49 -0
- data/lib/services/wallaby/map/model_class_mapper.rb +38 -0
- data/lib/services/wallaby/prefixes_builder.rb +66 -0
- data/lib/services/wallaby/sorting/hash_builder.rb +19 -0
- data/lib/services/wallaby/sorting/link_builder.rb +69 -0
- data/lib/services/wallaby/sorting/next_builder.rb +63 -0
- data/lib/services/wallaby/sorting/single_builder.rb +20 -0
- data/lib/services/wallaby/type_renderer.rb +50 -0
- data/lib/support/action_dispatch/routing/mapper.rb +75 -0
- data/lib/tree/wallaby/node.rb +25 -0
- data/lib/utils/wallaby/cell_utils.rb +34 -0
- data/lib/utils/wallaby/field_utils.rb +43 -0
- data/lib/utils/wallaby/filter_utils.rb +20 -0
- data/lib/utils/wallaby/model_utils.rb +51 -0
- data/lib/utils/wallaby/module_utils.rb +46 -0
- data/lib/utils/wallaby/params_utils.rb +14 -0
- data/lib/utils/wallaby/preload_utils.rb +44 -0
- data/lib/utils/wallaby/test_utils.rb +34 -0
- data/lib/utils/wallaby/utils.rb +27 -0
- data/lib/wallaby/configuration.rb +103 -0
- data/lib/wallaby/configuration/features.rb +24 -0
- data/lib/wallaby/configuration/mapping.rb +140 -0
- data/lib/wallaby/configuration/metadata.rb +23 -0
- data/lib/wallaby/configuration/models.rb +46 -0
- data/lib/wallaby/configuration/pagination.rb +30 -0
- data/lib/wallaby/configuration/security.rb +98 -0
- data/lib/wallaby/configuration/sorting.rb +28 -0
- data/lib/wallaby/constants.rb +45 -0
- data/lib/wallaby/core.rb +117 -0
- data/lib/wallaby/core/version.rb +7 -0
- data/lib/wallaby/engine.rb +43 -0
- data/lib/wallaby/map.rb +170 -0
- metadata +222 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Wallaby
|
|
4
|
+
class Configuration
|
|
5
|
+
# Sorting global configuration
|
|
6
|
+
# @since 5.2.0
|
|
7
|
+
class Sorting
|
|
8
|
+
# @!attribute [w] strategy
|
|
9
|
+
attr_writer :strategy
|
|
10
|
+
|
|
11
|
+
# @!attribute [r] strategy
|
|
12
|
+
# To globally configure which strategy to use for sorting. Options are
|
|
13
|
+
#
|
|
14
|
+
# - `:multiple`: support multiple columns sorting
|
|
15
|
+
# - `:single`: support single column sorting
|
|
16
|
+
#
|
|
17
|
+
# By default, strategy is `:multiple`.
|
|
18
|
+
# @example To enable turbolinks:
|
|
19
|
+
# Wallaby.config do |config|
|
|
20
|
+
# config.sorting.strategy = :single
|
|
21
|
+
# end
|
|
22
|
+
# @return [Symbol, String]
|
|
23
|
+
def strategy
|
|
24
|
+
@strategy ||= :multiple
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Wallaby
|
|
4
|
+
EMPTY_STRING = ''.html_safe
|
|
5
|
+
EMPTY_HASH = {}.freeze
|
|
6
|
+
EMPTY_ARRAY = [].freeze
|
|
7
|
+
SPACE = ' '
|
|
8
|
+
SLASH = '/'
|
|
9
|
+
COLONS = '::'
|
|
10
|
+
COMMA = ','
|
|
11
|
+
DOT = '.'
|
|
12
|
+
|
|
13
|
+
# Default page size for {Wallaby::Configuration::Pagination#page_size}
|
|
14
|
+
DEFAULT_PAGE_SIZE = 20
|
|
15
|
+
# Default max charactoers to display for {Wallaby::Configuration::Metadata#max}
|
|
16
|
+
DEFAULT_MAX = 20
|
|
17
|
+
# Default provider name for authorizer sorting.
|
|
18
|
+
DEFAULT_PROVIDER = 'default'
|
|
19
|
+
|
|
20
|
+
ERRORS = %i(
|
|
21
|
+
bad_request
|
|
22
|
+
forbidden
|
|
23
|
+
internal_server_error
|
|
24
|
+
not_found
|
|
25
|
+
not_implemented
|
|
26
|
+
unauthorized
|
|
27
|
+
unprocessable_entity
|
|
28
|
+
).freeze
|
|
29
|
+
MODEL_ACTIONS = %i(index new create show edit update destroy).freeze
|
|
30
|
+
FORM_ACTIONS = { new: 'form', create: 'form', edit: 'form', update: 'form' }.with_indifferent_access.freeze
|
|
31
|
+
SAVE_ACTIONS = %w(create update).freeze
|
|
32
|
+
NON_FIND_ACTIONS = %w(index new create).freeze
|
|
33
|
+
|
|
34
|
+
SCRIPT_NAME = 'SCRIPT_NAME'
|
|
35
|
+
PATH_INFO = 'PATH_INFO'
|
|
36
|
+
# Page size list
|
|
37
|
+
# @see Wallaby::Configuration::Pagination#page_size
|
|
38
|
+
PERS = [10, 20, 50, 100].freeze
|
|
39
|
+
CSV = 'csv'
|
|
40
|
+
WILDCARD = 'QUERY'
|
|
41
|
+
TITLE_NAMES = %w(name title string text).freeze
|
|
42
|
+
|
|
43
|
+
# A constant of error path for error handling
|
|
44
|
+
ERROR_PATH = 'error'
|
|
45
|
+
end
|
data/lib/wallaby/core.rb
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'parslet'
|
|
4
|
+
require 'responders'
|
|
5
|
+
|
|
6
|
+
require 'wallaby/core/version'
|
|
7
|
+
require 'wallaby/constants'
|
|
8
|
+
require 'wallaby/engine'
|
|
9
|
+
|
|
10
|
+
require 'support/action_dispatch/routing/mapper'
|
|
11
|
+
|
|
12
|
+
require 'wallaby/configuration'
|
|
13
|
+
require 'wallaby/configuration/features'
|
|
14
|
+
require 'wallaby/configuration/mapping'
|
|
15
|
+
require 'wallaby/configuration/metadata'
|
|
16
|
+
require 'wallaby/configuration/models'
|
|
17
|
+
require 'wallaby/configuration/pagination'
|
|
18
|
+
require 'wallaby/configuration/security'
|
|
19
|
+
require 'wallaby/configuration/sorting'
|
|
20
|
+
require 'wallaby/map'
|
|
21
|
+
|
|
22
|
+
require 'routes/wallaby/resources_router'
|
|
23
|
+
require 'tree/wallaby/node'
|
|
24
|
+
require 'parsers/wallaby/parser'
|
|
25
|
+
|
|
26
|
+
require 'utils/wallaby/cell_utils'
|
|
27
|
+
require 'utils/wallaby/field_utils'
|
|
28
|
+
require 'utils/wallaby/filter_utils'
|
|
29
|
+
require 'utils/wallaby/model_utils'
|
|
30
|
+
require 'utils/wallaby/module_utils'
|
|
31
|
+
require 'utils/wallaby/params_utils'
|
|
32
|
+
require 'utils/wallaby/preload_utils'
|
|
33
|
+
require 'utils/wallaby/test_utils'
|
|
34
|
+
require 'utils/wallaby/utils'
|
|
35
|
+
|
|
36
|
+
require 'concerns/wallaby/authorizable'
|
|
37
|
+
require 'concerns/wallaby/baseable'
|
|
38
|
+
require 'concerns/wallaby/decoratable'
|
|
39
|
+
require 'concerns/wallaby/defaultable'
|
|
40
|
+
require 'concerns/wallaby/engineable'
|
|
41
|
+
require 'concerns/wallaby/fieldable'
|
|
42
|
+
require 'concerns/wallaby/paginatable'
|
|
43
|
+
require 'concerns/wallaby/rails_overridden_methods'
|
|
44
|
+
require 'concerns/wallaby/resourcable'
|
|
45
|
+
require 'concerns/wallaby/servicable'
|
|
46
|
+
require 'concerns/wallaby/shared_helpers'
|
|
47
|
+
require 'concerns/wallaby/themeable'
|
|
48
|
+
|
|
49
|
+
require 'interfaces/wallaby/mode'
|
|
50
|
+
require 'interfaces/wallaby/model_decorator'
|
|
51
|
+
require 'interfaces/wallaby/model_finder'
|
|
52
|
+
require 'interfaces/wallaby/model_service_provider'
|
|
53
|
+
require 'interfaces/wallaby/model_pagination_provider'
|
|
54
|
+
require 'interfaces/wallaby/model_authorization_provider'
|
|
55
|
+
|
|
56
|
+
require 'errors/wallaby/general_error'
|
|
57
|
+
require 'errors/wallaby/invalid_error'
|
|
58
|
+
require 'errors/wallaby/not_implemented'
|
|
59
|
+
require 'errors/wallaby/not_found'
|
|
60
|
+
require 'errors/wallaby/model_not_found'
|
|
61
|
+
require 'errors/wallaby/resource_not_found'
|
|
62
|
+
require 'errors/wallaby/cell_handling'
|
|
63
|
+
|
|
64
|
+
require 'errors/wallaby/forbidden'
|
|
65
|
+
require 'errors/wallaby/not_authenticated'
|
|
66
|
+
require 'errors/wallaby/unprocessable_entity'
|
|
67
|
+
|
|
68
|
+
require 'decorators/wallaby/resource_decorator'
|
|
69
|
+
require 'servicers/wallaby/model_servicer'
|
|
70
|
+
require 'paginators/wallaby/model_paginator'
|
|
71
|
+
require 'paginators/wallaby/resource_paginator'
|
|
72
|
+
require 'authorizers/wallaby/model_authorizer'
|
|
73
|
+
require 'authorizers/wallaby/default_authorization_provider'
|
|
74
|
+
require 'authorizers/wallaby/cancancan_authorization_provider'
|
|
75
|
+
require 'authorizers/wallaby/pundit_authorization_provider'
|
|
76
|
+
|
|
77
|
+
require 'forms/wallaby/form_builder'
|
|
78
|
+
|
|
79
|
+
require 'services/wallaby/map/mode_mapper'
|
|
80
|
+
require 'services/wallaby/map/model_class_collector'
|
|
81
|
+
require 'services/wallaby/map/model_class_mapper'
|
|
82
|
+
require 'services/wallaby/prefixes_builder'
|
|
83
|
+
require 'services/wallaby/engine_name_finder'
|
|
84
|
+
require 'services/wallaby/engine_url_for'
|
|
85
|
+
require 'services/wallaby/type_renderer'
|
|
86
|
+
require 'services/wallaby/link_options_normalizer'
|
|
87
|
+
require 'services/wallaby/sorting/hash_builder'
|
|
88
|
+
require 'services/wallaby/sorting/next_builder'
|
|
89
|
+
require 'services/wallaby/sorting/single_builder'
|
|
90
|
+
require 'services/wallaby/sorting/link_builder'
|
|
91
|
+
|
|
92
|
+
require 'helpers/wallaby/configuration_helper'
|
|
93
|
+
require 'helpers/wallaby/form_helper'
|
|
94
|
+
require 'helpers/wallaby/index_helper'
|
|
95
|
+
require 'helpers/wallaby/links_helper'
|
|
96
|
+
require 'helpers/wallaby/styling_helper'
|
|
97
|
+
|
|
98
|
+
require 'helpers/wallaby/base_helper'
|
|
99
|
+
require 'helpers/wallaby/resources_helper'
|
|
100
|
+
require 'helpers/wallaby/secure_helper'
|
|
101
|
+
require 'helpers/wallaby/application_helper'
|
|
102
|
+
|
|
103
|
+
require 'responders/wallaby/resources_responder'
|
|
104
|
+
require 'responders/wallaby/json_api_responder'
|
|
105
|
+
|
|
106
|
+
require 'renderers/wallaby/cell'
|
|
107
|
+
require 'renderers/wallaby/cell_resolver'
|
|
108
|
+
require 'renderers/wallaby/custom_lookup_context'
|
|
109
|
+
require 'renderers/wallaby/custom_renderer'
|
|
110
|
+
require 'renderers/wallaby/custom_partial_renderer'
|
|
111
|
+
|
|
112
|
+
require 'adaptors/wallaby/custom'
|
|
113
|
+
require 'adaptors/wallaby/custom/default_provider'
|
|
114
|
+
require 'adaptors/wallaby/custom/model_finder'
|
|
115
|
+
require 'adaptors/wallaby/custom/model_decorator'
|
|
116
|
+
require 'adaptors/wallaby/custom/model_pagination_provider'
|
|
117
|
+
require 'adaptors/wallaby/custom/model_service_provider'
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Wallaby
|
|
4
|
+
# Wallaby engine
|
|
5
|
+
class Engine < ::Rails::Engine
|
|
6
|
+
initializer 'wallaby.autoload_paths', before: :set_load_path do |_|
|
|
7
|
+
# NOTE: this needs to be run before `set_load_path`
|
|
8
|
+
# so that files under `app/views` can be eager loaded
|
|
9
|
+
# and therefore, Wallaby's renderer can function properly
|
|
10
|
+
[Rails.configuration].each do |conf|
|
|
11
|
+
next if conf.paths['app/views'].eager_load?
|
|
12
|
+
|
|
13
|
+
conf.paths.add 'app/views', eager_load: true
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
initializer 'wallaby.development.reload' do |_|
|
|
18
|
+
# NOTE: Rails reload! will hit here
|
|
19
|
+
# @see http://rmosolgo.github.io/blog/2017/04/12/watching-files-during-rails-development/
|
|
20
|
+
config.to_prepare do
|
|
21
|
+
if Rails.env.development? || Rails.configuration.eager_load
|
|
22
|
+
Rails.logger.debug ' [WALLABY] Reloading...'
|
|
23
|
+
::Wallaby::Map.clear
|
|
24
|
+
::Wallaby::PreloadUtils.require_all
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
config.before_eager_load do
|
|
30
|
+
# NOTE: We need to ensure that the core models are loaded before anything else
|
|
31
|
+
Rails.logger.debug ' [WALLABY] Preload all model files.'
|
|
32
|
+
::Wallaby::PreloadUtils.require_one 'app/models'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Preload the rest files
|
|
36
|
+
config.after_initialize do
|
|
37
|
+
unless Rails.env.development? || Rails.configuration.eager_load
|
|
38
|
+
Rails.logger.debug ' [WALLABY] Preload files after initialize.'
|
|
39
|
+
::Wallaby::PreloadUtils.require_all
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/wallaby/map.rb
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Wallaby
|
|
4
|
+
# Global storage to hold all the information that Wallaby needs to look up.
|
|
5
|
+
class Map
|
|
6
|
+
class << self
|
|
7
|
+
# To store modes
|
|
8
|
+
attr_writer :modes
|
|
9
|
+
|
|
10
|
+
# @return [Array<Class>] descendants of Mode
|
|
11
|
+
def modes
|
|
12
|
+
@modes ||= Mode.descendants
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [Hash] { model => mode }
|
|
16
|
+
def mode_map
|
|
17
|
+
@mode_map ||= ModeMapper.new(modes).map.freeze
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# TODO: remove this method
|
|
21
|
+
# @return [Array] [ model classes ]
|
|
22
|
+
def model_classes
|
|
23
|
+
@model_classes ||= ModelClassCollector.new(configuration, mode_map.keys).collect.freeze
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# { model => resources name }
|
|
27
|
+
# It's a setter when value is given.
|
|
28
|
+
# Otherwise, a getter.
|
|
29
|
+
# @param model_class [Class]
|
|
30
|
+
# @param value [String, nil] resources name
|
|
31
|
+
# @return [String] resources name
|
|
32
|
+
def resources_name_map(model_class, value = nil)
|
|
33
|
+
@resources_name_map ||= {}
|
|
34
|
+
@resources_name_map[model_class] ||= value || ModelUtils.to_resources_name(model_class)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# { resources name => model }
|
|
38
|
+
# It's a setter when value is given.
|
|
39
|
+
# Otherwise, a getter.
|
|
40
|
+
# @param resources_name [String]
|
|
41
|
+
# @return [Class]
|
|
42
|
+
def model_class_map(resources_name, value = nil)
|
|
43
|
+
@model_class_map ||= {}
|
|
44
|
+
@model_class_map[resources_name] ||= value || ModelUtils.to_model_class(resources_name)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class << self
|
|
49
|
+
# Look up which controller to use for a given model class
|
|
50
|
+
# @param model_class [Class]
|
|
51
|
+
# @param application_controller [Class, nil]
|
|
52
|
+
# @return [Class] controller class, default to `mapping.resources_controller`
|
|
53
|
+
def controller_map(model_class, application_controller = nil)
|
|
54
|
+
application_controller ||= mapping.resources_controller
|
|
55
|
+
map_of :@controller_map, model_class, application_controller
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Look up which resource decorator to use for a given model class
|
|
59
|
+
# @param model_class [Class]
|
|
60
|
+
# @param application_decorator [Class, nil]
|
|
61
|
+
# @return [Class] resource decorator class, default to `mapping.resource_decorator`
|
|
62
|
+
def resource_decorator_map(model_class, application_decorator = nil)
|
|
63
|
+
application_decorator ||= mapping.resource_decorator
|
|
64
|
+
map_of :@decorator_map, model_class, application_decorator
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# { model => model decorator }
|
|
68
|
+
# @param model_class [Class]
|
|
69
|
+
# @param application_decorator [Class, nil]
|
|
70
|
+
# @return [Wallaby::ModelDecorator] model decorator instance
|
|
71
|
+
def model_decorator_map(model_class, application_decorator = nil)
|
|
72
|
+
application_decorator ||= mapping.resource_decorator
|
|
73
|
+
@model_decorator_map ||= {}
|
|
74
|
+
@model_decorator_map[application_decorator] ||= {}
|
|
75
|
+
@model_decorator_map[application_decorator][model_class] ||=
|
|
76
|
+
mode_map[model_class].try(:model_decorator).try :new, model_class
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Look up which model servicer to use for a given model class
|
|
80
|
+
# @param model_class [Class]
|
|
81
|
+
# @param application_servicer [Class, nil]
|
|
82
|
+
# @return [Class] model servicer class, default to `mapping.model_servicer`
|
|
83
|
+
def servicer_map(model_class, application_servicer = nil)
|
|
84
|
+
application_servicer ||= mapping.model_servicer
|
|
85
|
+
map_of :@servicer_map, model_class, application_servicer
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Look up which paginator to use for a given model class
|
|
89
|
+
# @param model_class [Class]
|
|
90
|
+
# @param application_paginator [Class, nil]
|
|
91
|
+
# @return [Class] resource paginator class, default to `mapping.model_paginator`
|
|
92
|
+
def paginator_map(model_class, application_paginator = nil)
|
|
93
|
+
application_paginator ||= mapping.model_paginator
|
|
94
|
+
map_of :@paginator_map, model_class, application_paginator
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Look up which authorizer to use for a given model class
|
|
98
|
+
# @param model_class [Class]
|
|
99
|
+
# @param application_authorizer [Class, nil]
|
|
100
|
+
# @return [Class] model authorizer class, default to `mapping.model_authorizer`
|
|
101
|
+
def authorizer_map(model_class, application_authorizer = nil)
|
|
102
|
+
application_authorizer ||= mapping.model_authorizer
|
|
103
|
+
map_of :@authorizer_map, model_class, application_authorizer
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
class << self
|
|
108
|
+
# { model => service_provider }
|
|
109
|
+
# @param model_class [Class]
|
|
110
|
+
# @return [Class] model service provider instance
|
|
111
|
+
def service_provider_map(model_class)
|
|
112
|
+
@service_provider_map ||= {}
|
|
113
|
+
@service_provider_map[model_class] ||= mode_map[model_class].try :model_service_provider
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# { model => pagination_provider }
|
|
117
|
+
# @param model_class [Class]
|
|
118
|
+
# @return [Class] model pagination provider class
|
|
119
|
+
def pagination_provider_map(model_class)
|
|
120
|
+
@pagination_provider_map ||= {}
|
|
121
|
+
@pagination_provider_map[model_class] ||= mode_map[model_class].try :model_pagination_provider
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# { model => authorizer_provider }
|
|
125
|
+
# @param model_class [Class]
|
|
126
|
+
# @return [Class] model authorizer provider class
|
|
127
|
+
def authorizer_provider_map(model_class)
|
|
128
|
+
@authorizer_provider_map ||= {}
|
|
129
|
+
@authorizer_provider_map[model_class] ||= mode_map[model_class].try :model_authorization_providers
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
class << self
|
|
134
|
+
# Reset all the instance variables to nil
|
|
135
|
+
def clear
|
|
136
|
+
instance_variables.each { |name| instance_variable_set name, nil }
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
private
|
|
140
|
+
|
|
141
|
+
# shorthand method
|
|
142
|
+
def configuration
|
|
143
|
+
::Wallaby.configuration
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# shorthand method
|
|
147
|
+
def mapping
|
|
148
|
+
configuration.mapping
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Set up the hash map for given variable name
|
|
152
|
+
# @param variable_name [Symbol] instance variable name e.g. :@decorator_map
|
|
153
|
+
# @param model_class [Class]
|
|
154
|
+
# @param application_class [Class]
|
|
155
|
+
# @return [Class]
|
|
156
|
+
def map_of(variable_name, model_class, application_class)
|
|
157
|
+
return unless model_class
|
|
158
|
+
|
|
159
|
+
unless mode_map[model_class]
|
|
160
|
+
Rails.logger.warn I18n.t('wallaby.map.missing_mode_for_model_class', model: model_class.name)
|
|
161
|
+
return
|
|
162
|
+
end
|
|
163
|
+
instance_variable_set(variable_name, instance_variable_get(variable_name) || {})
|
|
164
|
+
map = instance_variable_get variable_name
|
|
165
|
+
map[application_class] ||= ModelClassMapper.map application_class.descendants
|
|
166
|
+
map[application_class][model_class] ||= application_class
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: wallaby-core
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tian Chen
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-12-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: parslet
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rails
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 4.2.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 4.2.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: responders
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec-rails
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: wallaby-cop
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: The core of Wallaby
|
|
84
|
+
email:
|
|
85
|
+
- me@tian.im
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- LICENSE
|
|
91
|
+
- README.md
|
|
92
|
+
- app/controllers/wallaby/application_controller.rb
|
|
93
|
+
- app/controllers/wallaby/resources_controller.rb
|
|
94
|
+
- app/controllers/wallaby/secure_controller.rb
|
|
95
|
+
- app/security/ability.rb
|
|
96
|
+
- config/locales/wallaby.en.yml
|
|
97
|
+
- config/locales/wallaby_class.en.yml
|
|
98
|
+
- config/routes.rb
|
|
99
|
+
- lib/adaptors/wallaby/custom.rb
|
|
100
|
+
- lib/adaptors/wallaby/custom/default_provider.rb
|
|
101
|
+
- lib/adaptors/wallaby/custom/model_decorator.rb
|
|
102
|
+
- lib/adaptors/wallaby/custom/model_finder.rb
|
|
103
|
+
- lib/adaptors/wallaby/custom/model_pagination_provider.rb
|
|
104
|
+
- lib/adaptors/wallaby/custom/model_service_provider.rb
|
|
105
|
+
- lib/authorizers/wallaby/cancancan_authorization_provider.rb
|
|
106
|
+
- lib/authorizers/wallaby/default_authorization_provider.rb
|
|
107
|
+
- lib/authorizers/wallaby/model_authorizer.rb
|
|
108
|
+
- lib/authorizers/wallaby/pundit_authorization_provider.rb
|
|
109
|
+
- lib/concerns/wallaby/authorizable.rb
|
|
110
|
+
- lib/concerns/wallaby/baseable.rb
|
|
111
|
+
- lib/concerns/wallaby/decoratable.rb
|
|
112
|
+
- lib/concerns/wallaby/defaultable.rb
|
|
113
|
+
- lib/concerns/wallaby/engineable.rb
|
|
114
|
+
- lib/concerns/wallaby/fieldable.rb
|
|
115
|
+
- lib/concerns/wallaby/paginatable.rb
|
|
116
|
+
- lib/concerns/wallaby/rails_overridden_methods.rb
|
|
117
|
+
- lib/concerns/wallaby/resourcable.rb
|
|
118
|
+
- lib/concerns/wallaby/servicable.rb
|
|
119
|
+
- lib/concerns/wallaby/shared_helpers.rb
|
|
120
|
+
- lib/concerns/wallaby/themeable.rb
|
|
121
|
+
- lib/decorators/wallaby/resource_decorator.rb
|
|
122
|
+
- lib/errors/wallaby/cell_handling.rb
|
|
123
|
+
- lib/errors/wallaby/forbidden.rb
|
|
124
|
+
- lib/errors/wallaby/general_error.rb
|
|
125
|
+
- lib/errors/wallaby/invalid_error.rb
|
|
126
|
+
- lib/errors/wallaby/model_not_found.rb
|
|
127
|
+
- lib/errors/wallaby/not_authenticated.rb
|
|
128
|
+
- lib/errors/wallaby/not_found.rb
|
|
129
|
+
- lib/errors/wallaby/not_implemented.rb
|
|
130
|
+
- lib/errors/wallaby/resource_not_found.rb
|
|
131
|
+
- lib/errors/wallaby/unprocessable_entity.rb
|
|
132
|
+
- lib/forms/wallaby/form_builder.rb
|
|
133
|
+
- lib/helpers/wallaby/application_helper.rb
|
|
134
|
+
- lib/helpers/wallaby/base_helper.rb
|
|
135
|
+
- lib/helpers/wallaby/configuration_helper.rb
|
|
136
|
+
- lib/helpers/wallaby/form_helper.rb
|
|
137
|
+
- lib/helpers/wallaby/index_helper.rb
|
|
138
|
+
- lib/helpers/wallaby/links_helper.rb
|
|
139
|
+
- lib/helpers/wallaby/resources_helper.rb
|
|
140
|
+
- lib/helpers/wallaby/secure_helper.rb
|
|
141
|
+
- lib/helpers/wallaby/styling_helper.rb
|
|
142
|
+
- lib/interfaces/wallaby/mode.rb
|
|
143
|
+
- lib/interfaces/wallaby/model_authorization_provider.rb
|
|
144
|
+
- lib/interfaces/wallaby/model_decorator.rb
|
|
145
|
+
- lib/interfaces/wallaby/model_finder.rb
|
|
146
|
+
- lib/interfaces/wallaby/model_pagination_provider.rb
|
|
147
|
+
- lib/interfaces/wallaby/model_service_provider.rb
|
|
148
|
+
- lib/paginators/wallaby/model_paginator.rb
|
|
149
|
+
- lib/paginators/wallaby/resource_paginator.rb
|
|
150
|
+
- lib/parsers/wallaby/parser.rb
|
|
151
|
+
- lib/renderers/wallaby/cell.rb
|
|
152
|
+
- lib/renderers/wallaby/cell_resolver.rb
|
|
153
|
+
- lib/renderers/wallaby/custom_lookup_context.rb
|
|
154
|
+
- lib/renderers/wallaby/custom_partial_renderer.rb
|
|
155
|
+
- lib/renderers/wallaby/custom_renderer.rb
|
|
156
|
+
- lib/responders/wallaby/json_api_responder.rb
|
|
157
|
+
- lib/responders/wallaby/resources_responder.rb
|
|
158
|
+
- lib/routes/wallaby/resources_router.rb
|
|
159
|
+
- lib/servicers/wallaby/model_servicer.rb
|
|
160
|
+
- lib/services/wallaby/engine_name_finder.rb
|
|
161
|
+
- lib/services/wallaby/engine_url_for.rb
|
|
162
|
+
- lib/services/wallaby/link_options_normalizer.rb
|
|
163
|
+
- lib/services/wallaby/map/mode_mapper.rb
|
|
164
|
+
- lib/services/wallaby/map/model_class_collector.rb
|
|
165
|
+
- lib/services/wallaby/map/model_class_mapper.rb
|
|
166
|
+
- lib/services/wallaby/prefixes_builder.rb
|
|
167
|
+
- lib/services/wallaby/sorting/hash_builder.rb
|
|
168
|
+
- lib/services/wallaby/sorting/link_builder.rb
|
|
169
|
+
- lib/services/wallaby/sorting/next_builder.rb
|
|
170
|
+
- lib/services/wallaby/sorting/single_builder.rb
|
|
171
|
+
- lib/services/wallaby/type_renderer.rb
|
|
172
|
+
- lib/support/action_dispatch/routing/mapper.rb
|
|
173
|
+
- lib/tree/wallaby/node.rb
|
|
174
|
+
- lib/utils/wallaby/cell_utils.rb
|
|
175
|
+
- lib/utils/wallaby/field_utils.rb
|
|
176
|
+
- lib/utils/wallaby/filter_utils.rb
|
|
177
|
+
- lib/utils/wallaby/model_utils.rb
|
|
178
|
+
- lib/utils/wallaby/module_utils.rb
|
|
179
|
+
- lib/utils/wallaby/params_utils.rb
|
|
180
|
+
- lib/utils/wallaby/preload_utils.rb
|
|
181
|
+
- lib/utils/wallaby/test_utils.rb
|
|
182
|
+
- lib/utils/wallaby/utils.rb
|
|
183
|
+
- lib/wallaby/configuration.rb
|
|
184
|
+
- lib/wallaby/configuration/features.rb
|
|
185
|
+
- lib/wallaby/configuration/mapping.rb
|
|
186
|
+
- lib/wallaby/configuration/metadata.rb
|
|
187
|
+
- lib/wallaby/configuration/models.rb
|
|
188
|
+
- lib/wallaby/configuration/pagination.rb
|
|
189
|
+
- lib/wallaby/configuration/security.rb
|
|
190
|
+
- lib/wallaby/configuration/sorting.rb
|
|
191
|
+
- lib/wallaby/constants.rb
|
|
192
|
+
- lib/wallaby/core.rb
|
|
193
|
+
- lib/wallaby/core/version.rb
|
|
194
|
+
- lib/wallaby/engine.rb
|
|
195
|
+
- lib/wallaby/map.rb
|
|
196
|
+
homepage: https://github.com/wallaby-rails/wallaby-core
|
|
197
|
+
licenses:
|
|
198
|
+
- MIT
|
|
199
|
+
metadata:
|
|
200
|
+
homepage_uri: https://github.com/wallaby-rails/wallaby-core
|
|
201
|
+
source_code_uri: https://github.com/wallaby-rails/wallaby-core
|
|
202
|
+
changelog_uri: https://github.com/wallaby-rails/wallaby-core/blob/master/CHANGELOG.md
|
|
203
|
+
post_install_message:
|
|
204
|
+
rdoc_options: []
|
|
205
|
+
require_paths:
|
|
206
|
+
- lib
|
|
207
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
|
+
requirements:
|
|
209
|
+
- - ">="
|
|
210
|
+
- !ruby/object:Gem::Version
|
|
211
|
+
version: '0'
|
|
212
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
|
+
requirements:
|
|
214
|
+
- - ">="
|
|
215
|
+
- !ruby/object:Gem::Version
|
|
216
|
+
version: '0'
|
|
217
|
+
requirements: []
|
|
218
|
+
rubygems_version: 3.0.6
|
|
219
|
+
signing_key:
|
|
220
|
+
specification_version: 4
|
|
221
|
+
summary: The core of Wallaby
|
|
222
|
+
test_files: []
|