Module: ActsAsTaggable::HelperMethods
- Defined in:
- lib/acts_as_taggable/acts_as_taggable.rb
Class Method Summary collapse
-
.current_tag_scope ⇒ Object
Returns the current tag scope, e.g.
-
.filter_tags_by_current_tag_scope(tags) ⇒ Object
Filters an array of tags by the current tag scope.
- .scope_class_methods(metaclass, tag_type) ⇒ Object
- .scope_instance_methods(klass, tag_type) ⇒ Object
- .scope_tag_method(context, tag_type, method_name, scoped_method_name) ⇒ Object
- .scoped_association_assignment_name ⇒ Object
- .scoped_association_name ⇒ Object
Class Method Details
.current_tag_scope ⇒ Object
Returns the current tag scope, e.g. :tag_type => ‘material’
199 200 201 |
# File 'lib/acts_as_taggable/acts_as_taggable.rb', line 199 def self.current_tag_scope Tag.current_scope.where_values_hash if Tag.current_scope end |
.filter_tags_by_current_tag_scope(tags) ⇒ Object
Filters an array of tags by the current tag scope
181 182 183 184 185 186 187 188 |
# File 'lib/acts_as_taggable/acts_as_taggable.rb', line 181 def self.() return unless current_tag_scope .select do |tag| current_tag_scope.all? do |attribute, value| tag[attribute].to_s == value.to_s end end end |
.scope_class_methods(metaclass, tag_type) ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/acts_as_taggable/acts_as_taggable.rb', line 152 def self.scope_class_methods(, tag_type) scope_tag_method(, tag_type, :create_tag, "create_#{tag_type}_tag") scope_tag_method(, tag_type, :find_tags, "find_#{tag_type}_tags") scope_tag_method(, tag_type, :tagged_with_any, "tagged_with_any_#{tag_type}") scope_tag_method(, tag_type, :tagged_with_all, "tagged_with_all_#{tag_type.to_s.pluralize}") scope_tag_method(, tag_type, :tags, "#{tag_type}_tags") scope_tag_method(, tag_type, :tag_names, "#{tag_type}_tag_names") scope_tag_method(, tag_type, :applied_tags, "applied_#{tag_type}_tags") scope_tag_method(, tag_type, :applied_tag_names, "applied_#{tag_type}_tag_names") end |
.scope_instance_methods(klass, tag_type) ⇒ Object
163 164 165 166 167 168 169 170 |
# File 'lib/acts_as_taggable/acts_as_taggable.rb', line 163 def self.scope_instance_methods(klass, tag_type) scope_tag_method(klass, tag_type, :tag_names, "#{tag_type}_tag_names") scope_tag_method(klass, tag_type, :tag_names=, "#{tag_type}_tag_names=") scope_tag_method(klass, tag_type, :tag_string, "#{tag_type}_tag_string") scope_tag_method(klass, tag_type, :tag_string=, "#{tag_type}_tag_string=") scope_tag_method(klass, tag_type, :tag_with, "tag_with_#{tag_type}") scope_tag_method(klass, tag_type, :untag_with, "untag_with_#{tag_type}") end |
.scope_tag_method(context, tag_type, method_name, scoped_method_name) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/acts_as_taggable/acts_as_taggable.rb', line 172 def self.scope_tag_method(context, tag_type, method_name, scoped_method_name) context.send :define_method, scoped_method_name do |*args| Tag.where(:tag_type => tag_type).scoping do send(method_name, *args) end end end |
.scoped_association_assignment_name ⇒ Object
194 195 196 |
# File 'lib/acts_as_taggable/acts_as_taggable.rb', line 194 def self.scoped_association_assignment_name current_tag_scope ? "#{current_tag_scope['tag_type']}_tags=" : "tags=" end |
.scoped_association_name ⇒ Object
190 191 192 |
# File 'lib/acts_as_taggable/acts_as_taggable.rb', line 190 def self.scoped_association_name current_tag_scope ? "#{current_tag_scope['tag_type']}_tags" : "tags" end |