Skip to content

Commit

Permalink
Merge pull request medihack#5 from acmetech/master
Browse files Browse the repository at this point in the history
Add available_flags as a class method
  • Loading branch information
Eric Berry committed Mar 18, 2012
2 parents 6ed39cd + a37c16c commit 8782052
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ migrate the database

# 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
Expand All @@ -78,6 +78,12 @@ migrate the database
# 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
Expand Down
6 changes: 5 additions & 1 deletion lib/make_flaggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def flagger?
# end
def make_flaggable(*flags)
raise MakeFlaggable::Exceptions::MissingFlagsError.new if flags.empty?
define_method(:available_flags) { flags.map(&:to_sym) }
@flags = flags.map!(&:to_sym)
# Add available_flags as an instance method
define_method(:available_flags) { flags }
# Add available_flags as a class method
instance_eval { def available_flags; @flags; end }
include Flaggable
end

Expand Down

0 comments on commit 8782052

Please sign in to comment.