<commit_before>= ActsAsDigestedOn {<img src="https://secure.travis-ci.org/milk1000cc/acts_as_digested_on.png?branch=master" alt="Build Status" />}[http://travis-ci.org/milk1000cc/acts_as_digested_on]

acts_as_digested_on is a gem for Rails 3.

This sets the digested value before validation and validates uniqueness of the digested value.

If you use this gem for Rails 2, see rails-2 branch.

== Install

  sudo gem install acts_as_digested_on

== Usage

  # db/migrate/20090706000000_create_articles.rb
  class CreateArticles < ActiveRecord::Migration
    def self.up
      create_table :articles do |t|
        t.text :url       # any type is ok
        t.string :digest  # this is sha-1 hex digest field of url value
        ...
      end

      add_index :articles, :digest, :unique => true  # you can add index on digest field
    end

    def self.down
      drop_table :articles
    end
  end

  # app/models/article.rb
  class Article < ActiveRecord::Base
    acts_as_digested_on :url  # please add this
    ...
  end

  # this means
  class Article < ActiveRecord::Base
    validates_uniqueness_of :digest
    before_validation :set_digest

    def generate_digest
      Digest::SHA1.hexdigest "--#{ url.to_s }--"
    end

    private
    def set_digest
      self.digest = generate_digest
    end
    ...
  end

== Examples

  acts_as_digested_on :url, :unique => false

  acts_as_digested_on :url, :digest_column => :url_digest

  acts_as_digested_on [:url, :salt]

  acts_as_digested_on :url, :scope => :site_id

  Article.new(:url => 'http://example.com').generate_digest

== Copyright

Copyright (c) 2009-2012 milk1000cc, released under the MIT license

milk1000cc <mailto:<EMAIL>><commit_msg>Update README.rdoc (Rails 4 support)<commit_after>= ActsAsDigestedOn {<img src="https://secure.travis-ci.org/milk1000cc/acts_as_digested_on.png?branch=master" alt="Build Status" />}[http://travis-ci.org/milk1000cc/acts_as_digested_on]

acts_as_digested_on is a gem for Rails 3 and Rails 4.

This sets the digested value before validation and validates uniqueness of the digested value.

If you use this gem for Rails 2, see rails-2 branch.

== Install

  sudo gem install acts_as_digested_on

== Usage

  # db/migrate/20090706000000_create_articles.rb
  class CreateArticles < ActiveRecord::Migration
    def self.up
      create_table :articles do |t|
        t.text :url       # any type is ok
        t.string :digest  # this is sha-1 hex digest field of url value
        ...
      end

      add_index :articles, :digest, :unique => true  # you can add index on digest field
    end

    def self.down
      drop_table :articles
    end
  end

  # app/models/article.rb
  class Article < ActiveRecord::Base
    acts_as_digested_on :url  # please add this
    ...
  end

  # this means
  class Article < ActiveRecord::Base
    validates_uniqueness_of :digest
    before_validation :set_digest

    def generate_digest
      Digest::SHA1.hexdigest "--#{ url.to_s }--"
    end

    private
    def set_digest
      self.digest = generate_digest
    end
    ...
  end

== Examples

  acts_as_digested_on :url, :unique => false

  acts_as_digested_on :url, :digest_column => :url_digest

  acts_as_digested_on [:url, :salt]

  acts_as_digested_on :url, :scope => :site_id

  Article.new(:url => 'http://example.<EMAIL>').generate_digest

== Copyright

Copyright (c) 2009-2013 milk1000cc, released under the MIT license

milk1000cc <mailto:<EMAIL>>
{'fraction_non_alphanumeric': 0.0934876989869754, 'fraction_numerical': 0.025470332850940667, 'mean_word_length': 3.209500609013398, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 20, 'https://': 2, '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': '2697107', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1123, 'n_words': 312}