class ActsAsIndexable::Attribute

Attributes

attrs[RW]
format[RW]
key[RW]
label[RW]
partial[RW]
path[RW]

Public Class Methods

new(key, attrs={}) click to toggle source
# File lib/acts_as_indexable/attribute.rb, line 12
def initialize(key, attrs={})
  @key = key
  @attrs = attrs
  @label = @attrs.try(:[], :label) || @key.to_s.humanize
  @path = @attrs.try(:[], :link_to)
  @format = @attrs.try(:[], :format)
  @partial = @attrs.try(:[], :partial)
end

Public Instance Methods

href(ctx, href=nil) click to toggle source
# File lib/acts_as_indexable/attribute.rb, line 29
def href(ctx, href=nil)
  path = href || @path
  if path.present?
    if path.to_s == 'self'
      ctx
    else
      path.scan(/:[a-z_]*/).each do |attr|
        path = path.gsub(/#{attr}/, ctx.send(attr[1..-1].to_sym).to_s)
      end
      path
    end
  end
end
l(ctx) click to toggle source
# File lib/acts_as_indexable/attribute.rb, line 21
def l(ctx)
  if @format.present?
    I18n.l ctx.send(@key), format: @format
  else
    ctx.send(@key)
  end
end