Sha256: 917a6694f4f5358192751fa65b539e46dd746220108bc3ed0ebf41bfa57dc819
Contents?: true
Size: 1.4 KB
Versions: 31
Compression:
Stored size: 1.4 KB
Contents
module ForestAdminDatasourceToolkit class Collection < Components::Contracts::CollectionContract attr_reader :actions, :datasource, :name, :schema, :native_driver 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 def enable_count schema[:countable] = true end def is_countable? schema[:countable] end def is_searchable? schema[:searchable] end def fields schema[:fields] end def add_field(name, field) raise Exceptions::ForestException, "Field #{name} already defined in collection" if @schema[:fields].key?(name) schema[:fields][name] = field end def add_fields(fields) fields.each do |name, field| add_field(name, field) end end def add_action(name, action) raise Exceptions::ForestException, "Action #{name} already defined in collection" if @schema[:actions].key?(name) schema[:actions][name] = action end def render_chart(_caller, name, _record_id) raise Exceptions::ForestException, "Chart #{name} is not implemented." end end end
Version data entries
31 entries across 31 versions & 1 rubygems