Module: Marley::Utils
- Defined in:
- lib/marley/utils.rb
Defined Under Namespace
Modules: ClassAttrs
Class Method Summary collapse
- .combine(old, new) ⇒ Object
- .hash_keys_to_syms(hsh) ⇒ Object
- .many_to_many_join(lclass, rclass, lopts = {}, ropts = {}) ⇒ Object
- .sti(klass) ⇒ Object
Class Method Details
.combine(old, new) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/marley/utils.rb', line 47 def self.combine(old,new) if old.is_a?(Hash) && new.is_a?(Hash) old.merge(new) {|k,o,n|Marley::Utils.combine(o,n)} elsif old.is_a?(Array) && new.is_a?(Array) (old + new).uniq else new end end |
.hash_keys_to_syms(hsh) ⇒ Object
64 65 66 |
# File 'lib/marley/utils.rb', line 64 def self.hash_keys_to_syms(hsh) hsh.inject({}) {|h,(k,v)| h[k.to_sym]= v.class==Hash ? hash_keys_to_syms(v) : v;h } end |
.many_to_many_join(lclass, rclass, lopts = {}, ropts = {}) ⇒ Object
59 60 61 62 63 |
# File 'lib/marley/utils.rb', line 59 def self.many_to_many_join(lclass, rclass,lopts={},ropts={}) join_table=[lclass.table_name.to_s,rclass.table_name.to_s ].sort.join('_').to_sym lclass.many_to_many(rclass.resource_name.pluralize.to_sym,{:join_table => join_table,:class =>rclass, :left_key => lclass.foreign_key_name, :right_key => rclass.foreign_key_name}).update(lopts) rclass.many_to_many(lclass.resource_name.pluralize.to_sym,{:join_table => join_table, :class =>lclass,:left_key => rclass.foreign_key_name, :right_key => lclass.foreign_key_name}.update(ropts)) end |