module ActsAsTaggableOnDynamic::DynamicTagContextAttributes::InstanceMethods

Public Instance Methods

dynamic_tag_context_attribute(context) click to toggle source

Returns a text string which returns generates the list attribute given by the context name for taggings

Example:

self.dynamic_tag_context_attribute("skills") => "dynamic_tag_context_skill_list"
# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 15
def dynamic_tag_context_attribute(context)
  "dynamic_tag_context_#{context.singularize}_list"
end
dynamic_tag_context_attribute?(attribute) click to toggle source

Validates if the given attribute is a dynamic context tag

# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 30
def dynamic_tag_context_attribute?(attribute)
  (attribute.to_s.start_with?('dynamic_tag_context_') && attribute.to_s.ends_with?('_list'))
end
dynamic_tag_context_attribute_template() click to toggle source
# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 19
def dynamic_tag_context_attribute_template()
  "dynamic_tag_context_{{context}}_list"
end
dynamic_tag_context_from_attribute(attribute) click to toggle source

Returns the context of a give attributes name

# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 37
def dynamic_tag_context_from_attribute(attribute)
  attribute.to_s.sub('dynamic_tag_context_', '').chomp('_list').pluralize
end
dynamic_tag_context_label_template() click to toggle source
# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 23
def dynamic_tag_context_label_template()
  "{{context}}"
end
mass_assignment_authorizer(role) click to toggle source

Returns the mass assignment authorizer

Calls superclass method
# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 89
def mass_assignment_authorizer(role)
  ActsAsTaggableOnDynamic::DynamicMassAssignmentAuthorizer.new(self, super(role))
end
method_missing(method_name, *args, &block) click to toggle source

Handles all read and write operations to a dynamic tag context

Calls superclass method
# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 61
def method_missing(method_name, *args, &block)

  attribute = method_name.to_s.chomp('=')

  if ( dynamic_tag_context_attribute?(attribute) || tag_list_attribute?(attribute))

    context = dynamic_tag_context_from_attribute(attribute).to_sym

    if (method_name.to_s.ends_with?("="))
      self.write_tag_list_on(context, args.join(',').chomp(','))
    else
      self.tag_list_content_on(context)
    end
  else
    super
  end
end
respond_to?(method_name, include_private = false) click to toggle source

Validates if the requested method a supported method

Calls superclass method
# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 82
def respond_to?(method_name, include_private = false)
  dynamic_tag_context_attribute?(method_name.to_s.chomp("=")) || tag_list_attribute?(method_name.to_s.chomp("=")) || super
end
tag_list_attribute?(attribute) click to toggle source

Validates if the given attribute is a tag list attribute

# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 43
def tag_list_attribute?(attribute)
  attribute.to_s.ends_with?('_list')
end
tag_list_content_on(context) click to toggle source

Returns the contetn of a give tag list

# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 50
def tag_list_content_on(context)
  if (self.is_auto_tag_ownership_enabled?)
    self.owner_tags_on(self.tag_owner, context).map(&:to_s).join(',').chomp(',')
  else
    self.tags_on(context).map(&:to_s).join(',').chomp(',')
  end
end
write_tag_list_on(context, tags) click to toggle source

Handles the write request

# File lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb, line 95
def write_tag_list_on(context, tags)
  if (self.is_auto_tag_ownership_enabled?)
    self.tag_owner.tag(self, :with => tags, :on => context, :skip_save => true)
  else
    self.set_tag_list_on(context, tags)
  end
end