Class: Gutentag::Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gutentag::Tag
- Defined in:
- app/models/gutentag/tag.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.find_by_name(name) ⇒ Object
14 15 16 |
# File 'app/models/gutentag/tag.rb', line 14 def self.find_by_name(name) where(:name => Gutentag.normaliser.call(name)).first end |
.find_or_create(name) ⇒ Object
18 19 20 |
# File 'app/models/gutentag/tag.rb', line 18 def self.find_or_create(name) find_by_name(name) || create(:name => name) end |
.names_for_scope(scope) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/gutentag/tag.rb', line 22 def self.names_for_scope(scope) join_conditions = {:taggable_type => scope.name} if scope.is_a?(ActiveRecord::Relation) return Gutentag::Tag.none unless scope.current_scope.present? join_conditions[:taggable_id] = scope.select(:id) end joins(:taggings).where( Gutentag::Tagging.table_name => join_conditions ).distinct.pluck(:name) end |
Instance Method Details
#name=(value) ⇒ Object
35 36 37 |
# File 'app/models/gutentag/tag.rb', line 35 def name=(value) super(Gutentag.normaliser.call(value)) end |