Class: Polytag::Concerns::Taggable::ModelHelpers
- Inherits:
-
Object
- Object
- Polytag::Concerns::Taggable::ModelHelpers
- Defined in:
- lib/polytag/concerns/taggable/model_helpers.rb
Instance Method Summary collapse
- #del(tag, args = {}) ⇒ Object (also: #delete, #remove, #destroy)
- #exist?(tag, args = {}) ⇒ Boolean (also: #has_tag?)
- #get(tag, args = {}) ⇒ Object (also: #find)
-
#initialize(owner) ⇒ ModelHelpers
constructor
A new instance of ModelHelpers.
- #new(tag, args = {}) ⇒ Object (also: #add, #create)
Constructor Details
#initialize(owner) ⇒ ModelHelpers
Returns a new instance of ModelHelpers.
5 6 7 |
# File 'lib/polytag/concerns/taggable/model_helpers.rb', line 5 def initialize(owner) @owner = owner end |
Instance Method Details
#del(tag, args = {}) ⇒ Object Also known as: delete, remove, destroy
19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
#exist?(tag, args = {}) ⇒ Boolean Also known as: has_tag?
44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |
#get(tag, args = {}) ⇒ Object Also known as: find
34 35 36 37 38 39 40 41 |
# 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 |