Sha256: 835b9c56d9b997c3947610fae418ae206d4701dbc53334efc18078a74e2922ea

Contents?: true

Size: 687 Bytes

Versions: 7

Compression:

Stored size: 687 Bytes

Contents

# frozen_string_literal: true

class ThinkingSphinx::RealTime::Translator
  def self.call(object, column)
    new(object, column).call
  end

  def initialize(object, column)
    @object, @column = object, column
  end

  def call
    return name.call(object) if name.is_a?(Proc)
    return name   unless name.is_a?(Symbol)
    return result unless result.is_a?(String)

    result.gsub("\u0000", '').force_encoding "UTF-8"
  end

  private

  attr_reader :object, :column

  def name
    @column.__name
  end

  def owner
    stack.inject(object) { |previous, node| previous.try node }
  end

  def result
    @result ||= owner.try name
  end

  def stack
    @column.__stack
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/real_time/translator.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/real_time/translator.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/real_time/translator.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/real_time/translator.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/real_time/translator.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/real_time/translator.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/real_time/translator.rb