Module: ReportPrint::Api
- Included in:
- Module
- Defined in:
- lib/report_print/api.rb
Overview
These are the extensions that are included into the Module class that enabled you to customize the behaviour of ReportPrint for your own classes.
Instance Method Summary collapse
-
#report_print_inspect! ⇒ Object
Helper that defines a
report_printmethod which callsinspectand applies thecolor:specified in #report_print_options. -
#report_print_options(**kwargs) ⇒ Object
Defines options used by the printer when printing instances of the current class.
Instance Method Details
#report_print_inspect! ⇒ Object
Helper that defines a report_print method which calls inspect and
applies the color: specified in #report_print_options.
53 54 55 56 57 |
# File 'lib/report_print/api.rb', line 53 def report_print_inspect! define_method(:report_print) do |rp| rp.write(inspect, color: rp.(self)[:color]) end end |
#report_print_options(**kwargs) ⇒ Object
Defines options used by the printer when printing instances of the current class.
The currently supported options are:
detect_cycles:whether instances of this class should display just a header and id when printed multiple times by the same report print command.
Defaults totrueexcept for in the case of the simple value types and Data classes.color:the color value to apply when using #report_print_inspect!.
Defaults tonil.
Example Usage
class WithColor
(color: :bright_blue)
report_print_inspect!
end
class CustomContainer
(detect_cycles: false)
end
Option Loading
Setting any value to nil means: take the global value if it is defined.
When ReportPrint fetches options for a given class it first fetches the superclass options (recursively), then it merges the options for the current class on top.
After which it compacts the options (removing the nils) and merges them
on top of any global options. Where the global options are currently
specified by calling ReportPrint.report_print_options.
46 47 48 |
# File 'lib/report_print/api.rb', line 46 def (**kwargs) @report_print_options = (@report_print_options || {}).merge(kwargs) end |