module GenericResources::ActsAsGenericResource::ClassMethods

Public Instance Methods

acts_as_generic_resource(permitted_attributes: [], overview_attributes: [], deleteable: false) click to toggle source
# 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