Class: Ez::Resources::Manager::Config
- Inherits:
-
Object
- Object
- Ez::Resources::Manager::Config
- Includes:
- Pagy::Backend
- Defined in:
- lib/ez/resources/manager/config.rb
Constant Summary collapse
- DEFAULT_ACTIONS =
%i[index show new create edit update destroy].freeze
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#paginator ⇒ Object
readonly
Returns the value of attribute paginator.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
Instance Method Summary collapse
- #actions ⇒ Object
- #collection_actions ⇒ Object
- #collection_columns ⇒ Object
- #collection_search? ⇒ Boolean
- #collection_views ⇒ Object
- #data ⇒ Object
- #form_fields ⇒ Object
- #hooks ⇒ Object
-
#initialize(controller:, dsl_config:, data: nil) ⇒ Config
constructor
A new instance of Config.
- #model ⇒ Object
- #paginate_collection? ⇒ Boolean
- #params ⇒ Object
- #path_for(action:, id: nil, params: nil) ⇒ Object
- #resource_label ⇒ Object
- #resource_name ⇒ Object
- #resources_name ⇒ Object
- #show_action_renders_form? ⇒ Boolean
- #total_count ⇒ Object
Constructor Details
#initialize(controller:, dsl_config:, data: nil) ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 |
# File 'lib/ez/resources/manager/config.rb', line 13 def initialize(controller:, dsl_config:, data: nil) @controller = controller @dsl_config = dsl_config @data = data end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
11 12 13 |
# File 'lib/ez/resources/manager/config.rb', line 11 def controller @controller end |
#paginator ⇒ Object (readonly)
Returns the value of attribute paginator.
11 12 13 |
# File 'lib/ez/resources/manager/config.rb', line 11 def paginator @paginator end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
11 12 13 |
# File 'lib/ez/resources/manager/config.rb', line 11 def search @search end |
Instance Method Details
#actions ⇒ Object
43 44 45 |
# File 'lib/ez/resources/manager/config.rb', line 43 def actions @actions ||= dsl_config.actions || DEFAULT_ACTIONS end |
#collection_actions ⇒ Object
89 90 91 |
# File 'lib/ez/resources/manager/config.rb', line 89 def collection_actions @colleciton_actions ||= dsl_config.collection_actions || [] end |
#collection_columns ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/ez/resources/manager/config.rb', line 79 def collection_columns @collection_columns ||= dsl_config.collection_columns || model.columns.map do |column| Ez::Resources::Manager::Field.new( name: column.name, title: column.name.to_s.humanize, type: column..type ) end.reject { |col| Ez::Resources.config.ignore_fields.include?(col.name) } end |
#collection_search? ⇒ Boolean
71 72 73 |
# File 'lib/ez/resources/manager/config.rb', line 71 def collection_search? @collection_search ||= dsl_config.collection_search != false end |
#collection_views ⇒ Object
75 76 77 |
# File 'lib/ez/resources/manager/config.rb', line 75 def collection_views @collection_views ||= dsl_config.collection_views || [] end |
#data ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ez/resources/manager/config.rb', line 19 def data @data ||= case controller.action_name when 'index' then collection when 'new' then new_resource when 'show' then resource when 'edit' then resource when 'update' then resource when 'destroy' then resource else raise ConfigurationError, "Invalid action #{controller.action_name}" end end |
#form_fields ⇒ Object
93 94 95 |
# File 'lib/ez/resources/manager/config.rb', line 93 def form_fields @form_fields ||= dsl_config.form_fields || collection_columns || [] end |
#hooks ⇒ Object
51 52 53 |
# File 'lib/ez/resources/manager/config.rb', line 51 def hooks @hooks ||= dsl_config.hooks || [] end |
#model ⇒ Object
36 37 38 39 40 41 |
# File 'lib/ez/resources/manager/config.rb', line 36 def model @model ||= dsl_config.model || controller_name.classify.constantize rescue NameError raise GuessingError, "Ez::Resources tried to guess model name as #{controller_name.classify} but constant is missing. You can define model class explicitly with :model options" end |
#paginate_collection? ⇒ Boolean
67 68 69 |
# File 'lib/ez/resources/manager/config.rb', line 67 def paginate_collection? @paginate_collection ||= dsl_config.paginate_collection != false end |
#params ⇒ Object
107 108 109 |
# File 'lib/ez/resources/manager/config.rb', line 107 def params @params ||= controller.params end |
#path_for(action:, id: nil, params: nil) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/ez/resources/manager/config.rb', line 97 def path_for(action:, id: nil, params: nil) if id controller.url_for(action: action, id: id, only_path: true) elsif params controller.url_for(action: action, **params, only_path: true) else controller.url_for(action: action, only_path: true) end end |
#resource_label ⇒ Object
55 56 57 |
# File 'lib/ez/resources/manager/config.rb', line 55 def resource_label @resource_label ||= dsl_config.resource_label || :id end |
#resource_name ⇒ Object
59 60 61 |
# File 'lib/ez/resources/manager/config.rb', line 59 def resource_name @resource_name ||= controller_name.classify end |
#resources_name ⇒ Object
63 64 65 |
# File 'lib/ez/resources/manager/config.rb', line 63 def resources_name @resources_name ||= dsl_config.resources_name || resource_name.pluralize end |
#show_action_renders_form? ⇒ Boolean
47 48 49 |
# File 'lib/ez/resources/manager/config.rb', line 47 def show_action_renders_form? @show_action_renders_form ||= dsl_config.show_action_renders_form end |
#total_count ⇒ Object
32 33 34 |
# File 'lib/ez/resources/manager/config.rb', line 32 def total_count @total_count ||= model.count end |