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
 97 def array_from_csv(csv, opts = OPTS)
 98   CsvSerializer.csv_call(:parse, csv, process_csv_serializer_opts(opts)).map do |row|
 99     row = row.to_hash
100     row.delete(nil)
101     new(row)
102   end
103 end
freeze() click to toggle source

Freeze csv serializier opts when freezing model class

Calls superclass method
    # File lib/sequel/plugins/csv_serializer.rb
106 def freeze
107   @csv_serializer_opts.freeze.each_value do |v|
108     v.freeze if v.is_a?(Array) || v.is_a?(Hash)
109   end
110 
111   super
112 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
115 def from_csv(csv, opts = OPTS)
116   new.from_csv(csv, opts)
117 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
120 def process_csv_serializer_opts(opts)
121   opts = (csv_serializer_opts || OPTS).merge(opts)
122   opts_cols = opts.delete(:columns)
123   opts_include = opts.delete(:include)
124   opts_except = opts.delete(:except)
125   only = opts.delete(:only) 
126   opts[:headers] ||= Array(only || opts_cols || columns) + Array(opts_include) - Array(opts_except)
127   opts
128 end