Class: Mautic::Tag::Collection

Inherits:
Array
  • Object
show all
Defined in:
app/models/mautic/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, *several_variants) ⇒ Collection

Returns a new instance of Collection.

Parameters:



8
9
10
11
12
# File 'app/models/mautic/tag.rb', line 8

def initialize(model, *several_variants)
  @model = model
  @tags_to_remove = []
  super(several_variants)
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'app/models/mautic/tag.rb', line 5

def model
  @model
end

Instance Method Details

#<<(item) ⇒ Object



14
15
16
17
18
# File 'app/models/mautic/tag.rb', line 14

def <<(item)
  @model.changed = true
  item = Tag.new(@model, { tag: item }) if item.is_a?(String)
  super(item)
end

#remove(item) ⇒ Object



20
21
22
23
24
25
# File 'app/models/mautic/tag.rb', line 20

def remove(item)
  @model.changed = true
  item = detect { |t| t.name == item } if item.is_a?(String)
  @tags_to_remove << "-#{item}"
  delete item
end

#to_mauticObject



27
28
29
# File 'app/models/mautic/tag.rb', line 27

def to_mautic
  map(&:name) + @tags_to_remove
end