module Sequel::Plugins::CsvSerializer::ClassMethods
Attributes
csv_serializer_opts[R]
The default opts to use when serializing model objects to CSV
Public Instance Methods
array_from_csv(csv, opts = OPTS)
click to toggle source
Attempt to parse an array of instances from the given CSV string
# File lib/sequel/plugins/csv_serializer.rb 83 def array_from_csv(csv, opts = OPTS) 84 CSV.parse(csv, process_csv_serializer_opts(opts)).map do |row| 85 row = row.to_hash 86 row.delete(nil) 87 new(row) 88 end 89 end
freeze()
click to toggle source
Freeze csv serializier opts when freezing model class
Calls superclass method
# File lib/sequel/plugins/csv_serializer.rb 92 def freeze 93 @csv_serializer_opts.freeze.each_value do |v| 94 v.freeze if v.is_a?(Array) || v.is_a?(Hash) 95 end 96 97 super 98 end
from_csv(csv, opts = OPTS)
click to toggle source
Attempt to parse a single instance from the given CSV string
# File lib/sequel/plugins/csv_serializer.rb 101 def from_csv(csv, opts = OPTS) 102 new.from_csv(csv, opts) 103 end
process_csv_serializer_opts(opts)
click to toggle source
Convert the options hash to one that can be passed to CSV.
# File lib/sequel/plugins/csv_serializer.rb 106 def process_csv_serializer_opts(opts) 107 opts = (csv_serializer_opts || OPTS).merge(opts) 108 opts_cols = opts.delete(:columns) 109 opts_include = opts.delete(:include) 110 opts_except = opts.delete(:except) 111 opts[:headers] ||= Array(opts.delete(:only) || opts_cols || columns) + Array(opts_include) - Array(opts_except) 112 opts 113 end