Module: Madmin::Resourceable
- Defined in:
- lib/madmin/resourceable.rb,
lib/madmin/resourceable/class_methods.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#form_fields ⇒ Object
This method returns a list of fields where the index option is truthy.
-
#friendly_name ⇒ Object
This methods exposes the underlying resource’s name in a way humans can enjoy and understand.
-
#index_fields ⇒ Object
This method returns a list of fields where the index option is truthy.
-
#index_headers ⇒ Object
This method returns a list of labels for fields where the index option is truthy.
-
#scopes ⇒ Object
This method affords us the ability to retrieve a list of the scopes from the class variable.
-
#show_fields ⇒ Object
This method, when used in the resource, sets all fields to be used when the show partial is rendered.
-
#show_in_menu? ⇒ Boolean
This method exposes a way to control if the resource should visible in the menu.
-
#slug ⇒ Object
This method affords us the ability to have a consistently rendered slug for a resource.
Class Method Details
.included(base) ⇒ Object
11 12 13 |
# File 'lib/madmin/resourceable.rb', line 11 def included(base) base.extend Madmin::Resourceable::ClassMethods end |
Instance Method Details
#form_fields ⇒ Object
This method returns a list of fields where the index option is truthy.
19 20 21 |
# File 'lib/madmin/resourceable.rb', line 19 def form_fields self.class.fields.values.select { |field| field.form } end |
#friendly_name ⇒ Object
This methods exposes the underlying resource’s name in a way humans can enjoy and understand.
26 27 28 |
# File 'lib/madmin/resourceable.rb', line 26 def friendly_name self.class.model_name.split("::").join(" ") end |
#index_fields ⇒ Object
This method returns a list of fields where the index option is truthy.
33 34 35 |
# File 'lib/madmin/resourceable.rb', line 33 def index_fields self.class.fields.values.select { |field| field.index } end |
#index_headers ⇒ Object
This method returns a list of labels for fields where the index option is truthy.
40 41 42 |
# File 'lib/madmin/resourceable.rb', line 40 def index_headers index_fields.map { |field| field.label } end |
#scopes ⇒ Object
This method affords us the ability to retrieve a list of the scopes from the class variable.
47 48 49 |
# File 'lib/madmin/resourceable.rb', line 47 def scopes self.class.scopes end |
#show_fields ⇒ Object
This method, when used in the resource, sets all fields to be used when the show partial is rendered.
61 62 63 |
# File 'lib/madmin/resourceable.rb', line 61 def show_fields self.class.fields.values.select { |field| field.show } end |
#show_in_menu? ⇒ Boolean
This method exposes a way to control if the resource should visible in the menu.
54 55 56 |
# File 'lib/madmin/resourceable.rb', line 54 def true end |
#slug ⇒ Object
This method affords us the ability to have a consistently rendered slug for a resource.
68 69 70 |
# File 'lib/madmin/resourceable.rb', line 68 def slug ActiveModel::Naming.route_key(self.class.model) end |