Class: Phaseout::Handler
- Inherits:
-
Object
- Object
- Phaseout::Handler
- Defined in:
- lib/phaseout/handler.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
Instance Method Summary collapse
- #as ⇒ Object
- #call(&action_block) ⇒ Object
- #class_index_key ⇒ Object
-
#initialize(controller, action, as_pattern, key_pattern, editable, &block) ⇒ Handler
constructor
A new instance of Handler.
- #key ⇒ Object
- #seo_fields ⇒ Object
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/phaseout/handler.rb', line 3 def action @action end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
3 4 5 |
# File 'lib/phaseout/handler.rb', line 3 def controller @controller end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
3 4 5 |
# File 'lib/phaseout/handler.rb', line 3 def default @default end |
Instance Method Details
#as ⇒ Object
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_fields.to_html @controller else @controller. = @default.to_html @controller end action_block.call set_blank_field if @controller.status == 200 && @blank_field && @editable true end |
#class_index_key ⇒ Object
42 43 44 |
# File 'lib/phaseout/handler.rb', line 42 def class_index_key ['action:', @controller.class.name, '#', @action].join.gsub(/\s+/, '_').underscore end |
#key ⇒ Object
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_fields ⇒ Object
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 |