Class: ActiveAdmin::Comment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/active_admin/orm/active_record/comments/comment.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) find_for_resource_in_namespace(resource, namespace)



29
30
31
32
33
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 29

def self.find_for_resource_in_namespace(resource, namespace)
  where resource_type: resource_type(resource),
        resource_id:   resource_id_cast(resource),
        namespace:     namespace.to_s
end

+ (Object) resource_id_cast(record)

Postgres adapters won't compare strings to numbers (issue 34)



25
26
27
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 25

def self.resource_id_cast(record)
  resource_id_type == :string ? record.id.to_s : record.id
end

+ (Object) resource_id_type



35
36
37
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 35

def self.resource_id_type
  columns.detect{ |i| i.name == "resource_id" }.type
end

+ (Object) resource_type(resource)



16
17
18
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 16

def self.resource_type(resource)
  undecorate_resource(resource).class.name.to_s
end

+ (Object) table_name



39
40
41
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 39

def self.table_name
  @table_name ||= ActiveRecord::Migrator.proper_table_name("active_admin_comments")
end

+ (Object) undecorate_resource(resource)



20
21
22
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 20

def self.undecorate_resource(resource)
  ActiveAdmin::ResourceController::Decorators.undecorate_resource(resource)
end

Instance Method Details

- (Object) set_resource_type



43
44
45
# File 'lib/active_admin/orm/active_record/comments/comment.rb', line 43

def set_resource_type
  self.resource_type = self.class.resource_type(resource)
end