Module: Nazar
- Extended by:
- Dry::Configurable
- Defined in:
- lib/nazar.rb,
lib/nazar/view.rb,
lib/nazar/version.rb,
lib/nazar/renderer.rb,
lib/nazar/formatter.rb,
lib/nazar/base_table.rb,
lib/nazar/cell_formatter.rb,
lib/nazar/vertical_table.rb,
lib/nazar/formatter/struct.rb,
lib/nazar/horizontal_table.rb,
lib/nazar/formatter/generic.rb,
lib/nazar/headers_formatter.rb,
lib/nazar/formatter/csv_table.rb,
lib/nazar/formatter/sequel_item.rb,
lib/nazar/formatter/sequel_interface.rb,
lib/nazar/formatter/sequel_collection.rb,
lib/nazar/formatter/active_record_item.rb,
lib/nazar/formatter/active_record_interface.rb,
lib/nazar/formatter/active_record_collection.rb
Overview
rubocop:disable Metrics/ModuleLength
Defined Under Namespace
Modules: Formatter
Classes: BaseTable, CellFormatter, HeadersFormatter, HorizontalTable, Renderer, VerticalTable, View
Constant Summary
collapse
- VERSION =
'1.3.3'
Class Method Summary
collapse
Class Method Details
.disable! ⇒ Object
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/nazar.rb', line 106
def disable!
disable_shorthand_method! if @defined_shorthand_method
return unless @enabled
disable_for_irb! if defined?(IRB)
disable_for_pry! if defined?(Pry)
@enabled = false
end
|
.enable!(extensions: [:active_record, :csv, :struct]) ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/nazar.rb', line 46
def enable!(extensions: [:active_record, :csv, :struct])
return if @enabled
load_extensions!(extensions)
enable_repl!
enable_shorthand_method! if Nazar.config.enable_shorthand_method
@enabled = true
end
|
42
43
44
|
# File 'lib/nazar.rb', line 42
def formatters
@formatters ||= Set.new
end
|
.load!(extensions: [:active_record, :csv]) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/nazar.rb', line 57
def load!(extensions: [:active_record, :csv])
load_extensions!(extensions)
enable_shorthand_method! if Nazar.config.enable_shorthand_method
true
end
|
.load_active_record! ⇒ Object
76
77
78
79
80
81
|
# File 'lib/nazar.rb', line 76
def load_active_record!
require 'active_record'
register_formatter!('ActiveRecordCollection', 'nazar/formatter/active_record_collection')
register_formatter!('ActiveRecordItem', 'nazar/formatter/active_record_item')
end
|
.load_csv! ⇒ Object
64
65
66
67
68
|
# File 'lib/nazar.rb', line 64
def load_csv!
require 'csv'
register_formatter!('CSVTable', 'nazar/formatter/csv_table')
end
|
.load_sequel! ⇒ Object
83
84
85
86
87
88
|
# File 'lib/nazar.rb', line 83
def load_sequel!
require 'sequel'
register_formatter!('SequelCollection', 'nazar/formatter/sequel_collection')
register_formatter!('SequelItem', 'nazar/formatter/sequel_item')
end
|
.load_struct! ⇒ Object
70
71
72
73
74
|
# File 'lib/nazar.rb', line 70
def load_struct!
require 'ostruct'
register_formatter!('Struct', 'nazar/formatter/struct')
end
|
.pry_proc ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/nazar.rb', line 96
def pry_proc
return unless defined?(Pry)
proc do |output, value, instance|
renderer = Nazar::Renderer.new(value, layout: Nazar.config.formatter.layout,
paginate: Nazar.config.formatter.paginate)
renderer.valid? ? renderer.render : @__original_pry_print.call(output, value, instance)
end
end
|
90
91
92
93
94
|
# File 'lib/nazar.rb', line 90
def register_formatter!(klass_name, path)
require path
formatters << Nazar::Formatter.const_get(klass_name)
end
|