class Crudboy::Definition
Attributes
model[RW]
model_name[RW]
table_name[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/crudboy/definition.rb, line 64 def initialize(options) @@options = options @table_name = @@options[:table_name] @model_name = @@options[:model_name] ActiveRecord::Base.connection.tap do |conn| Object.const_set('CrudboyModel', Class.new(ActiveRecord::Base) do include ::Crudboy::Concerns::TableDataDefinition self.abstract_class = true end) raise "Table not exist: #{@table_name}" unless conn.tables.include?(@table_name) table_comment = conn.table_comment(@table_name) conn.primary_key(@table_name).tap do |pkey| Class.new(::CrudboyModel) do include Crudboy::Extension self.table_name = options[:table_name] if pkey.is_a?(Array) self.primary_keys = pkey else self.primary_key = pkey end self.inheritance_column = nil self.default_timezone = :local if options[:created_at].present? define_singleton_method :timestamp_attributes_for_create do options[:created_at] end end if options[:updated_at].present? define_singleton_method :timestamp_attributes_for_update do options[:updated_at] end end end.tap do |clazz| Object.const_set(@model_name, clazz).tap do |const| @model = Model.new(const, @table_name, table_comment) end end end end end
Public Instance Methods
a()
click to toggle source
# File lib/crudboy/definition.rb, line 117 def a to_a end
t(*attrs, **options)
click to toggle source
# File lib/crudboy/definition.rb, line 109 def t(*attrs, **options) records.t(*attrs, **options) end
v()
click to toggle source
# File lib/crudboy/definition.rb, line 113 def v records.v end