Class: Ratbug::Table
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name) ⇒ Table
constructor
A new instance of Table.
- #load_enums(model) ⇒ Object
- #load_presence_validators(model) ⇒ Object
- #load_relations ⇒ Object
Methods included from TableExt
Constructor Details
#initialize(name) ⇒ Table
Returns a new instance of Table.
22 23 24 25 |
# File 'lib/ratbug/table.rb', line 22 def initialize(name) @name = name @columns = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *argv, **argh) ⇒ Object (private)
58 59 60 61 62 |
# 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 |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
20 21 22 |
# File 'lib/ratbug/table.rb', line 20 def columns @columns end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/ratbug/table.rb', line 20 def name @name end |
Instance Method Details
#load_enums(model) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# 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) ⇒ Object
46 47 48 49 50 51 52 |
# 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 ⇒ Object
41 42 43 |
# File 'lib/ratbug/table.rb', line 41 def load_relations # TODO end |