Class: EasyTags::TaggableContextMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_tags/taggable_context_methods.rb

Overview

Handles injecting of the dynamic context related methods Example:

easy_tags_on :bees

# will create:

has_many :bees_taggings
has_many :bees_tags

def bees
def bees=
def bees_list
def bees_list=

Class Method Summary collapse

Class Method Details

.inject(class_instance:, context:) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/easy_tags/taggable_context_methods.rb', line 17

def inject(class_instance:, context:)
  class_instance.class_eval "has_many(\n:\#{context}_taggings, -> { includes(:tag).where(context: :\#{context}) },\nas: :taggable,\nclass_name: 'EasyTags::Tagging',\ndependent: :destroy\n)\n\nhas_many(\n:\#{context}_tags,\nclass_name: 'EasyTags::Tag',\nthrough: :\#{context}_taggings,\nsource: :tag\n)\n\nattribute :\#{context}_list, ActiveModel::Type::Value.new\n\ndef \#{context}\n_taggable_context(:\#{context}).tags\nend\n\ndef \#{context}=(value)\n_taggable_context(:\#{context}).update(value)\n\#{context}\nend\n\ndef \#{context}_list\n_taggable_context(:\#{context}).tags.to_s\nend\n\ndef \#{context}_list=(value)\n_taggable_context(:\#{context}).update(value)\n\#{context}_list\nend\n", __FILE__, __LINE__ + 1
end