Module: Findable::Associations::Utils

Defined in:
lib/findable/associations/utils.rb

Class Method Summary collapse

Class Method Details

.add_reflection(macro, name, options, ar) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/findable/associations/utils.rb', line 23

def self.add_reflection(macro, name, options, ar)
  reflection = ActiveRecord::Reflection.create(
    macro.to_sym,
    name.to_sym,
    nil,
    options,
    ar
  )
  ActiveRecord::Reflection.add_reflection(ar, name.to_sym, reflection)
end

.model_for(name, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/findable/associations/utils.rb', line 4

def self.model_for(name, options = {})
  unless model_name = options[:class_name].presence
    name = options[:collection] ? name.to_s.singularize : name.to_s
    model_name = name.camelize
  end

  if options[:safe]
    model_name.try(:safe_constantize)
  else
    model_name.constantize
  end
end

.parse_args(args) ⇒ Object



17
18
19
20
21
# File 'lib/findable/associations/utils.rb', line 17

def self.parse_args(args)
  copied = args.dup
  options = copied.extract_options!
  [copied.first, options]
end