module Sequel::Plugins::CsvSerializer::ClassMethods

  1. lib/sequel/plugins/csv_serializer.rb

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)

Attempt to parse an array of instances from the given CSV string

[show source]
    # File lib/sequel/plugins/csv_serializer.rb
 99 def array_from_csv(csv, opts = OPTS)
100   CsvSerializer.csv_call(:parse, csv, process_csv_serializer_opts(opts)).map do |row|
101     row = row.to_hash
102     row.delete(nil)
103     new(row)
104   end
105 end
freeze()

Freeze csv serializier opts when freezing model class

[show source]
    # File lib/sequel/plugins/csv_serializer.rb
108 def freeze
109   @csv_serializer_opts.freeze.each_value do |v|
110     v.freeze if v.is_a?(Array) || v.is_a?(Hash)
111   end
112 
113   super
114 end
from_csv(csv, opts = OPTS)

Attempt to parse a single instance from the given CSV string

[show source]
    # File lib/sequel/plugins/csv_serializer.rb
117 def from_csv(csv, opts = OPTS)
118   new.from_csv(csv, opts)
119 end
process_csv_serializer_opts(opts)

Convert the options hash to one that can be passed to CSV.

[show source]
    # File lib/sequel/plugins/csv_serializer.rb
122 def process_csv_serializer_opts(opts)
123   opts = (csv_serializer_opts || OPTS).merge(opts)
124   opts_cols = opts.delete(:columns)
125   opts_include = opts.delete(:include)
126   opts_except = opts.delete(:except)
127   only = opts.delete(:only) 
128   opts[:headers] ||= Array(only || opts_cols || columns) + Array(opts_include) - Array(opts_except)
129   opts
130 end