lib/acb/base.rb in acb-0.1.5 vs lib/acb/base.rb in acb-0.2.0
- old
+ new
@@ -2,37 +2,35 @@
module Acb
module Base
extend ActiveSupport::Concern
- class_methods do
- def columns
- @columns ||= Columns.new
- end
-
- def add_column(name:, **options)
- columns.push(name, **options)
- end
+ module ClassMethods
+ include Columns
end
def to_csv(**options)
CSV.generate(**options) do |csv|
- csv << self.class.columns.header
+ csv << self.class.header
data.each do |row|
- csv << get_data_from(row)
+ csv << summarize(row)
end
end
end
alias content_string to_csv
+ def load_from(relations)
+ @data = relations
+ end
+
private
def data
@data = @data.preload(relations) if respond_to?(:relations)
@data.find_each
end
- def get_data_from(row)
- self.class.columns.get_data(row)
+ def summarize(row)
+ self.class.summarize(row)
end
end
end