class RailsAgnosticModels::ArelTranslator::Translator
Attributes
arel_string[RW]
search_hash[RW]
Public Class Methods
new(search_hash)
click to toggle source
# File lib/rails_agnostic_models/arel_translator/translator.rb, line 8 def initialize(search_hash) @search_hash = search_hash @arel_string = "" end
Public Instance Methods
translate!()
click to toggle source
# File lib/rails_agnostic_models/arel_translator/translator.rb, line 13 def translate! options_to_arel(search_hash) arel_string end
Private Instance Methods
hash_to_ostruct(key, value)
click to toggle source
# File lib/rails_agnostic_models/arel_translator/translator.rb, line 31 def hash_to_ostruct(key, value) option = OpenStruct.new option.key = key option.value = value option end
options_to_arel(options)
click to toggle source
# File lib/rails_agnostic_models/arel_translator/translator.rb, line 20 def options_to_arel(options) first_key = options.keys.first option = hash_to_ostruct(first_key, options[first_key]) self.arel_string << "#{translate_arel(option)}" options.keys.drop(1).each do |opt| option = hash_to_ostruct(opt, options[opt]) self.arel_string << ".#{translate_arel(option)}" end self.arel_string end
translate_arel(option)
click to toggle source
# File lib/rails_agnostic_models/arel_translator/translator.rb, line 38 def translate_arel(option) case option.key when :order then Order.new(option.value) when :conditions then Where.new(option.value) else "" end.translate! end