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



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

def encoding; nil; end

#force_encoding(enc) ⇒ Object

Raises:



147
148
149
150
# File 'lib/pod4/typecasting.rb', line 147

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

#typecast(*args) ⇒ Object

Raises:



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/pod4/typecasting.rb', line 154

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



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

def typecasts; {}; end