<commit_before>= Character

This is a partial extraction of the DataMapper Property API with various
modifications. My goal is to provide a common API to define attributes on a
model along with (auto-)validations so all ORMs/ODMs could use it instead of
reinventing the wheel all over again. It would be also suitable for any other
usecase where you need to extend your ruby objects with various attributes that
require typecasting and/or validations.

== Installation

  gem i character

== Usage

  require 'character'

  class User
    include Character

    attribute :name, String
    attribute :age,  Integer
    attribute :bday, DateTime
  end

  user = User.new
  user.name = "Piotr"
  user.name # => "Piotr"

  # that's it for a good start :)

== TODO

* specs
* typecasting
* validations
* ActiveModel compliance
* I18n

== Note on Patches/Pull Requests
<commit_msg>Add more examples to readme<commit_after>= Character

This is a partial extraction of the DataMapper Property API with various
modifications. My goal is to provide a common API to define attributes on a
model along with (auto-)validations so all ORMs/ODMs could use it instead of
reinventing the wheel all over again. It would be also suitable for any other
usecase where you need to extend your ruby objects with various attributes that
require typecasting and/or validations.

== Installation

  gem i character

== Usage

  require 'character'

  class User
    include Character

    attribute :name,     String
    attribute :age,      Integer
    attribute :birthday, DateTime
  end

  user = User.new

  # attribute writer
  user.name = "Piotr"

  # attribute reader
  user.name # => "Piotr"

  # hash of attribute values
  user.attributes # => { :name => "Piotr" }

  # automatic typecasting
  user.age = '28'
  user.age # => 28

  user.birthday = 'November 18th, 1983'
  user.birthday # => #<DateTime: 1983-11-18T00:00:00+00:00 (4891313/2,0/1,2299161)>

  # define your own attribute classes

  module MyApp
    module Attributes
      class JSON < Character::Attributes::Object
        primitive Hash

        def typecast(value, model = nil)
          JSON.parse(value)
        end
      end
    end

    class User
      include Character

      attribute :info, Attributes::JSON
    end
  end

  user = MyApp::User.new

  user.info = '{"email" : "<EMAIL>" }'
  user.info # => {"email"=>"<EMAIL>"}

  # validations coming soon...
== TODO

* specs
* typecasting
* validations
* ActiveModel compliance
* I18n

== Note on Patches/Pull Requests

{'fraction_non_alphanumeric': 0.077500988533017, 'fraction_numerical': 0.01937524713325425, 'mean_word_length': 3.23785594639866, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2516592', 'n_tokens_mistral': 797, 'n_tokens_neox': 723, 'n_words': 294}