Module: GenericResources::ActsAsGenericResource::ClassMethods

Defined in:
lib/generic_resources/acts_as_generic_resource.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_generic_resource(permitted_attributes: [], overview_attributes: [], deleteable: false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generic_resources/acts_as_generic_resource.rb', line 11

def acts_as_generic_resource(permitted_attributes: [], overview_attributes: [], deleteable: false)
  
  resource_deleteable = true if deleteable == true
  
  if !self.table_exists?
    Rails.logger.warn "Try to add generic resource #{self.name} - table does not exist"
    return false
  end

  if permitted_attributes.empty?
    permitted_attributes = (self.try(:column_names) || []) - ['id', 'created_at', 'updated_at']
  end

  if overview_attributes.empty?
    overview_attributes = permitted_attributes
  end

  GenericResource.register_resource!(self, 
    permitted_attributes: permitted_attributes, overview_attributes: overview_attributes,
    resource_deleteable: resource_deleteable
  )
end