Module: HasAttachedTags
- Defined in:
- lib/has_attached_tags.rb,
lib/has_attached_tags/tag.rb,
lib/has_attached_tags/tagging.rb,
lib/has_attached_tags/version.rb,
lib/generators/has_attached_tags/install_generator.rb,
lib/generators/has_attached_tags/migration_generator.rb
Defined Under Namespace
Classes: InstallGenerator, MigrationGenerator, Tag, Tagging
Constant Summary collapse
- TAGGINGS_EXISTS =
lambda { |tag, , taggable| Tagging .where(tag: tag, attachment: , taggable_type: taggable.polymorphic_name) .where(Tagging.arel_table[:taggable_id].eq(taggable.arel_table[:id])) .arel.exists }
- VERSION =
'0.1.1'
Instance Method Summary collapse
- #has_many_tags(attachment, type: default_type_for_attachment(attachment), required: false) ⇒ void
- #has_one_tag(attachment, type: default_type_for_attachment(attachment), required: false) ⇒ void
Instance Method Details
#has_many_tags(attachment, type: default_type_for_attachment(attachment), required: false) ⇒ void
This method returns an undefined value.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/has_attached_tags.rb', line 37 def (, type: (), required: false) # rubocop:disable Naming/PredicateName klass = (, type) has_many(:"#{}_taggings", -> { where(attachment: ) }, as: :taggable, autosave: true, class_name: klass.name, dependent: :destroy, inverse_of: :taggable) has_many(, -> { of_type(type) }, source: :tag, through: :"#{}_taggings") validates(, presence: true) if required () end |
#has_one_tag(attachment, type: default_type_for_attachment(attachment), required: false) ⇒ void
This method returns an undefined value.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/has_attached_tags.rb', line 21 def has_one_tag(, type: (), required: false) # rubocop:disable Naming/PredicateName klass = (, type) has_one(:"#{}_tagging", -> { where(attachment: ) }, as: :taggable, autosave: true, class_name: klass.name, dependent: :destroy, inverse_of: :taggable) has_one(, -> { of_type(type) }, source: :tag, through: :"#{}_tagging") validates(, presence: true) if required () end |