Module: AwesomePrint::NoBrainer
- Defined in:
- lib/awesome_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
9 10 11 12 |
# File 'lib/awesome_print/ext/nobrainer.rb', line 9 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.
30 31 32 33 34 35 |
# File 'lib/awesome_print/ext/nobrainer.rb', line 30 def awesome_nobrainer_class(object) data = Hash[object.fields.map do |field, | [field, ([:type] || Object).to_s.underscore.to_sym] end] "class #{object} < #{object.superclass} " << awesome_hash(data) end |
#awesome_nobrainer_document(object) ⇒ Object
Format NoBrainer Document object.
39 40 41 42 43 44 45 |
# File 'lib/awesome_print/ext/nobrainer.rb', line 39 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.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/awesome_print/ext/nobrainer.rb', line 16 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 |