Module: ActiveMocker::MockInstanceMethods
- Defined in:
- lib/active_mocker/mock_instance_methods.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
35 36 37 38 39 |
# File 'lib/active_mocker/mock_instance_methods.rb', line 35 def ==(obj) return false if obj.nil? return hash == obj.attributes.hash if obj.respond_to?(:attributes) hash == obj.hash if obj.respond_to?(:hash) end |
#attribute_for_inspect(attr_name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_mocker/mock_instance_methods.rb', line 17 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
31 32 33 |
# File 'lib/active_mocker/mock_instance_methods.rb', line 31 def hash attributes.hash end |
#inspect ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/active_mocker/mock_instance_methods.rb', line 9 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
5 6 7 |
# File 'lib/active_mocker/mock_instance_methods.rb', line 5 def mock_instance_method(method, &block) model_instance_methods[method] = block end |