Module: Octopus::Rails3::Association
- Defined in:
- lib/octopus/rails3.0/association.rb
Instance Method Summary collapse
- #association_accessor_methods(reflection, association_proxy_class) ⇒ Object
- #association_constructor_method(constructor, reflection, association_proxy_class) ⇒ Object
- #collection_accessor_methods(reflection, association_proxy_class, writer = true) ⇒ Object
- #collection_reader_method(reflection, association_proxy_class) ⇒ Object
Instance Method Details
#association_accessor_methods(reflection, association_proxy_class) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/octopus/rails3.0/association.rb', line 4 def association_accessor_methods(reflection, association_proxy_class) super define_method("#{reflection.name}_with_octopus") do |*params| reload_connection send("#{reflection.name}_without_octopus", *params) end define_method("loaded_#{reflection.name}_with_octopus?") do reload_connection send("loaded_#{reflection.name}_without_octopus?") end define_method("#{reflection.name}_with_octopus=") do |new_value| reload_connection send("#{reflection.name}_without_octopus=", new_value) end define_method("set_#{reflection.name}_target_with_octopus") do |target| reload_connection send("set_#{reflection.name}_target_without_octopus", target) end alias_method_chain reflection.name, "octopus" alias_method_chain "loaded_#{reflection.name}?", "octopus" alias_method_chain "#{reflection.name}=", "octopus" alias_method_chain "set_#{reflection.name}_target", "octopus" end |
#association_constructor_method(constructor, reflection, association_proxy_class) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/octopus/rails3.0/association.rb', line 69 def association_constructor_method(constructor, reflection, association_proxy_class) super define_method("#{constructor}_#{reflection.name}_with_octopus") do |*params| reload_connection result = send("#{constructor}_#{reflection.name}_without_octopus", *params) result.current_shard = current_shard if should_set_current_shard? result end alias_method_chain "#{constructor}_#{reflection.name}", "octopus" end |
#collection_accessor_methods(reflection, association_proxy_class, writer = true) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/octopus/rails3.0/association.rb', line 50 def collection_accessor_methods(reflection, association_proxy_class, writer = true) super if writer define_method("#{reflection.name}_with_octopus=") do |new_value| reload_connection send("#{reflection.name}_without_octopus=", new_value) end define_method("#{reflection.name.to_s.singularize}_ids_with_octopus=") do |new_value| reload_connection send("#{reflection.name.to_s.singularize}_ids_without_octopus=", new_value) end alias_method_chain "#{reflection.name}=", "octopus" alias_method_chain "#{reflection.name.to_s.singularize}_ids=", "octopus" end end |
#collection_reader_method(reflection, association_proxy_class) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/octopus/rails3.0/association.rb', line 33 def collection_reader_method(reflection, association_proxy_class) super define_method("#{reflection.name}_with_octopus") do |*params| reload_connection send("#{reflection.name}_without_octopus", *params) end define_method("#{reflection.name.to_s.singularize}_ids_with_octopus") do reload_connection send("#{reflection.name.to_s.singularize}_ids_without_octopus") end alias_method_chain reflection.name, "octopus" alias_method_chain "#{reflection.name.to_s.singularize}_ids", "octopus" end |