Class: CanCan::ModelAdapters::ConditionsExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/cancan/model_adapters/conditions_extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(model_class) ⇒ ConditionsExtractor

Returns a new instance of ConditionsExtractor.



10
11
12
13
# File 'lib/cancan/model_adapters/conditions_extractor.rb', line 10

def initialize(model_class)
  @names_cache = { model_class.table_name => [] }.with_indifferent_access
  @root_model_class = model_class
end

Instance Method Details

#tableize_conditions(conditions, model_class = @root_model_class, path_to_key = 0) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cancan/model_adapters/conditions_extractor.rb', line 15

def tableize_conditions(conditions, model_class = @root_model_class, path_to_key = 0)
  return conditions unless conditions.is_a? Hash

  conditions.each_with_object({}) do |(key, value), result_hash|
    if value.is_a? Hash
      result_hash.merge!(calculate_result_hash(key, model_class, path_to_key, result_hash, value))
    else
      result_hash[key] = value
    end
    result_hash
  end
end