/typed_accessors

A rails plugin that enforces attribute accessors as a prespecified type

Primary LanguageRubyMIT LicenseMIT

= Overview

Typed accessors creates a set of accessors with a predefined typed.
Often when dealing with webservices all the data comes back as
strings, but you really want to be working with these things as
numbers or dates.  Manually converting them is duplication, and can be
error prone.

== Example

  class Foo
    float_accessor :float
    date_accessor :date
  end

  >> f = Foo.new
  => #<Foo:0xb7a3dd44>
  >> f.float = "1.4"
  => "1.4"
  >> f.float
  => 1.4
  >> f.float = "1"
  => "1"
  >> f.float
  => 1.0
  >> f.date = "2009-10-30"
  => "2009-10-30"
  >> f.date
  => #<Date: 4910269/2,0,2299161>
  >> f.date.to_s
  => "2009-10-30"

== Installation

First install the gem

  gem install typed_accesors

Then include it in your environment

  require "typed_accessors"

== Authors

Creator: Pat Ladd
Packager: Sean Dague

== License

This is released under an MIT license, see COPYING for full details.