Module: ActsAsTaggableOnDynamic::DynamicTagContextAttributes::InstanceMethods
- Defined in:
- lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb
Instance Method Summary collapse
-
#dynamic_tag_context_attribute(context) ⇒ Object
Returns a text string which returns generates the list attribute given by the context name for taggings.
-
#dynamic_tag_context_attribute?(attribute) ⇒ Boolean
Validates if the given attribute is a dynamic context tag.
- #dynamic_tag_context_attribute_template ⇒ Object
-
#dynamic_tag_context_from_attribute(attribute) ⇒ Object
Returns the context of a give attributes name.
- #dynamic_tag_context_label_template ⇒ Object
-
#mass_assignment_authorizer(role) ⇒ Object
Returns the mass assignment authorizer.
-
#method_missing(method_name, *args, &block) ⇒ Object
Handles all read and write operations to a dynamic tag context.
-
#respond_to?(method_name, include_private = false) ⇒ Boolean
Validates if the requested method a supported method.
-
#tag_list_attribute?(attribute) ⇒ Boolean
Validates if the given attribute is a tag list attribute.
-
#tag_list_content_on(context) ⇒ Object
Returns the contetn of a give tag list.
-
#write_tag_list_on(context, tags) ⇒ Object
Handles the write request.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Handles all read and write operations to a dynamic tag context
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# 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 |
Instance Method Details
#dynamic_tag_context_attribute(context) ⇒ Object
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"
15 16 17 |
# 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) ⇒ Boolean
Validates if the given attribute is a dynamic context tag
30 31 32 |
# 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 ⇒ Object
19 20 21 |
# 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) ⇒ Object
Returns the context of a give attributes name
37 38 39 |
# 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 ⇒ Object
23 24 25 |
# 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) ⇒ Object
Returns the mass assignment authorizer
89 90 91 |
# File 'lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb', line 89 def (role) ActsAsTaggableOnDynamic::DynamicMassAssignmentAuthorizer.new(self, super(role)) end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
Validates if the requested method a supported method
82 83 84 |
# 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) ⇒ Boolean
Validates if the given attribute is a tag list attribute
43 44 45 |
# 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) ⇒ Object
Returns the contetn of a give tag list
50 51 52 53 54 55 56 |
# 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.(self.tag_owner, context).map(&:to_s).join(',').chomp(',') else self.(context).map(&:to_s).join(',').chomp(',') end end |
#write_tag_list_on(context, tags) ⇒ Object
Handles the write request
95 96 97 98 99 100 101 |
# File 'lib/acts_as_taggable_on_dynamic/dynamic_tag_context_attributes.rb', line 95 def write_tag_list_on(context, ) if (self.is_auto_tag_ownership_enabled?) self.tag_owner.tag(self, :with => , :on => context, :skip_save => true) else self.set_tag_list_on(context, ) end end |