Class: Para::Component::Crud

Inherits:
Resource show all
Includes:
Exportable, History, Importable, Subclassable
Defined in:
app/models/para/component/crud.rb

Instance Method Summary collapse

Methods included from History

#history?

Methods included from Subclassable

#subclass_names, #subclassable?, #subclassable_with?

Methods included from Importable

#importable?, #importers

Methods included from Exportable

#exportable?

Methods inherited from Resource

#model, #model_table_name

Methods inherited from Base

configurable_on, #default_form_actions, #exportable?, #history?, #main_navigation_name, model_name, #name, register, #subclassable?, #to_param

Methods inherited from ApplicationRecord

with_belongs_to_optional_option_if_needed

Instance Method Details

#add_resource(resource) ⇒ Object



30
31
32
# File 'app/models/para/component/crud.rb', line 30

def add_resource(resource)
  component_resources.create(resource: resource)
end

#namespaced?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'app/models/para/component/crud.rb', line 19

def namespaced?
  case namespaced
  when 'true' then true
  else false
  end
end

#remove_resource(resource) ⇒ Object



34
35
36
# File 'app/models/para/component/crud.rb', line 34

def remove_resource(resource)
  component_resources.where(resource: resource).first.destroy
end

#resourcesObject



26
27
28
# File 'app/models/para/component/crud.rb', line 26

def resources
  namespaced? ? namespaced_resources : model.all
end

#update_with(attributes) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'app/models/para/component/crud.rb', line 38

def update_with(attributes)
  # If no model_type is provided in the configuration file, default to
  # the singular and camelized version of the identifier, allowing to
  # create crud components without setting the :model_type option, when
  # given a conventional name
  attributes[:model_type] ||= identifier.to_s.camelize.singularize if identifier
  attributes[:controller] ||= '/para/admin/crud_resources'

  super
end