Module: Banyan::Categorizable::ClassMethods
- Defined in:
- lib/banyan/categorizable.rb
Instance Method Summary collapse
-
#acts_as_categorizable(opts = {}) ⇒ Object
Add categories to model.
-
#acts_as_group_categorizable(opts = {}) ⇒ Object
Add category groups to model.
Instance Method Details
#acts_as_categorizable(opts = {}) ⇒ Object
Add categories to model
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/banyan/categorizable.rb', line 12 def acts_as_categorizable(opts = {}) single = !!opts.delete(:single) as = opts.delete(:as) || (self.name.underscore.gsub('/','___') + '_categorizations') if single has_one :categorization, :as => :categorizable, :class_name => "::Banyan::Categorization", :dependent => :destroy has_one :category, opts.merge(:through => :categorization) else has_many :categorizations, :as => :categorizable, :class_name => "::Banyan::Categorization", :dependent => :destroy has_many :categories, opts.merge(:through => :categorizations, :uniq => true) end Banyan::Category.has_many as, :through => :categorizations, :source => :categorizable, :source_type => self.name end |
#acts_as_group_categorizable(opts = {}) ⇒ Object
Add category groups to model
30 31 32 33 34 35 36 37 38 |
# File 'lib/banyan/categorizable.rb', line 30 def acts_as_group_categorizable(opts = {}) single = !!opts.delete(:single) if single has_one :category_group, opts.merge(:as => :group_categorizable, :class_name => "Banyan::CategoryGroup") else has_many :category_groups, opts.merge(:as => :group_categorizable, :class_name => "Banyan::CategoryGroup", :uniq => true) end end |