Class: Phaseout::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/phaseout/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, action, as_pattern, key_pattern, editable, &block) ⇒ Handler

Returns a new instance of Handler.



5
6
7
8
# File 'lib/phaseout/handler.rb', line 5

def initialize(controller, action, as_pattern, key_pattern, editable, &block)
  @controller, @action, @as_pattern, @key_pattern, @editable = controller, action, as_pattern, key_pattern, editable
  @default = Phaseout::SEOFields.new key, as, &block
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/phaseout/handler.rb', line 3

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



3
4
5
# File 'lib/phaseout/handler.rb', line 3

def controller
  @controller
end

#defaultObject (readonly)

Returns the value of attribute default.



3
4
5
# File 'lib/phaseout/handler.rb', line 3

def default
  @default
end

Instance Method Details

#asObject



21
22
23
# File 'lib/phaseout/handler.rb', line 21

def as
  @as ||= eval_pattern @as_pattern
end

#call(&action_block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/phaseout/handler.rb', line 10

def call(&action_block)
  if seo_fields
    @controller.seo_tags = seo_fields.to_html @controller
  else
    @controller.seo_tags = @default.to_html @controller
  end
  action_block.call
  set_blank_field if @controller.status == 200 && @blank_field && @editable
  true
end

#class_index_keyObject



42
43
44
# File 'lib/phaseout/handler.rb', line 42

def class_index_key
  ['action:', @controller.class.name, '#', @action].join.gsub(/\s+/, '_').underscore
end

#keyObject



25
26
27
# File 'lib/phaseout/handler.rb', line 25

def key
  @key ||= I18n.transliterate( [ 'seo_key:', @controller.class.name, '#', @action, ':', eval_pattern(@key_pattern) ].join.gsub(/\s+/, '_').underscore )
end

#seo_fieldsObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/phaseout/handler.rb', line 29

def seo_fields
  return @seo_fields if @seo_fields
  dump = Phaseout.redis.get key
  if dump.blank?
    @blank_field = true
    return nil
  else
    @seo_fields = Marshal.load dump
    @seo_fields.default = @default
    @seo_fields
  end
end