class Ratbug::Table
Attributes
columns[RW]
name[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/ratbug/table.rb, line 22 def initialize(name) @name = name @columns = {} end
Public Instance Methods
load_enums(model)
click to toggle source
@param [ApplicationRecord] model
# File lib/ratbug/table.rb, line 28 def load_enums(model) model.defined_enums.each do |column_name, v| if v.is_a?(Hash) enum_values = v elsif v.is_a?(Array) enum_values = v.map.with_index(0) { |r, i| [r, i] }.to_h else fail "#{model.name} enum #{column_name.pluralize} is not valid" end columns[column_name.to_sym]&.set_enums(enum_values) end end
load_presence_validators(model)
click to toggle source
@param [ApplicationRecord] model
# File lib/ratbug/table.rb, line 46 def load_presence_validators(model) model.validators.filter { |r| r.is_a?(ActiveRecord::Validations::PresenceValidator) }.each do |validator| validator.attributes.each do |column_name_sym| columns[column_name_sym]&.set_nullable(false) end end end
load_relations()
click to toggle source
# File lib/ratbug/table.rb, line 41 def load_relations # TODO end
Private Instance Methods
method_missing(symbol, *argv, **argh)
click to toggle source
# File lib/ratbug/table.rb, line 58 def method_missing(symbol, *argv, **argh) puts "t.#{symbol.to_s} has no correspond implementation currenlty" p argv p argh end