Class: NoFlyList::TaggableRecord::TagSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/no_fly_list/taggable_record/tag_setup.rb

Overview

Handles setup and configuration of tagging for a model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(taggable_klass, context, options = {}) ⇒ TagSetup

Creates new tag setup configuration

Parameters:

  • taggable_klass (Class)

    Model to configure

  • context (Symbol)

    Tag context name

  • options (Hash) (defaults to: {})

    Setup options



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 41

def initialize(taggable_klass, context, options = {})
  @taggable_klass = taggable_klass
  @context = context
  @transformer = options.fetch(:transformer, ApplicationTagTransformer)
  @polymorphic = options.fetch(:polymorphic, false)
  @restrict_to_existing = options.fetch(:restrict_to_existing, false)
  @counter_cache = options.fetch(:counter_cache, false)
  @counter_cache_column = "#{context}_count"
  @limit = options.fetch(:limit, nil)
  @tag_class_name = determine_tag_class_name(taggable_klass, options)
  @tagging_class_name = determine_tagging_class_name(taggable_klass, options)
  @adapter = determine_adapter
end

Instance Attribute Details

#adapterSymbol (readonly)

Returns Database adapter type (:postgresql, :mysql, :sqlite).

Returns:

  • (Symbol)

    Database adapter type (:postgresql, :mysql, :sqlite)



35
36
37
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 35

def adapter
  @adapter
end

#contextSymbol (readonly)

Returns Tagging context name.

Returns:

  • (Symbol)

    Tagging context name



11
12
13
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 11

def context
  @context
end

#counter_cacheBoolean (readonly)

Returns Whether to use counter cache.

Returns:

  • (Boolean)

    Whether to use counter cache



26
27
28
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 26

def counter_cache
  @counter_cache
end

#limitInteger? (readonly)

Returns Maximum number of tags allowed.

Returns:

  • (Integer, nil)

    Maximum number of tags allowed



23
24
25
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 23

def limit
  @limit
end

#polymorphicBoolean (readonly)

Returns Whether tags are polymorphic.

Returns:

  • (Boolean)

    Whether tags are polymorphic



17
18
19
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 17

def polymorphic
  @polymorphic
end

#restrict_to_existingBoolean (readonly)

Returns Whether to restrict to existing tags.

Returns:

  • (Boolean)

    Whether to restrict to existing tags



20
21
22
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 20

def restrict_to_existing
  @restrict_to_existing
end

#tag_class_nameString (readonly)

Returns Name of tag class.

Returns:

  • (String)

    Name of tag class



29
30
31
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 29

def tag_class_name
  @tag_class_name
end

#taggable_klassClass (readonly)

Returns Model class being made taggable.

Returns:

  • (Class)

    Model class being made taggable



8
9
10
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 8

def taggable_klass
  @taggable_klass
end

#tagging_class_nameString (readonly)

Returns Name of tagging class.

Returns:

  • (String)

    Name of tagging class



32
33
34
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 32

def tagging_class_name
  @tagging_class_name
end

#transformerClass (readonly)

Returns Tag string transformer.

Returns:

  • (Class)

    Tag string transformer



14
15
16
# File 'lib/no_fly_list/taggable_record/tag_setup.rb', line 14

def transformer
  @transformer
end