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
240 241 242 |
# File 'lib/active_mocker/base.rb', line 240 def ==(obj) hash == obj.attributes.hash end |
#attribute_for_inspect(attr_name) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/active_mocker/base.rb', line 222 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
236 237 238 |
# File 'lib/active_mocker/base.rb', line 236 def hash attributes.hash end |
#inspect ⇒ Object
214 215 216 217 218 219 220 |
# File 'lib/active_mocker/base.rb', line 214 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
210 211 212 |
# File 'lib/active_mocker/base.rb', line 210 def mock_instance_method(method, &block) model_instance_methods[method] = block end |