Skip to content

Commit

Permalink
Add owner_tags method to taggable
Browse files Browse the repository at this point in the history
  • Loading branch information
brilyuhns committed Aug 7, 2016
1 parent 8990a39 commit ae673fc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/acts_as_taggable_on/taggable/ownership.rb
Expand Up @@ -27,13 +27,16 @@ def #{tag_type}_from(owner)
end
end

def owner_tags_on(owner, context)
def owner_tags(owner)
if owner.nil?
scope = base_tags.where([%(#{ActsAsTaggableOn::Tagging.table_name}.context = ?), context.to_s])
scope = base_tags
else
scope = base_tags.where([%(#{ActsAsTaggableOn::Tagging.table_name}.context = ? AND
#{ActsAsTaggableOn::Tagging.table_name}.tagger_id = ? AND
#{ActsAsTaggableOn::Tagging.table_name}.tagger_type = ?), context.to_s, owner.id, owner.class.base_class.to_s])
scope = base_tags.where(
"#{ActsAsTaggableOn::Tagging.table_name}" => {
tagger_id: owner.id,
tagger_type: owner.class.base_class.to_s
}
)
end

# when preserving tag order, return tags in created order
Expand All @@ -45,6 +48,10 @@ def owner_tags_on(owner, context)
end
end

def owner_tags_on(owner, context)
scope = owner_tags(owner).where([%(#{ActsAsTaggableOn::Tagging.table_name}.context = ?), context.to_s])
end

def cached_owned_tag_list_on(context)
variable_name = "@owned_#{context}_list"
(instance_variable_defined?(variable_name) && instance_variable_get(variable_name)) || instance_variable_set(variable_name, {})
Expand Down

0 comments on commit ae673fc

Please sign in to comment.