class Phaseout::SEOFields

Attributes

default[RW]
fields[RW]
human_name[R]
key[R]
values[RW]

Public Class Methods

all(action_key) { |find match('seo_key:').post_match| ... } click to toggle source
# File lib/phaseout/seo_fields.rb, line 104
def self.all(action_key, &block)
  unless block_given?
    values = []
    self.all(action_key){ |field| values << field }
    return values
  end

  class_index_key = "#{Phaseout.redis.namespace}:action:#{action_key}"
  Phaseout.redis.sscan_each(class_index_key) do |value|
    yield self.find value.match('seo_key:').post_match
  end
end
find(key) click to toggle source
# File lib/phaseout/seo_fields.rb, line 99
def self.find(key)
  dump = Phaseout.redis.get "seo_key:#{key}"
  dump ? Marshal.load(dump) : nil
end
new(key, human_name, values = Hash.new) { |self| ... } click to toggle source
# File lib/phaseout/seo_fields.rb, line 7
def initialize(key, human_name, values = Hash.new, &block)
  @key, @human_name, @values = I18n.transliterate(key).gsub(/\s+/, '_').underscore, human_name, values
  yield(self) if block_given?
end

Public Instance Methods

[](index) click to toggle source
# File lib/phaseout/seo_fields.rb, line 70
def [](index)
  values[index.to_sym]
end
[]=(index, value) click to toggle source
# File lib/phaseout/seo_fields.rb, line 74
def []=(index, value)
  values[index.to_sym] = value
end
action() click to toggle source
# File lib/phaseout/seo_fields.rb, line 22
def action
  @action ||= ::Phaseout::SEOAction.new action_key
end
action_key() click to toggle source
# File lib/phaseout/seo_fields.rb, line 18
def action_key
  @action_key ||= @key.match('seo_key:').post_match.match(':').pre_match
end
delete() click to toggle source
# File lib/phaseout/seo_fields.rb, line 49
def delete
  Phaseout::SEOAction.find(action_key).remove key
  Phaseout.redis.del key
end
dump() click to toggle source
# File lib/phaseout/seo_fields.rb, line 41
def dump
  Marshal.dump self
end
evaluated_values(controller) click to toggle source
# File lib/phaseout/seo_fields.rb, line 54
def evaluated_values(controller)
  @_values ||= if @default
    @default.evaluated_values(controller).merge @values
  else
    Hash[
      @values.map do |helper, argument|
        if argument.is_a? Proc
          [ helper, controller.instance_eval(&argument) ]
        else
          [ helper, argument ]
        end
      end
    ]
  end
end
id() click to toggle source
# File lib/phaseout/seo_fields.rb, line 26
def id
  @key.match(/\#.+\:/).post_match.gsub(/\s+/, '_').underscore
end
inspect() click to toggle source
# File lib/phaseout/seo_fields.rb, line 78
def inspect
  "#<Phaseout::SEO #{action_key} #{@human_name}>"
end
Also aliased as: to_s
marshal_dump() click to toggle source
# File lib/phaseout/seo_fields.rb, line 91
def marshal_dump
  [ @key, @human_name, @values ]
end
marshal_load(dump_array) click to toggle source
# File lib/phaseout/seo_fields.rb, line 95
def marshal_load(dump_array)
  @key, @human_name, @values = dump_array
end
method_missing(method, *args, &block) click to toggle source
# File lib/phaseout/seo_fields.rb, line 83
def method_missing(method, *args, &block)
  if block_given?
    @values[method.to_sym] = block
  else
    @values[method.to_sym] = args unless args.empty?
  end
end
save() click to toggle source
# File lib/phaseout/seo_fields.rb, line 45
def save
  Phaseout.redis.set key, self.dump
end
to_html(controller) click to toggle source
# File lib/phaseout/seo_fields.rb, line 12
def to_html(controller)
  evaluated_values(controller).map do |helper, argument|
    controller.view_context.send helper, *argument
  end.join.html_safe
end
to_json() click to toggle source
# File lib/phaseout/seo_fields.rb, line 30
def to_json
  {
    id:         id,
    key:        @key.match('seo_key:').post_match,
    fields:     @values,
    name:       @human_name,
    action_id:  action_key.gsub('#', '_').underscore,
    action_key: action_key
  }.to_json
end
to_s()
Alias for: inspect