/
base.rb
45 lines (36 loc) · 1.08 KB
/
base.rb
1
2
3
4
5
6
7
8
9
10
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
38
39
40
41
42
43
44
45
module Administrate
module Page
class Base
def initialize(dashboard, options = {})
@dashboard = dashboard
@options = options
end
def resource_name
@resource_name ||=
dashboard.class.to_s.scan(/(.+)Dashboard/).first.first.underscore
end
def resource_path
@resource_path ||= resource_name.tr("/", "_")
end
def collection_includes
dashboard.try(:collection_includes) || []
end
def item_includes
dashboard.try(:item_includes) || []
end
def item_associations
dashboard.try(:item_associations) || []
end
private
def attribute_field(dashboard, resource, attribute_name, page)
value = get_attribute_value(resource, attribute_name)
field = dashboard.attribute_type_for(attribute_name)
field.new(attribute_name, value, page, resource: resource)
end
def get_attribute_value(resource, attribute_name)
resource.public_send(attribute_name)
end
attr_reader :dashboard, :options
end
end
end