Sha256: b5db464924e16f749b2940380cd48c127639f340274240df29f78f08b29edb3e

Contents?: true

Size: 1.14 KB

Versions: 26

Compression:

Stored size: 1.14 KB

Contents

class Boolean
  # to have a boolean type for attributes
end

module Arrest

  CONVERTER = {}

  def add_converter key, converter
    CONVERTER[key] = converter
  end

  class Converter
    class << self
      attr_reader :clazz

      def convert value
        if value.is_a?(self.clazz)
          value
        else
          self.parse value
        end
      end

      def mk_json obj
        obj
      end

      def target clazz
        @clazz = clazz
        CONVERTER[clazz] = self
      end
    end
  end

  class IdentConv < Converter
    def self.convert value
      value
    end
  end

  class StringConv < IdentConv
    target String
  end

  class BooleanConv < IdentConv
    target Boolean
  end

  class IntegerConv < IdentConv
    target Integer
  end

  class FloatConv < IdentConv
    target Float
  end

  class ArrayConv < IdentConv
    target Array

    def self.mk_json value
      if value == nil || value == ""
        return nil
      end
      value
    end
  end

  class TimeConv < Converter
    target Time

    def self.parse value
      Time.parse(value)
    end

    def self.mk_json time
      time.strftime "%FT%T%z"
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
arrest-0.0.91 lib/arrest/attributes/converter.rb
arrest-0.0.90 lib/arrest/attributes/converter.rb
arrest-0.0.89 lib/arrest/attributes/converter.rb
arrest-0.0.88 lib/arrest/attributes/converter.rb
arrest-0.0.87 lib/arrest/attributes/converter.rb
arrest-0.0.86 lib/arrest/attributes/converter.rb
arrest-0.0.85 lib/arrest/attributes/converter.rb
arrest-0.0.84 lib/arrest/attributes/converter.rb
arrest-0.0.83.crud lib/arrest/attributes/converter.rb
arrest-0.0.83.1 lib/arrest/attributes/converter.rb
arrest-0.0.83 lib/arrest/attributes/converter.rb
arrest-0.0.82 lib/arrest/attributes/converter.rb
arrest-0.0.80 lib/arrest/attributes/converter.rb
arrest-0.0.79 lib/arrest/attributes/converter.rb
arrest-0.0.78 lib/arrest/attributes/converter.rb
arrest-0.0.77 lib/arrest/attributes/converter.rb
arrest-0.0.76 lib/arrest/attributes/converter.rb
arrest-0.0.75 lib/arrest/attributes/converter.rb
arrest-0.0.74 lib/arrest/attributes/converter.rb
arrest-0.0.73 lib/arrest/attributes/converter.rb