Module: Detour::ActsAsFlaggable
- Defined in:
- lib/detour/acts_as_flaggable.rb
Instance Method Summary collapse
-
#acts_as_flaggable(options = {}) ⇒ Object
Sets up ActiveRecord associations for the including class, and includes Flaggable in the class.
Instance Method Details
#acts_as_flaggable(options = {}) ⇒ Object
Sets up ActiveRecord associations for the including class, and includes Flaggable in the class.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/detour/acts_as_flaggable.rb', line 12 def acts_as_flaggable( = {}) Detour::Feature.class_eval <<-EOF has_one :#{table_name}_percentage_flag, class_name: "Detour::PercentageFlag", inverse_of: :feature, dependent: :destroy, conditions: { flaggable_type: "#{self}" } attr_accessible :#{table_name}_percentage_flag_attributes accepts_nested_attributes_for :#{table_name}_percentage_flag, update_only: true, reject_if: proc { |attrs| attrs[:percentage].blank? } has_many :#{table_name}_group_flags, class_name: "Detour::GroupFlag", inverse_of: :feature, dependent: :destroy, conditions: { flaggable_type: "#{self}" } attr_accessible :#{table_name}_group_flags_attributes accepts_nested_attributes_for :#{table_name}_group_flags, allow_destroy: true has_many :#{table_name}_flag_ins, class_name: "Detour::FlagInFlag", inverse_of: :feature, dependent: :destroy, conditions: { flaggable_type: "#{self}" } has_many :#{table_name}_opt_outs, class_name: "Detour::OptOutFlag", inverse_of: :feature, dependent: :destroy, conditions: { flaggable_type: "#{self}" } EOF class_eval do @detour_flaggable_find_by = :id has_many :flag_in_flags, as: :flaggable, class_name: "Detour::FlagInFlag" has_many :opt_out_flags, as: :flaggable, class_name: "Detour::OptOutFlag" has_many :features, through: :flag_in_flags, class_name: "Detour::Feature" if [:find_by] @detour_flaggable_find_by = [:find_by] end def self.detour_flaggable_find_by @detour_flaggable_find_by end extend Detour::Flaggable::ClassMethods include Detour::Flaggable end end |