class Polytag::Concerns::Taggable::ModelHelpers

Public Class Methods

new(owner) click to toggle source
# File lib/polytag/concerns/taggable/model_helpers.rb, line 5
def initialize(owner)
  @owner = owner
end

Public Instance Methods

add(tag, args = {})
Alias for: new
create(tag, args = {})
Alias for: new
del(tag, args = {}) click to toggle source
# File lib/polytag/concerns/taggable/model_helpers.rb, line 19
def del(tag, args = {})
  return false unless exist?(tag, args)
  tag = ::Polytag.get tag: tag,
    tag_group: args[:tag_group],
    owner: args[:tag_group_owner],
    tagged: @owner,
    foc: :first

  tag.destroy
  true
end
Also aliased as: delete, remove, destroy
delete(tag, args = {})
Alias for: del
destroy(tag, args = {})
Alias for: del
exist?(tag, args = {}) click to toggle source
# File lib/polytag/concerns/taggable/model_helpers.rb, line 44
def exist?(tag, args = {})
  tag = ::Polytag.get tag: tag,
    tag_group: args[:tag_group],
    owner: args[:tag_group_owner],
    tagged: @owner,
    foc: :first

  # Return the result
  tag.is_a?(::Polytag::Connection)
rescue ActiveRecord::RecordNotFound
  false
end
Also aliased as: has_tag?
find(tag, args = {})
Alias for: get
get(tag, args = {}) click to toggle source
# File lib/polytag/concerns/taggable/model_helpers.rb, line 34
def get(tag, args = {})
  return false unless exist?(tag, args)
  ::Polytag.get tag: tag,
    tag_group: args[:tag_group],
    owner: args[:tag_group_owner],
    tagged: @owner,
    foc: :first
end
Also aliased as: find
has_tag?(tag, args = {})
Alias for: exist?
new(tag, args = {}) click to toggle source
# File lib/polytag/concerns/taggable/model_helpers.rb, line 9
def new(tag, args = {})
  ::Polytag.get tag: tag,
    foc: :first_or_create,
    tag_group: args[:tag_group],
    owner: args[:tag_group_owner],
    tagged: @owner
end
Also aliased as: add, create
remove(tag, args = {})
Alias for: del