Module: ActiveMocker::ModelInstanceMethods
- Defined in:
- lib/active_mocker/base.rb
Instance Method Summary collapse
- #==(obj) ⇒ Object
- #attribute_for_inspect(attr_name) ⇒ Object
- #hash ⇒ Object
- #inspect ⇒ Object
- #mock_instance_method(method, &block) ⇒ Object
Instance Method Details
#==(obj) ⇒ Object
235 236 237 |
# File 'lib/active_mocker/base.rb', line 235 def ==(obj) hash == obj.attributes.hash end |
#attribute_for_inspect(attr_name) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/active_mocker/base.rb', line 217 def attribute_for_inspect(attr_name) value = self.attributes[attr_name] if value.is_a?(String) && value.length > 50 "#{value[0, 50]}...".inspect elsif value.is_a?(Date) || value.is_a?(Time) %("#{value.to_s(:db)}") elsif value.is_a?(Array) && value.size > 10 inspected = value.first(10).inspect %(#{inspected[0...-1]}, ...]) else value.inspect end end |
#hash ⇒ Object
231 232 233 |
# File 'lib/active_mocker/base.rb', line 231 def hash attributes.hash end |
#inspect ⇒ Object
209 210 211 212 213 214 215 |
# File 'lib/active_mocker/base.rb', line 209 def inspect inspection = self.class.column_names.map { |name| "#{name}: #{attribute_for_inspect(name)}" }.compact.join(", ") "#<#{self.class} #{inspection}>" end |
#mock_instance_method(method, &block) ⇒ Object
205 206 207 |
# File 'lib/active_mocker/base.rb', line 205 def mock_instance_method(method, &block) model_instance_methods[method] = block end |