Module: Ooor::FieldMethods
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *arguments) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ooor/field_methods.rb', line 81 def method_missing(method_symbol, *arguments) method_name = method_symbol.to_s method_key = method_name.sub('=', '') self.class.reload_fields_definition(false, object_session) if attributes.has_key?(method_key) if method_name.end_with?('=') attributes[method_key] = arguments[0] else attributes[method_key] end elsif @loaded_associations.has_key?(method_name) @loaded_associations[method_name] elsif @associations.has_key?(method_name) result = relationnal_result(method_name, *arguments) @loaded_associations[method_name] = result and return result if result elsif method_name.end_with?('=') return method_missing_value_assign(method_key, arguments) elsif self.class.fields.has_key?(method_name) || self.class.associations_keys.index(method_name) #unloaded field/association return lazzy_load_field(method_name, *arguments) # check if that is not a Rails style association with an _id[s][=] suffix: elsif method_name.match(/_id$/) && self.class.associations_keys.index(rel=method_name.gsub(/_id$/, "")) return many2one_id_method(rel, *arguments) elsif method_name.match(/_ids$/) && self.class.associations_keys.index(rel=method_name.gsub(/_ids$/, "")) return x_to_many_ids_method(rel, *arguments) elsif id rpc_execute(method_key, [id], *arguments) #we assume that's an action else super end rescue UnknownAttributeOrAssociationError => e e.klass = self.class raise e end |