@@ -110,39 +110,40 @@ def self.primary_key; :id; end
110
110
end
111
111
end
112
112
end
113
- m . __send__ ( :__mock_proxy ) . instance_eval ( <<-CODE , __FILE__ , __LINE__ )
114
- def @object.is_a?(other)
115
- #{ model_class } .ancestors.include?(other)
116
- end unless #{ stubs . has_key? ( :is_a? ) }
117
113
118
- def @object.kind_of?(other)
119
- #{ model_class } .ancestors.include?(other)
120
- end unless #{ stubs . has_key? ( :kind_of? ) }
114
+ msingleton = m . singleton_class
115
+ msingleton . __send__ ( :define_method , :is_a? ) do |other |
116
+ model_class . ancestors . include? ( other )
117
+ end unless stubs . has_key? ( :is_a? )
121
118
122
- def @object.instance_of?( other)
123
- other == #{ model_class }
124
- end unless #{ stubs . has_key? ( :instance_of? ) }
119
+ msingleton . __send__ ( :define_method , :kind_of? ) do | other |
120
+ model_class . ancestors . include? ( other )
121
+ end unless stubs . has_key? ( :kind_of? )
125
122
126
- def @object.__model_class_has_column?(method_name)
127
- #{ model_class } .respond_to?(:column_names) && #{ model_class } .column_names.include?(method_name.to_s)
128
- end
123
+ msingleton . __send__ ( :define_method , :instance_of? ) do | other |
124
+ other == model_class
125
+ end unless stubs . has_key? ( :instance_of? )
129
126
130
- def @object.respond_to?(method_name, include_private=false)
131
- __model_class_has_column ?(method_name) ? true : super
132
- end unless #{ stubs . has_key? ( :respond_to? ) }
127
+ msingleton . __send__ ( :define_method , :__model_class_has_column? ) do | method_name |
128
+ model_class . respond_to? ( :column_names ) && model_class . column_names . include ?( method_name . to_s )
129
+ end
133
130
134
- def @object.method_missing(m, *a, &b)
135
- respond_to?(m) ? null_object? ? self : nil : super
136
- end
131
+ msingleton . __send__ ( :define_method , :respond_to? ) do |method_name , include_private = false |
132
+ __model_class_has_column? ( method_name ) ? true : super ( method_name , include_private )
133
+ end unless stubs . has_key? ( :respond_to? )
134
+
135
+ msingleton . __send__ ( :define_method , :method_missing ) do |m , *a , &b |
136
+ respond_to? ( m ) ? null_object? ? self : nil : super ( m , *a , &b )
137
+ end
137
138
138
- def @object. class
139
- #{ model_class }
140
- end unless #{ stubs . has_key? ( :class ) }
139
+ msingleton . __send__ ( :define_method , : class) do
140
+ model_class
141
+ end unless stubs . has_key? ( :class )
141
142
142
- def @object.to_s
143
- " #{ model_class . name } _ #{ to_param } "
144
- end unless #{ stubs . has_key? ( :to_s ) }
145
- CODE
143
+ mock_param = to_param
144
+ msingleton . __send__ ( :define_method , :to_s ) do
145
+ " #{ model_class . name } _ #{ mock_param } "
146
+ end unless stubs . has_key? ( :to_s )
146
147
yield m if block_given?
147
148
end
148
149
end
0 commit comments