wallaby 5.1.5 → 5.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/app/controllers/wallaby/abstract_resources_controller.rb +171 -187
  4. data/app/controllers/wallaby/application_controller.rb +15 -4
  5. data/app/controllers/wallaby/base_controller.rb +1 -3
  6. data/app/controllers/wallaby/secure_controller.rb +10 -6
  7. data/app/security/ability.rb +1 -0
  8. data/app/views/wallaby/resources/form/_float.html.erb +1 -1
  9. data/config/locales/wallaby.en.yml +5 -0
  10. data/lib/adaptors/wallaby/active_record.rb +1 -1
  11. data/lib/adaptors/wallaby/active_record/model_decorator.rb +17 -19
  12. data/lib/adaptors/wallaby/active_record/model_decorator/fields_builder.rb +7 -0
  13. data/lib/adaptors/wallaby/active_record/model_decorator/fields_builder/association_builder.rb +11 -0
  14. data/lib/adaptors/wallaby/active_record/model_decorator/fields_builder/polymorphic_builder.rb +10 -1
  15. data/lib/adaptors/wallaby/active_record/model_decorator/fields_builder/sti_builder.rb +14 -7
  16. data/lib/adaptors/wallaby/active_record/model_decorator/title_field_finder.rb +4 -0
  17. data/lib/adaptors/wallaby/active_record/model_finder.rb +4 -3
  18. data/lib/adaptors/wallaby/active_record/model_pagination_provider.rb +3 -6
  19. data/lib/adaptors/wallaby/active_record/model_service_provider.rb +12 -3
  20. data/lib/adaptors/wallaby/active_record/model_service_provider/normalizer.rb +16 -1
  21. data/lib/adaptors/wallaby/active_record/model_service_provider/permitter.rb +14 -2
  22. data/lib/adaptors/wallaby/active_record/model_service_provider/querier.rb +46 -1
  23. data/lib/adaptors/wallaby/active_record/model_service_provider/querier/transformer.rb +11 -5
  24. data/lib/adaptors/wallaby/active_record/model_service_provider/validator.rb +6 -0
  25. data/lib/concerns/wallaby/resources_helper_methods.rb +44 -0
  26. data/lib/decorators/wallaby/abstract_resource_decorator.rb +9 -4
  27. data/lib/errors/wallaby/model_not_found.rb +1 -0
  28. data/lib/errors/wallaby/resource_not_found.rb +1 -0
  29. data/lib/forms/wallaby/form_builder.rb +5 -3
  30. data/lib/helpers/wallaby/application_helper.rb +10 -1
  31. data/lib/helpers/wallaby/base_helper.rb +12 -4
  32. data/lib/helpers/wallaby/form_helper.rb +7 -4
  33. data/lib/helpers/wallaby/links_helper.rb +10 -7
  34. data/lib/helpers/wallaby/resources_helper.rb +2 -0
  35. data/lib/helpers/wallaby/secure_helper.rb +13 -7
  36. data/lib/helpers/wallaby/styling_helper.rb +1 -1
  37. data/lib/interfaces/wallaby/mode.rb +38 -16
  38. data/lib/interfaces/wallaby/model_decorator.rb +36 -27
  39. data/lib/interfaces/wallaby/model_decorator/field_helpers.rb +12 -2
  40. data/lib/interfaces/wallaby/model_finder.rb +1 -0
  41. data/lib/interfaces/wallaby/model_pagination_provider.rb +6 -5
  42. data/lib/interfaces/wallaby/model_service_provider.rb +10 -2
  43. data/lib/paginators/wallaby/abstract_resource_paginator.rb +6 -1
  44. data/lib/parsers/wallaby/parser.rb +1 -0
  45. data/lib/responders/wallaby/abstract_responder.rb +15 -2
  46. data/lib/routes/wallaby/resources_router.rb +4 -0
  47. data/lib/servicers/wallaby/abstract_model_servicer.rb +25 -1
  48. data/lib/servicers/wallaby/model_servicer.rb +1 -0
  49. data/lib/services/wallaby/link_options_normalizer.rb +13 -9
  50. data/lib/services/wallaby/lookup_context_wrapper.rb +11 -2
  51. data/lib/services/wallaby/map.rb +107 -69
  52. data/lib/services/wallaby/map/mode_mapper.rb +2 -0
  53. data/lib/services/wallaby/map/model_class_collector.rb +7 -0
  54. data/lib/services/wallaby/map/model_class_mapper.rb +15 -7
  55. data/lib/services/wallaby/partial_renderer.rb +7 -0
  56. data/lib/services/wallaby/prefixes_builder.rb +18 -0
  57. data/lib/services/wallaby/sorting/hash_builder.rb +7 -1
  58. data/lib/services/wallaby/sorting/link_builder.rb +6 -1
  59. data/lib/services/wallaby/sorting/next_builder.rb +23 -2
  60. data/lib/tree/wallaby/node.rb +2 -0
  61. data/lib/utils/wallaby/test_utils.rb +32 -0
  62. data/lib/utils/wallaby/utils.rb +51 -5
  63. data/lib/wallaby.rb +1 -0
  64. data/lib/wallaby/configuration.rb +9 -3
  65. data/lib/wallaby/configuration/features.rb +2 -1
  66. data/lib/wallaby/configuration/mapping.rb +66 -0
  67. data/lib/wallaby/configuration/metadata.rb +1 -0
  68. data/lib/wallaby/configuration/pagination.rb +2 -1
  69. data/lib/wallaby/engine.rb +4 -0
  70. data/lib/wallaby/version.rb +1 -1
  71. metadata +5 -3
  72. data/lib/tasks/wallaby_tasks.rake +0 -4
@@ -5,15 +5,15 @@ module Wallaby
5
5
  # Guess the model class from class name
6
6
  # @return [Class]
7
7
  def model_class
8
- return unless self < ::Wallaby::ResourceDecorator
9
- Map.model_class_map name.gsub 'Decorator', EMPTY_STRING
8
+ return unless self < ::Wallaby.configuration.mapping.resource_decorator
9
+ Map.model_class_map name.gsub('Decorator', EMPTY_STRING)
10
10
  end
11
11
 
12
12
  # Get the model decorator for the model class
13
13
  # It should be the same as #model_decorator
14
- # @return Wallaby::ModelDecorator
14
+ # @return [Wallaby::ModelDecorator]
15
15
  def model_decorator
16
- return unless self < ::Wallaby::ResourceDecorator
16
+ return unless self < ::Wallaby.configuration.mapping.resource_decorator
17
17
  Map.model_decorator_map model_class
18
18
  end
19
19
 
@@ -25,6 +25,7 @@ module Wallaby
25
25
 
26
26
  attr_reader :resource, :model_decorator
27
27
 
28
+ # @param resource [Object] resource object
28
29
  def initialize(resource)
29
30
  @resource = resource
30
31
  @model_decorator = Map.model_decorator_map model_class
@@ -62,11 +63,15 @@ module Wallaby
62
63
  delegate :to_s, :to_param, to: :resource
63
64
 
64
65
  # We delegate missing methods to resource
66
+ # @param method_id [String,Symbol]
67
+ # @param args [Array]
65
68
  def method_missing(method_id, *args)
66
69
  return super unless @resource.respond_to? method_id
67
70
  @resource.public_send method_id, *args
68
71
  end
69
72
 
73
+ # @param method_id [String,Symbol]
74
+ # @param _include_private [Boolean]
70
75
  def respond_to_missing?(method_id, _include_private)
71
76
  @resource.respond_to?(method_id) || super
72
77
  end
@@ -1,6 +1,7 @@
1
1
  module Wallaby
2
2
  # Model not found error
3
3
  class ModelNotFound < NotFound
4
+ # @return [String] not found error message
4
5
  def message
5
6
  I18n.t 'errors.not_found.model', model: super
6
7
  end
@@ -1,6 +1,7 @@
1
1
  module Wallaby
2
2
  # Resource not found error
3
3
  class ResourceNotFound < NotFound
4
+ # @return [String] resource not found error message
4
5
  def message
5
6
  I18n.t 'errors.not_found.resource', resource: super
6
7
  end
@@ -23,14 +23,16 @@ module Wallaby
23
23
  end
24
24
 
25
25
  # Extend label to accept proc type `text` argument
26
+ # @see ActionView::Helpers::FormBuilder#label
26
27
  def label(method, text = nil, options = {}, &block)
27
- text = instance_exec(&text) if text.respond_to? :call
28
+ text = instance_exec(&text) if text.is_a?(Proc)
28
29
  super
29
30
  end
30
31
 
31
32
  # Extend select to accept proc type `choices` argument
33
+ # @see ActionView::Helpers::FormBuilder#select
32
34
  def select(method, choices = nil, options = {}, html_options = {}, &block)
33
- choices = instance_exec(&choices) if choices.respond_to? :call
35
+ choices = instance_exec(&choices) if choices.is_a?(Proc)
34
36
  super
35
37
  end
36
38
 
@@ -40,7 +42,7 @@ module Wallaby
40
42
  def method_missing(method, *args, &block)
41
43
  return super unless @template.respond_to? method
42
44
  # Delegate the method so that we don't come in here the next time
43
- # same method is called
45
+ # when same method is called
44
46
  self.class.delegate method, to: :@template
45
47
  @template.public_send method, *args, &block
46
48
  end
@@ -2,7 +2,10 @@ module Wallaby
2
2
  # Application helper
3
3
  module ApplicationHelper
4
4
  # Override `actionview/lib/action_view/routing_url_for.rb#url_for`
5
- # to handle the url_for properly for wallaby engine
5
+ # to handle the url_for properly for wallaby engine when options contains
6
+ # values of both `:resources` and `:action`
7
+ # @param options [String, Hash]
8
+ # @return [String] url
6
9
  def url_for(options = nil)
7
10
  # possible Hash or Parameters
8
11
  if options.respond_to?(:to_h) \
@@ -14,6 +17,9 @@ module Wallaby
14
17
  end
15
18
 
16
19
  # Add turbolinks options when it's enabled
20
+ # @see ActionView::Helpers::AssetTagHelper#stylesheet_link_tag
21
+ # @param sources [Array<String>] source name under `app/assets/stylesheets`
22
+ # @return [String] a list of stylesheet link tags
17
23
  def stylesheet_link_tag(*sources)
18
24
  default_options =
19
25
  if Wallaby.configuration.features.turbolinks_enabled
@@ -26,6 +32,9 @@ module Wallaby
26
32
  end
27
33
 
28
34
  # Add turbolinks options when it's enabled
35
+ # @see ActionView::Helpers::AssetTagHelper#javascript_include_tag
36
+ # @param sources [Array<String>] source name under `app/assets/javascripts`
37
+ # @return [String] a list of javascript script tags
29
38
  def javascript_include_tag(*sources)
30
39
  default_options =
31
40
  if Wallaby.configuration.features.turbolinks_enabled
@@ -5,15 +5,21 @@ module Wallaby
5
5
  include LinksHelper
6
6
 
7
7
  # @see Utils.to_model_label
8
+ # @return [String] label for given model class
8
9
  def to_model_label(model_class)
9
10
  Utils.to_model_label model_class
10
11
  end
11
12
 
12
13
  # @see Map.resources_name_map
14
+ # @return [String] resources name for given model class
13
15
  def to_resources_name(model_class)
14
16
  Map.resources_name_map model_class
15
17
  end
16
18
 
19
+ # Generate body class from the following sources:
20
+ # - `:action` parameter
21
+ # - converted current resources name (e.g. `order__item` from `Order::Item`)
22
+ # - `:custom_body_class` content
17
23
  # @return [String] css classes for body tag
18
24
  def body_class
19
25
  [
@@ -23,9 +29,10 @@ module Wallaby
23
29
  ].compact.join SPACE
24
30
  end
25
31
 
26
- # Turn a list of classes into tree structure
27
- # @param classes [Array] a list of all the classes that wallaby supports
28
- # @return [Array] a tree structure of given classes
32
+ # Turn a list of classes into tree structure by inheritance.
33
+ # @param classes [Array<Class>]
34
+ # a list of all the classes that wallaby supports
35
+ # @return [Array<Wallaby::Node>] a tree structure of given classes
29
36
  def model_classes(classes = Map.model_classes)
30
37
  nested_hash = classes.each_with_object({}) do |klass, hash|
31
38
  hash[klass] = Node.new(klass)
@@ -37,7 +44,8 @@ module Wallaby
37
44
  nested_hash.values.select { |v| v.parent.nil? }
38
45
  end
39
46
 
40
- # @param array [Array] root classes
47
+ # Turn the tree of classes into a nested `ul` list.
48
+ # @param array [Array<Wallaby::Node>] root classes
41
49
  # @return [String] HTML for the whole tree
42
50
  def model_tree(array)
43
51
  return EMPTY_STRING.html_safe if array.blank?
@@ -3,17 +3,19 @@ module Wallaby
3
3
  module FormHelper
4
4
  # @param options [Hash, String]
5
5
  # @param locals [Hash] local variables for the partial
6
+ # @return [String] rendered type partial for a form
6
7
  def form_type_partial_render(options = {}, locals = {}, &block)
7
8
  PartialRenderer.render_form self, options, locals, &block
8
9
  end
9
10
 
10
11
  # To generate remote url for auto select plugin.
11
- # @see app/assets/javascripts/wallaby/auto_select.js
12
+ # @see https://github.com/reinteractive/wallaby/blob/master/app/assets/javascripts/wallaby/auto_select.js
12
13
  # @param url [String, nil]
13
14
  # if url is nil, it will fall back to default remote url
14
15
  # @param model_class [Class]
15
16
  # @param wildcard [String] wildcard that auto_select uses to replace with
16
17
  # the typed keyword
18
+ # @return [String] url for autocomplete
17
19
  def remote_url(url, model_class, wildcard = 'QUERY')
18
20
  url ||
19
21
  index_path(
@@ -24,13 +26,14 @@ module Wallaby
24
26
  end
25
27
 
26
28
  # To generate dropdown options (class => url) for polymorphic class.
27
- # @see app/assets/javascripts/wallaby/auto_select.js
29
+ # @see https://github.com/reinteractive/wallaby/blob/master/app/assets/javascripts/wallaby/auto_select.js
28
30
  # This function will pull out remote urls from `metadata[:remote_urls]`
29
31
  # (Class => url).
32
+ # @see ActionView::Helpers::FormOptionsHelper#options_for_select
30
33
  # @param metadata [Hash]
31
- # @param wildcard [String]
34
+ # @param wildcard [String] wildcard to be used in the url
32
35
  # @param select_options [Hash]
33
- # @return [String] HTML
36
+ # @return [String] options HTML
34
37
  def polymorphic_options(metadata, wildcard = 'QUERY', select_options = {})
35
38
  urls = metadata[:remote_urls] || {}
36
39
  options = (metadata[:polymorphic_list] || []).map do |klass|
@@ -1,16 +1,17 @@
1
1
  module Wallaby
2
2
  # Links helper
3
3
  module LinksHelper
4
- # Permit the params used by Wallaby
4
+ # @return [ActionController::Parameters] whitelisted params used by Wallaby
5
5
  def index_params
6
6
  params.except(:resources, :utf8).permit(:filter, :page, :per, :q, :sort)
7
7
  end
8
8
 
9
9
  # Return link to index page by a given model class
10
+ #
10
11
  # If user's not authorized, nil will be returned
11
12
  # @param model_class [Class] model class
12
13
  # @param url_params [ActionController::Parameters, Hash]
13
- # @param html_options [Hash] (see ActionView::Helpers::UrlHelper#link_to)
14
+ # @param html_options [Hash] (@see ActionView::Helpers::UrlHelper#link_to)
14
15
  # @return [String, nil] anchor element
15
16
  def index_link(model_class, url_params: {}, html_options: {}, &block)
16
17
  return if cannot? :index, model_class
@@ -24,10 +25,11 @@ module Wallaby
24
25
  end
25
26
 
26
27
  # Return link to create page by a given model class
28
+ #
27
29
  # If user's not authorized, nil will be returned
28
30
  # @param model_class [Class] model class
29
31
  # @param options [Hash]
30
- # @param html_options [Hash] (see ActionView::Helpers::UrlHelper#link_to)
32
+ # @param html_options [Hash] (@see ActionView::Helpers::UrlHelper#link_to)
31
33
  # @return [String, nil] anchor element
32
34
  def new_link(model_class, html_options: {}, &block)
33
35
  return if cannot? :new, model_class
@@ -44,7 +46,7 @@ module Wallaby
44
46
  # If user's not authorized, resource label will be returned
45
47
  # @param resource [Object, Wallaby::ResourceDecorator] model class
46
48
  # @param options [Hash]
47
- # @param html_options [Hash] (see ActionView::Helpers::UrlHelper#link_to)
49
+ # @param html_options [Hash] (@see ActionView::Helpers::UrlHelper#link_to)
48
50
  # @return [String] anchor element / text
49
51
  def show_link(resource, options: {}, html_options: {}, &block)
50
52
  # NOTE: to_s is a must
@@ -64,7 +66,7 @@ module Wallaby
64
66
  # If user's not authorized, resource label will be returned
65
67
  # @param resource [Object, Wallaby::ResourceDecorator] model class
66
68
  # @param options [Hash]
67
- # @param html_options [Hash] (see ActionView::Helpers::UrlHelper#link_to)
69
+ # @param html_options [Hash] (@see ActionView::Helpers::UrlHelper#link_to)
68
70
  # @return [String] anchor element / text
69
71
  def edit_link(resource, options: {}, html_options: {}, &block)
70
72
  default = options[:readonly] && decorate(resource).to_label || nil
@@ -80,10 +82,11 @@ module Wallaby
80
82
  end
81
83
 
82
84
  # Return link to delete action by a given model class
85
+ #
83
86
  # If user's not authorized, nil will be returned
84
87
  # @param resource [Object, Wallaby::ResourceDecorator] model class
85
88
  # @param options [Hash]
86
- # @param html_options [Hash] (see ActionView::Helpers::UrlHelper#link_to)
89
+ # @param html_options [Hash] (@see ActionView::Helpers::UrlHelper#link_to)
87
90
  # @return [String, nil] anchor element
88
91
  def delete_link(resource, html_options: {}, &block)
89
92
  return if cannot? :destroy, extract(resource)
@@ -102,7 +105,7 @@ module Wallaby
102
105
  end
103
106
 
104
107
  # Return link to cancel an action
105
- # @param html_options [Hash] (see ActionView::Helpers::UrlHelper#link_to)
108
+ # @param html_options [Hash] (@see ActionView::Helpers::UrlHelper#link_to)
106
109
  # @return [String] HTML anchor element
107
110
  def cancel_link(html_options = {}, &block)
108
111
  block ||= -> { t 'links.cancel' }
@@ -4,6 +4,8 @@ module Wallaby
4
4
  include FormHelper
5
5
  include IndexHelper
6
6
 
7
+ # @see Map.model_decorator_map
8
+ # @return [Wallaby::ModelDecorator]
7
9
  def model_decorator(model_class)
8
10
  Map.model_decorator_map model_class
9
11
  end
@@ -1,7 +1,9 @@
1
1
  module Wallaby
2
2
  # Secure helper
3
3
  module SecureHelper
4
- # Image portrait for given user
4
+ # Image portrait for given user.
5
+ # - if email is present, a gravatar image tag will be returned
6
+ # - otherwise, an user icon will be returned
5
7
  # @param user [Object]
6
8
  # @return [String] IMG or I element
7
9
  def user_portrait(user = current_user)
@@ -18,20 +20,24 @@ module Wallaby
18
20
  end
19
21
 
20
22
  # Logout path for given user
23
+ # @see Wallaby::Configuration::Security#logout_path
21
24
  # @param user [Object]
22
25
  # @param app [Object]
23
- # @return [String] HTML anchor element
26
+ # @return [String] url to log out
24
27
  def logout_path(user = current_user, app = main_app)
25
28
  path = Wallaby.configuration.security.logout_path
26
- path ||= if defined? ::Devise
27
- scope = ::Devise::Mapping.find_scope! user
28
- "destroy_#{scope}_session_path"
29
- end
29
+ path ||=
30
+ if defined? ::Devise
31
+ scope = ::Devise::Mapping.find_scope! user
32
+ "destroy_#{scope}_session_path"
33
+ end
30
34
  app.public_send path if path && app.respond_to?(path)
31
35
  end
32
36
 
33
37
  # Logout method for given user
34
- # @return [String, Symbol]
38
+ # @see Wallaby::Configuration::Security#logout_method
39
+ # @param user [Object]
40
+ # @return [String, Symbol] http method to log out
35
41
  def logout_method(user = current_user)
36
42
  http_method = Wallaby.configuration.security.logout_method
37
43
  http_method || if defined? ::Devise
@@ -2,7 +2,7 @@ module Wallaby
2
2
  # Styling helper
3
3
  module StylingHelper
4
4
  # Shortcut to build up the html options as keyword arguments
5
- # @param string_or_array [String, Array]
5
+ # @param string_or_array [String, Array<String>]
6
6
  # @return [Hash]
7
7
  def html_classes(string_or_array)
8
8
  { html_options: { class: string_or_array } }
@@ -1,24 +1,46 @@
1
1
  module Wallaby
2
2
  # This is the abstract class that all ORM modes to have implemented.
3
3
  class Mode
4
- INTERFACE_METHODS = %w(
5
- model_decorator model_finder
6
- model_service_provider model_pagination_provider
7
- ).freeze
4
+ class << self
5
+ # @see Wallaby::ModelDecorator
6
+ # @return [Wallaby::ModelDecorator] model decorator for the mode
7
+ def model_decorator
8
+ check_and_constantize __callee__
9
+ end
10
+
11
+ # @see Wallaby::ModelFinder
12
+ # @return [Wallaby::ModelFinder] model finder for the mode
13
+ def model_finder
14
+ check_and_constantize __callee__
15
+ end
16
+
17
+ # @see Wallaby::ModelServiceProvider
18
+ # @return [Wallaby::ModelServiceProvider] service provider for the mode
19
+ def model_service_provider
20
+ check_and_constantize __callee__
21
+ end
22
+
23
+ # @see Wallaby::ModelPaginationProvider
24
+ # @return [Wallaby::ModelPaginationProvider]
25
+ # pagination provider for the mode
26
+ def model_pagination_provider
27
+ check_and_constantize __callee__
28
+ end
29
+
30
+ private
8
31
 
9
- INTERFACE_METHODS.each do |method_id|
10
- define_singleton_method method_id do
11
- begin
12
- method_class = __callee__.to_s.classify
13
- class_name = "#{name}::#{method_class}"
14
- parent_class = "Wallaby::#{method_class}".constantize
15
- class_name.constantize.tap do |klass|
16
- next if klass < parent_class
17
- raise InvalidError, "#{klass} must inherit #{parent_class}"
18
- end
19
- rescue NameError
20
- raise NotImplemented, class_name
32
+ #
33
+ # @return [Class] constantized class
34
+ def check_and_constantize(method_id)
35
+ method_class = method_id.to_s.classify
36
+ class_name = "#{name}::#{method_class}"
37
+ parent_class = "Wallaby::#{method_class}".constantize
38
+ class_name.constantize.tap do |klass|
39
+ next if klass < parent_class
40
+ raise InvalidError, "#{klass} must inherit #{parent_class}"
21
41
  end
42
+ rescue NameError
43
+ raise NotImplemented, class_name
22
44
  end
23
45
  end
24
46
  end
@@ -1,8 +1,8 @@
1
1
  module Wallaby
2
- # Model Decorator interface, designed to maintain metadata information for all
2
+ # Model Decorator interface, designed to maintain metadata for all
3
3
  # the fields coming from data source (database/api)
4
4
  # @see Wallaby::ResourceDecorator for more information on how to customize
5
- # metadata information
5
+ # metadata
6
6
  class ModelDecorator
7
7
  include FieldHelpers
8
8
 
@@ -10,83 +10,85 @@ module Wallaby
10
10
  attr_writer \
11
11
  :field_names, :index_field_names, :show_field_names, :form_field_names
12
12
 
13
+ # Initialize with model class
14
+ # @param model_class [Class] model class
13
15
  def initialize(model_class)
14
16
  @model_class = model_class
15
17
  end
16
18
 
17
- # @return [Hash] metadata information for all fields that index/show/form
18
- # will copy
19
+ # @return [Hash] origin metadata for fields
19
20
  def fields
20
21
  raise NotImplemented
21
22
  end
22
23
 
23
- # @param fields [Hash] metadata information for all fields
24
+ # Set metadata as origin
25
+ # @param fields [Hash] metadata
24
26
  def fields=(fields)
25
27
  @fields = ::ActiveSupport::HashWithIndifferentAccess.new fields
26
28
  end
27
29
 
28
- # @return [Array] field names
30
+ # @return [Array<String>, Array<Symbol>] a list of field names
29
31
  def field_names
30
32
  @field_names ||= reposition fields.keys, primary_key
31
33
  end
32
34
 
33
- # @return [Hash] metadata information for all fields that would be used on
34
- # index page
35
+ # @return [Hash] metadata for fields used on index page
35
36
  def index_fields
36
37
  raise NotImplemented
37
38
  end
38
39
 
39
- # @param fields [Hash] metadata information for all fields that would be
40
- # used on index page
40
+ # Set metadata for index page
41
+ # @param fields [Hash] metadata
41
42
  def index_fields=(fields)
42
43
  @index_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields
43
44
  end
44
45
 
45
- # @return [Array] field names of index page
46
+ # @return [Array<String>, Array<Symbol>]
47
+ # a list of field names displayed on index page
46
48
  def index_field_names
47
49
  @index_field_names ||= reposition index_fields.keys, primary_key
48
50
  end
49
51
 
50
- # @return [Hash] metadata information for all fields that would be used on
51
- # show page
52
+ # @return [Hash] metadata for fields used on show page
52
53
  def show_fields
53
54
  raise NotImplemented
54
55
  end
55
56
 
56
- # @param fields [Hash] metadata information for all fields that would be
57
- # used on show page
57
+ # Set metadata for show page
58
+ # @param fields [Hash] metadata
58
59
  def show_fields=(fields)
59
60
  @show_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields
60
61
  end
61
62
 
62
- # @return [Array] field names of show page
63
+ # @return [Array<String>, Array<Symbol>]
64
+ # a list of field names displayed on show page
63
65
  def show_field_names
64
66
  @show_field_names ||= reposition show_fields.keys, primary_key
65
67
  end
66
68
 
67
- # @return [Hash] metadata information for all fields that would be used on
68
- # form page
69
+ # @return [Hash] metadata for fields used on form (new/edit) page
69
70
  def form_fields
70
71
  raise NotImplemented
71
72
  end
72
73
 
73
- # @param fields [Hash] metadata information for all fields that would be
74
- # used on form page
74
+ # Set metadata for form (new/edit) page
75
+ # @param fields [Hash] metadata
75
76
  def form_fields=(fields)
76
77
  @form_fields = ::ActiveSupport::HashWithIndifferentAccess.new fields
77
78
  end
78
79
 
79
- # @return [Array] field names of form page
80
+ # @return [Array<String>, Array<Symbol>]
81
+ # a list field names displayed on form (new/edit) page
80
82
  def form_field_names
81
83
  @form_field_names ||= reposition form_fields.keys, primary_key
82
84
  end
83
85
 
84
- # @return [Hash] custom filters
86
+ # @return [Hash] metadata for custom filters used on index page
85
87
  def filters
86
88
  @filters ||= ::ActiveSupport::HashWithIndifferentAccess.new
87
89
  end
88
90
 
89
- # @return [Hash] errors
91
+ # @return [Hash] validation errors for current resource
90
92
  def form_active_errors(_resource)
91
93
  raise NotImplemented
92
94
  end
@@ -96,22 +98,29 @@ module Wallaby
96
98
  raise NotImplemented
97
99
  end
98
100
 
101
+ # To guess the title for a resource.
102
+ #
103
+ # This title will be used on the following places:
104
+ # - page title on show page
105
+ # - in the response for autocomplete association field
106
+ # - title of show link for a resource
99
107
  # @param _resource [Object] resource
100
- # @return [String] title of given resource
108
+ # @return [String] title of current resource
101
109
  def guess_title(_resource)
102
110
  raise NotImplemented
103
111
  end
104
112
 
105
- # @return [String] resources name mapped from model class
113
+ # @return [String] resources name coverted from model class
106
114
  def resources_name
107
115
  Map.resources_name_map @model_class
108
116
  end
109
117
 
110
118
  protected
111
119
 
112
- # @param field_names [Array] field names
120
+ # @param field_names [Array<String>, Array<Symbol>] field names
113
121
  # @param primary_key [String] primary key name
114
- # @return [Array] a list of field names that primary key goes first
122
+ # @return [Array<String>, Array<Symbol>]
123
+ # a list of field names that primary key goes first
115
124
  def reposition(field_names, primary_key)
116
125
  field_names.unshift(primary_key).uniq
117
126
  end