Module: Findable::Associations::Utils
- Defined in:
- lib/findable/associations/utils.rb
Class Method Summary collapse
- .add_reflection(macro, name, options, ar) ⇒ Object
- .model_for(name, options = {}) ⇒ Object
- .parse_args(args) ⇒ Object
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, , ar) reflection = ActiveRecord::Reflection.create( macro.to_sym, name.to_sym, nil, , 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, = {}) unless model_name = [:class_name].presence name = [:collection] ? name.to_s.singularize : name.to_s model_name = name.camelize end if [: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 = copied. [copied.first, ] end |