Sha256: 17b5d96d21db069860340978dab490a86a57824da5ba1287c74dc58c1be1c3c0

Contents?: true

Size: 896 Bytes

Versions: 5

Compression:

Stored size: 896 Bytes

Contents

# encoding: UTF-8

module Spontaneous
  module FieldTypes

    autoload :Field, "spontaneous/field_types/field"

    @@type_map = {}

    def self.register(klass, *labels)
      labels.each do |label|
        @@type_map[label.to_sym] = klass
      end
    end

    def self.[](label)
      @@type_map[label.to_sym] || StringField
    end

    def self.serialize_field(field)
      [field.schema_id.to_s, field.version, field.unprocessed_value, field.processed_values]
    end

    def self.deserialize_field(serialized_field)
      {
        :id => serialized_field[0],
        :version => serialized_field[1],
        :unprocessed_value => serialized_field[2],
        :processed_values => serialized_field[3]
      }
    end

  end
end

[:string, :long_string, :file, :image, :date, :markdown, :location, :webvideo, :select].each do |type|
  require "spontaneous/field_types/#{type}_field"
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha7 lib/spontaneous/field_types.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/field_types.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/field_types.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/field_types.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/field_types.rb