Class: ForestAdminDatasourceToolkit::Collection
Instance Attribute Summary collapse
Instance Method Summary
collapse
#aggregate, #create, #delete, #execute, #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
|
# 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: {}
}
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
60
61
62
63
64
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 60
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
66
67
68
69
70
71
72
73
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 66
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
48
49
50
51
52
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 48
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
54
55
56
57
58
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 54
def add_fields(fields)
fields.each do |name, field|
add_field(name, field)
end
end
|
#add_segments(segments) ⇒ Object
40
41
42
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 40
def add_segments(segments)
schema[:segments] = schema[:segments] | segments
end
|
#enable_count ⇒ Object
24
25
26
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 24
def enable_count
schema[:countable] = true
end
|
#enable_search ⇒ Object
28
29
30
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 28
def enable_search
schema[:searchable] = true
end
|
#fields ⇒ Object
44
45
46
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 44
def fields
schema[:fields]
end
|
#is_countable? ⇒ Boolean
32
33
34
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 32
def is_countable?
schema[:countable]
end
|
#is_searchable? ⇒ Boolean
36
37
38
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 36
def is_searchable?
schema[:searchable]
end
|
#render_chart(_caller, name, _record_id) ⇒ Object
75
76
77
|
# File 'lib/forest_admin_datasource_toolkit/collection.rb', line 75
def render_chart(_caller, name, _record_id)
raise Exceptions::ForestException, "Chart #{name} is not implemented."
end
|