Class: DataTable

Inherits:
Object
  • Object
show all
Defined in:
app/models/data_table.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, columns, options = {}) ⇒ DataTable

Returns a new instance of DataTable.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/data_table.rb', line 13

def initialize(name, columns, options = {})
  @name = name
  @columns = columns
  @new_record_strategy = options[:new_record_strategy] || :insert
  options[:allowed_controller_actions] ||= options[:controller_actions]
  if options[:allowed_controller_actions].present?
    @allowed_controller_actions = Array(options[:allowed_controller_actions]).map(&:to_sym)
  else
    @allowed_controller_actions = legacy_controller_actions
  end
  self.class.all[name.to_sym] = self
end

Instance Attribute Details

#allowed_controller_actionsObject (readonly) Also known as: controller_actions

Returns the value of attribute allowed_controller_actions.



10
11
12
# File 'app/models/data_table.rb', line 10

def allowed_controller_actions
  @allowed_controller_actions
end

#columnsObject (readonly)

Returns the value of attribute columns.



10
11
12
# File 'app/models/data_table.rb', line 10

def columns
  @columns
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'app/models/data_table.rb', line 10

def name
  @name
end

#new_record_strategyObject (readonly)

Returns the value of attribute new_record_strategy.



10
11
12
# File 'app/models/data_table.rb', line 10

def new_record_strategy
  @new_record_strategy
end

Class Method Details

.allObject



2
3
4
# File 'app/models/data_table.rb', line 2

def self.all
  @all ||= {}
end

.find_by_name(name) ⇒ Object



6
7
8
# File 'app/models/data_table.rb', line 6

def self.find_by_name(name)
  all[name.to_sym]
end

Instance Method Details

#class_nameObject



26
27
28
# File 'app/models/data_table.rb', line 26

def class_name
  name.to_s.classify
end

#classifyObject



34
35
36
37
38
39
# File 'app/models/data_table.rb', line 34

def classify
  return Gatherable.const_get(class_name) if Gatherable.const_defined?(class_name)
  klass = Gatherable.const_set(class_name, Class.new(ActiveRecord::Base))
  klass.table_name = Gatherable.config.schema_name + '.' + name.to_s.pluralize
  klass
end

#controller_nameObject



30
31
32
# File 'app/models/data_table.rb', line 30

def controller_name
  "#{class_name.pluralize}Controller"
end

#controllerifyObject



41
42
43
44
# File 'app/models/data_table.rb', line 41

def controllerify
  return Gatherable.const_get(controller_name) if Gatherable.const_defined?(controller_name)
  Gatherable.const_set(controller_name, Class.new(Gatherable::ApplicationController))
end