Class: ForestAdminDatasourceToolkit::Collection
Instance Attribute Summary collapse
Instance Method Summary
collapse
#aggregate, #create, #delete, #execute, #form, #get_form, #list, #update
Constructor Details
#initialize(datasource, name, native_driver = nil) ⇒ Collection
Returns a new instance of Collection.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 9
def initialize(datasource, name, native_driver = nil)
super()
@datasource = datasource
@name = name
@native_driver = native_driver
@schema = {
fields: {},
countable: false,
searchable: false,
charts: [],
segments: [],
actions: {},
aggregation_capabilities: {
support_groups: true,
supported_date_operations: %w[Year Quarter Month Week Day]
}
}
end
|
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
3
4
5
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 3
def actions
@actions
end
|
#datasource ⇒ Object
Returns the value of attribute datasource.
3
4
5
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 3
def datasource
@datasource
end
|
#name ⇒ Object
Returns the value of attribute name.
3
4
5
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 3
def name
@name
end
|
#native_driver ⇒ Object
Returns the value of attribute native_driver.
3
4
5
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 3
def native_driver
@native_driver
end
|
#schema ⇒ Object
Returns the value of attribute schema.
3
4
5
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 3
def schema
@schema
end
|
Instance Method Details
#add_action(name, action) ⇒ Object
64
65
66
67
68
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 64
def add_action(name, action)
raise Exceptions::ForestException, "Action #{name} already defined in collection" if @schema[:actions].key?(name)
schema[:actions][name] = action
end
|
#add_chart(name) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 70
def add_chart(name)
if @schema[:charts].include?(name)
raise Exceptions::ForestException,
"Chart #{name} already defined in collection"
end
schema[:charts] << name
end
|
#add_field(name, field) ⇒ Object
52
53
54
55
56
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 52
def add_field(name, field)
raise Exceptions::ForestException, "Field #{name} already defined in collection" if @schema[:fields].key?(name)
schema[:fields][name] = field
end
|
#add_fields(fields) ⇒ Object
58
59
60
61
62
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 58
def add_fields(fields)
fields.each do |name, field|
add_field(name, field)
end
end
|
#add_segments(segments) ⇒ Object
44
45
46
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 44
def add_segments(segments)
schema[:segments] = schema[:segments] | segments
end
|
#enable_count ⇒ Object
28
29
30
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 28
def enable_count
schema[:countable] = true
end
|
#enable_search ⇒ Object
32
33
34
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 32
def enable_search
schema[:searchable] = true
end
|
#fields ⇒ Object
48
49
50
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 48
def fields
schema[:fields]
end
|
#is_countable? ⇒ Boolean
36
37
38
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 36
def is_countable?
schema[:countable]
end
|
#is_searchable? ⇒ Boolean
40
41
42
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 40
def is_searchable?
schema[:searchable]
end
|
#render_chart(_caller, name, _record_id, _parameters = {}) ⇒ Object
79
80
81
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 79
def render_chart(_caller, name, _record_id, _parameters = {})
raise Exceptions::ForestException, "Chart #{name} is not implemented."
end
|