Module: PagesCore::Taggable

Extended by:
ActiveSupport::Concern
Included in:
Page
Defined in:
app/models/concerns/pages_core/taggable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#serialized_tagsObject


22
23
24
# File 'app/models/concerns/pages_core/taggable.rb', line 22

def serialized_tags
  tags.order("name ASC").map(&:name).to_json
end

#serialized_tags=(json) ⇒ Object


26
27
28
# File 'app/models/concerns/pages_core/taggable.rb', line 26

def serialized_tags=(json)
  tag_with(ActiveSupport::JSON.decode(json))
end

#tag_listObject


43
44
45
# File 'app/models/concerns/pages_core/taggable.rb', line 43

def tag_list
  tags.order("name ASC").map(&:name).join(", ")
end

#tag_list=(tag_list) ⇒ Object


39
40
41
# File 'app/models/concerns/pages_core/taggable.rb', line 39

def tag_list=(tag_list)
  tag_with(tag_list)
end

#tag_with(*list) ⇒ Object


30
31
32
33
34
35
36
37
# File 'app/models/concerns/pages_core/taggable.rb', line 30

def tag_with(*list)
  Tag.transaction do
    taggings.destroy_all
    Tag.parse(list).each do |name|
      Tag.find_or_create_by(name: name).on(self)
    end
  end
end