Class: Phaseout::SEOAction

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_or_key, action = nil) ⇒ SEOAction



5
6
7
8
9
10
11
# File 'lib/phaseout/seo_action.rb', line 5

def initialize(controller_or_key, action = nil)
  if action
    @controller, @action = controller_or_key, action
  else
    @controller, @action = controller_or_key.split '#'
  end
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



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

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



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

def controller
  @controller
end

Class Method Details

.all(&block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/phaseout/seo_action.rb', line 55

def self.all(&block)
  unless block_given?
    values = []
    self.all{ |action| values << action }
    return values
  end

  pattern = "#{Phaseout.redis.namespace}:action:*"
  Phaseout.redis.scan_each(match: pattern) do |value|
    yield self.new( value.match(/#{ Phaseout.redis.namespace }\:action\:/).post_match )
  end
end

.find(key) ⇒ Object



51
52
53
# File 'lib/phaseout/seo_action.rb', line 51

def self.find(key)
  self.new "action:#{key}"
end

Instance Method Details

#add(field_key) ⇒ Object



33
34
35
# File 'lib/phaseout/seo_action.rb', line 33

def add(field_key)
  Phaseout.redis.sadd key, field_key
end

#fields(&block) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/phaseout/seo_action.rb', line 21

def fields(&block)
  if block_given?
    SEOFields.all self.key, &block
  else
    @fields ||= SEOFields.all self.key
  end
end

#idObject



17
18
19
# File 'lib/phaseout/seo_action.rb', line 17

def id
  I18n.transliterate([ @controller, @action ].join '-' ).gsub(/\s+/, '_').underscore
end

#keyObject



13
14
15
# File 'lib/phaseout/seo_action.rb', line 13

def key
  I18n.transliterate([ @controller, @action ].join '#' ).gsub(/\s+/, '_').underscore
end

#nameObject



29
30
31
# File 'lib/phaseout/seo_action.rb', line 29

def name
  controller.camelize.constantize.seo_group_name[key] || key
end

#remove(field_key) ⇒ Object



37
38
39
# File 'lib/phaseout/seo_action.rb', line 37

def remove(field_key)
  Phaseout.redis.srem key, field_key
end

#to_jsonObject



41
42
43
44
45
46
47
48
49
# File 'lib/phaseout/seo_action.rb', line 41

def to_json
  {
    id:         id,
    key:        key,
    name:       name,
    action:     action,
    controller: controller
  }.to_json
end