class Ez::Resources::Manager::Config
Constants
- DEFAULT_ACTIONS
Attributes
controller[R]
dsl_config[R]
paginator[R]
search[R]
Public Class Methods
new(controller:, dsl_config:, data: nil)
click to toggle source
# 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
Public Instance Methods
actions()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 42 def actions @actions ||= dsl_config.actions || DEFAULT_ACTIONS end
collection_actions()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 88 def collection_actions @colleciton_actions ||= dsl_config.collection_actions || [] end
collection_columns()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 78 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.sql_type_metadata.type ) end.reject { |col| Ez::Resources.config.ignore_fields.include?(col.name) } end
collection_search?()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 70 def collection_search? @collection_search ||= dsl_config.collection_search != false end
collection_views()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 74 def collection_views @collection_views ||= dsl_config.collection_views || [] end
data()
click to toggle source
# 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()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 92 def form_fields @form_fields ||= dsl_config.form_fields || collection_columns || [] end
hooks()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 50 def hooks @hooks ||= dsl_config.hooks || [] end
model()
click to toggle source
# 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?()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 66 def paginate_collection? @paginate_collection ||= dsl_config.paginate_collection != false end
params()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 106 def params @params ||= controller.params end
path_for(action:, id: nil, params: nil)
click to toggle source
# File lib/ez/resources/manager/config.rb, line 96 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()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 54 def resource_label @resource_label ||= dsl_config.resource_label || :id end
resource_name()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 58 def resource_name @resource_name ||= controller_name.classify end
resources_name()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 62 def resources_name @resources_name ||= dsl_config.resources_name || resource_name.pluralize end
show_action_renders_form?()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 46 def show_action_renders_form? @show_action_renders_form ||= dsl_config.show_action_renders_form end
total_count()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 32 def total_count @total_count ||= model.count end
Private Instance Methods
collection()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 114 def collection return paginated_collection if paginate_collection? @collection ||= if dsl_config.collection_query dsl_config.collection_query.call(model, controller) else model.all end end
controller_name()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 145 def controller_name @controller_name ||= controller.controller_name end
new_resource()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 137 def new_resource @new_resource ||= model.new end
paginated_collection()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 124 def paginated_collection @search = model.ransack(params[:q]) @paginated_collection ||= if dsl_config.collection_query pagy, paginated_collection = pagy dsl_config.collection_query.call(search.result, controller) else pagy, paginated_collection = pagy search.result.includes(dsl_config.includes) end @paginator = pagy paginated_collection end
resource()
click to toggle source
# File lib/ez/resources/manager/config.rb, line 141 def resource @resource ||= model.find(controller.params[:id]) end