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: []) ⇒ Object



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

def acts_as_generic_resource(permitted_attributes: [], overview_attributes: [])
  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)
end