Module: Pod4::TypeCasting::ClassMethods

Includes:
Metaxing
Defined in:
lib/pod4/typecasting.rb

Instance Method Summary collapse

Methods included from Metaxing

#define_class_method, #metaclass

Instance Method Details

#encodingObject



139
# File 'lib/pod4/typecasting.rb', line 139

def encoding; nil; end

#force_encoding(enc) ⇒ Object

Raises:



134
135
136
137
# File 'lib/pod4/typecasting.rb', line 134

def force_encoding(enc)
  raise Pod4Error, "Bad encoding" unless enc.kind_of? Encoding
  define_class_method(:encoding){enc}
end

#typecast(*args) ⇒ Object

Raises:



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/pod4/typecasting.rb', line 141

def typecast(*args)
  options = args.pop
  raise Pod4Error, "Bad Type" \
    unless options.keys.include?(:use) || TYPES.include?(options[:as])

  raise Pod4Error, "Bad Typecasting" unless options.is_a?(Hash) \
                                         && options.keys.any?{|o| i|as use|.include? o} \
                                         && args.size >= 1

  # Modify self.typecasts to look like: {foo: {as: Date}, bar: {as: Time, strict: true}, ...}
  c = typecasts.dup
  args.each do |f| 
    raise Pod4Error, "Unknown column '#{f}'" unless columns.include?(f)
    c[f] = options
  end

  define_class_method(:typecasts) {c}
end

#typecastsObject



160
# File 'lib/pod4/typecasting.rb', line 160

def typecasts; {}; end