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

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_fieldsObject

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_nameObject

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_fieldsObject

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_headersObject

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

#scopesObject

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_fieldsObject

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.

Returns:

  • (Boolean)


54
55
56
# File 'lib/madmin/resourceable.rb', line 54

def show_in_menu?
  true
end

#slugObject

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