11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# 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
begin
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
)
rescue ActiveRecord::NoDatabaseError => e
puts "SKIPPING acts_as_generic_resource on #{self.name} - NoDatabase"
end
end
|