<commit_before>= MakeFlaggable

MakeFlaggable is an extension for building a user-centric flagging system for Rails 3 applications.
It currently supports ActiveRecord models.

Special thanks to medihack[https://github.com/medihack/make_flaggable] for providing this awesome gem!

== Installation

add MakeFlaggable to your Gemfile

  gem 'make_flaggable', :git => 'git://github.com/cavneb/make_flaggable.git'

afterwards execute

  bundle install

generate the required migration file

  rails generate make_flaggable

migrate the database

  rake db:migrate

== Usage

  # Specify a model that can be flagged and provide the names of the flags
  class Article < ActiveRecord::Base
    make_flaggable :inappropriate, :favorite
  end

  # Specify a model that can flag another model.
  class User < ActiveRecord::Base
    make_flagger
  end

  # The user can now flag the flaggable.
  # If the user already flagged the flaggable with the :flag_name then an AlreadyFlaggedError is raised.
  user.flag!(article, :flag_name)

  # The method without bang(!) does not raise the AlreadyFlaggedError when the user flags the flaggable more than once.
  # Instead it just returns false and ignores the flagging.
  user.flag(article, :flag_name)

  # The user may unflag an already done flagging.
  # If the user never flagged the flaggable then an NotFlaggedError is raised.
  user.unflag!(article, :flag_name)

  # The method without bang(!) does not raise the NotFlaggedError, but just returns false if the user never flagged
  # the flaggable.
  user.unflag(article, :flag_name)

  # The user can also easily toggle the state of a flag: subsquent calls to toggle_flag will flag/unflag it:
  user.toggle_flag(article, :flag_name) # returns true as the flag has been set
  user.toggle_flag(article, :flag_name) # returns false as the flag has now been removed
  user.toggle_flag(article, :flag_name) # flag set again

  # Get all flaggings of a flaggable.
  article.flaggings

  # Get the flagging with a specified flag.
  article.flaggings.with_flag(:flag_name)
  
  # Get the flagger of the flagging.
  flagging = article.flaggings.with_flag(:flag_name).first
  user = flagging.flagger

  # Returns true if the flagger flagged the flaggable, false otherwise.
  user.flagged?(article, :flag_name)

  # Return true if the flaggable was flagged by the flagger, false otherwise.
  article.flagged_by?(user, :flag_name)

  # Returns true if the article was flagged by any flagger at all, false otherwise.
  article.flagged?(:flag_name)

  # Flaggings can also be accessed by its flagger.
  flagger.flaggings or flagger.flaggings.with_flag(:flag_name)

== Testing

MakeFlaggable uses RSpec for testing and has a rake task for executing the provided specs

  rake spec

or simply

  rake

Copyright © 2010-2011 <NAME> (http://www.medihack.org), released under the MIT license

Modified to use specified flags by <NAME><commit_msg>Add documentation for the available_flags methods.<commit_after>= MakeFlaggable

MakeFlaggable is an extension for building a user-centric flagging system for Rails 3 applications.
It currently supports ActiveRecord models.

Special thanks to medihack[https://github.com/medihack/make_flaggable] for providing this awesome gem!

== Installation

add MakeFlaggable to your Gemfile

  gem 'make_flaggable', :git => 'git://github.com/cavneb/make_flaggable.git'

afterwards execute

  bundle install

generate the required migration file

  rails generate make_flaggable

migrate the database

  rake db:migrate

== Usage

  # Specify a model that can be flagged and provide the names of the flags
  class Article < ActiveRecord::Base
    make_flaggable :inappropriate, :favorite
  end

  # Specify a model that can flag another model.
  class User < ActiveRecord::Base
    make_flagger
  end

  # The user can now flag the flaggable.
  # If the user already flagged the flaggable with the :flag_name then an AlreadyFlaggedError is raised.
  user.flag!(article, :flag_name)

  # The method without bang(!) does not raise the AlreadyFlaggedError when the user flags the flaggable more than once.
  # Instead it just returns false and ignores the flagging.
  user.flag(article, :flag_name)

  # The user may unflag an already done flagging.
  # If the user never flagged the flaggable then an NotFlaggedError is raised.
  user.unflag!(article, :flag_name)

  # The method without bang(!) does not raise the NotFlaggedError, but just returns false if the user never flagged
  # the flaggable.
  user.unflag(article, :flag_name)

  # The user can also easily toggle the state of a flag: subsquent calls to toggle_flag will flag/unflag it:
  user.toggle_flag(article, :flag_name) # returns true as the flag has been set
  user.toggle_flag(article, :flag_name) # returns false as the flag has now been removed
  user.toggle_flag(article, :flag_name) # flag set again

  # Get all flaggings of a flaggable.
  article.flaggings

  # Get the flagging with a specified flag.
  article.flaggings.with_flag(:flag_name)

  # Get the flagger of the flagging.
  flagging = article.flaggings.with_flag(:flag_name).first
  user = flagging.flagger

  # Returns true if the flagger flagged the flaggable, false otherwise.
  user.flagged?(article, :flag_name)

  # Return true if the flaggable was flagged by the flagger, false otherwise.
  article.flagged_by?(user, :flag_name)

  # Returns true if the article was flagged by any flagger at all, false otherwise.
  article.flagged?(:flag_name)

  # Flaggings can also be accessed by its flagger.
  flagger.flaggings or flagger.flaggings.with_flag(:flag_name)

  # Get the available flags for a flaggable
  article.available_flags

  # Get the available flags for a flaggable class
  Article.available_flags

== Testing

MakeFlaggable uses RSpec for testing and has a rake task for executing the provided specs

  rake spec

or simply

  rake

Copyright © 2010-2011 <NAME> (http://www.medihack.org), released under the MIT license

Modified to use specified flags by <NAME>
{'fraction_non_alphanumeric': 0.0626766417290108, 'fraction_numerical': 0.0029925187032418953, 'mean_word_length': 4.204152249134948, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1813689', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1761, 'n_words': 717}