Class: ClAdmin::Resource
- Inherits:
-
Object
- Object
- ClAdmin::Resource
- Defined in:
- lib/cl_admin/resource.rb,
lib/cl_admin/resource/field.rb
Defined Under Namespace
Classes: Field
Constant Summary collapse
- @@all_resources =
[]
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#form_fields ⇒ Object
readonly
Returns the value of attribute form_fields.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#index_fields ⇒ Object
readonly
Returns the value of attribute index_fields.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#show_fields ⇒ Object
readonly
Returns the value of attribute show_fields.
-
#subtitle ⇒ Object
readonly
Returns the value of attribute subtitle.
Class Method Summary collapse
Instance Method Summary collapse
- #default_columns ⇒ Object
- #generate_routes? ⇒ Boolean
-
#initialize(model:, name: nil, icon: nil, linked_on_dashboard: false, generate_routes: true, path: nil) ⇒ Resource
constructor
A new instance of Resource.
- #linked_on_dashboard? ⇒ Boolean
- #paths ⇒ Object
- #plural_name ⇒ Object
Constructor Details
#initialize(model:, name: nil, icon: nil, linked_on_dashboard: false, generate_routes: true, path: nil) ⇒ Resource
Returns a new instance of Resource.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cl_admin/resource.rb', line 9 def initialize(model:, name: nil, icon: nil, linked_on_dashboard: false, generate_routes: true, path: nil) @model = model @name = name || model.try(:model_name).try(:human) @linked_on_dashboard = linked_on_dashboard @icon = icon @link = '#' @subtitle = nil @generate_routes = generate_routes @path = path || plural_name.downcase @fields = [] model.attribute_names.each do |attr| field = Field.new( attribute: attr, name: model.human_attribute_name(attr), create: default_columns.include?(attr), show: (model.attribute_names - ["id"]).include?(attr), index: (model.attribute_names - ["id"]).include?(attr), edit: default_columns.include?(attr) ) @fields.push field end @index_fields ||= default_columns @form_fields ||= default_columns @show_fields ||= model.attribute_names - ["id"] end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def fields @fields end |
#form_fields ⇒ Object (readonly)
Returns the value of attribute form_fields.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def form_fields @form_fields end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def icon @icon end |
#index_fields ⇒ Object (readonly)
Returns the value of attribute index_fields.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def index_fields @index_fields end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def link @link end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def path @path end |
#show_fields ⇒ Object (readonly)
Returns the value of attribute show_fields.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def show_fields @show_fields end |
#subtitle ⇒ Object (readonly)
Returns the value of attribute subtitle.
7 8 9 |
# File 'lib/cl_admin/resource.rb', line 7 def subtitle @subtitle end |
Class Method Details
.all ⇒ Object
65 66 67 |
# File 'lib/cl_admin/resource.rb', line 65 def self.all @@all_resources end |
Instance Method Details
#default_columns ⇒ Object
56 57 58 |
# File 'lib/cl_admin/resource.rb', line 56 def default_columns model.attribute_names - ["id", "created_at", "updated_at"] end |
#generate_routes? ⇒ Boolean
73 74 75 |
# File 'lib/cl_admin/resource.rb', line 73 def generate_routes? !!@generate_routes end |
#linked_on_dashboard? ⇒ Boolean
69 70 71 |
# File 'lib/cl_admin/resource.rb', line 69 def linked_on_dashboard? !!@linked_on_dashboard end |
#paths ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/cl_admin/resource.rb', line 44 def paths @paths ||= { new: "new_#{model.name.underscore}_path", index: "#{plural_name.underscore}_path", edit: "edit_#{model.name.underscore}_path" } end |
#plural_name ⇒ Object
52 53 54 |
# File 'lib/cl_admin/resource.rb', line 52 def plural_name @plural_name ||= @name.pluralize end |