Module: AmazingPrint::NoBrainer
- Included in:
- Formatter
- Defined in:
- lib/amazing_print/ext/nobrainer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#awesome_nobrainer_class(object) ⇒ Object
Format NoBrainer class object.
-
#awesome_nobrainer_document(object) ⇒ Object
Format NoBrainer Document object.
-
#cast_with_nobrainer(object, type) ⇒ Object
Add NoBrainer class names to the dispatcher pipeline.
Class Method Details
.included(base) ⇒ Object
8 9 10 11 |
# File 'lib/amazing_print/ext/nobrainer.rb', line 8 def self.included(base) base.send :alias_method, :cast_without_nobrainer, :cast base.send :alias_method, :cast, :cast_with_nobrainer end |
Instance Method Details
#awesome_nobrainer_class(object) ⇒ Object
Format NoBrainer class object.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/amazing_print/ext/nobrainer.rb', line 29 def awesome_nobrainer_class(object) name = "#{awesome_simple(object, :class)} < #{awesome_simple(object.superclass, :class)}" data = Hash[object.fields.map do |field, | [field, ([:type] || Object).to_s.underscore.to_sym] end] name = "class #{awesome_simple(object.to_s, :class)}" base = "< #{awesome_simple(object.superclass.to_s, :class)}" [name, base, awesome_hash(data)].join(' ') end |
#awesome_nobrainer_document(object) ⇒ Object
Format NoBrainer Document object.
43 44 45 46 47 48 49 |
# File 'lib/amazing_print/ext/nobrainer.rb', line 43 def awesome_nobrainer_document(object) data = object.inspectable_attributes.symbolize_keys if object.errors.present? data = { errors: object.errors, attributes: data } end "#{object} #{awesome_hash(data)}" end |
#cast_with_nobrainer(object, type) ⇒ Object
Add NoBrainer class names to the dispatcher pipeline.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/amazing_print/ext/nobrainer.rb', line 15 def cast_with_nobrainer(object, type) cast = cast_without_nobrainer(object, type) if defined?(::NoBrainer::Document) if object.is_a?(Class) && object < ::NoBrainer::Document cast = :nobrainer_class elsif object.is_a?(::NoBrainer::Document) cast = :nobrainer_document end end cast end |