Class: Rails::Cache::Tags::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/cache/tags/tag.rb

Constant Summary collapse

KEY_PREFIX =
'_tags'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Tag

Tag constructor



25
26
27
# File 'lib/rails/cache/tags/tag.rb', line 25

def initialize(name)
  @name = ActiveSupport::Cache.expand_cache_key(name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/rails/cache/tags/tag.rb', line 22

def name
  @name
end

Class Method Details

.build(names) ⇒ Object

=> [‘1’, ‘2’, ‘3’] => [Tag(post/1), Tag(post/2), Tag(post/3)] => 1, :user => 2 => [Tag(post/1), Tag(user/2)]

‘post/1’, ‘post/2’, ‘post/3’

> [Tag(post/1), Tag(post/2), Tag(post/3)]



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rails/cache/tags/tag.rb', line 10

def self.build(names)
  case names
    when NilClass then nil
    when Hash then names.map do |key, value|
      Array.wrap(value).map { |v| new([key, v]) }
    end.flatten
    when Enumerable then names.map { |v| build(v) }.flatten
    when self then names
    else [new(names)]
  end
end

Instance Method Details

#to_keyObject

real cache key



30
31
32
# File 'lib/rails/cache/tags/tag.rb', line 30

def to_key
  [KEY_PREFIX, @name].join('/')
end