nazar 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.github/workflows/main.yml +5 -1
- data/README.md +1 -1
- data/lib/nazar/formatter/active_record_collection.rb +6 -0
- data/lib/nazar/formatter/active_record_item.rb +4 -0
- data/lib/nazar/formatter/csv_table.rb +4 -0
- data/lib/nazar/formatter/sequel_collection.rb +24 -0
- data/lib/nazar/formatter/sequel_interface.rb +33 -0
- data/lib/nazar/formatter/sequel_item.rb +25 -0
- data/lib/nazar/version.rb +1 -1
- data/lib/nazar/view.rb +1 -36
- data/lib/nazar.rb +21 -9
- data/nazar.gemspec +3 -1
- data.tar.gz.sig +0 -0
- metadata +37 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae9a224c9ae75c4e9b85ef48d22c97ea0c293b42aa859cc03dd4e0f31abed150
|
4
|
+
data.tar.gz: e2450f3e6a340c7bd6e1e239201c6bf7e7248c9e88d4e032d1e7e09be96d40aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39ed17bba483fde391edcafe72f942f7f38777f25d1baa152ddfc5121a1e2019c686f736af537e46a65e4fca6edd7a6acc02858a8d569f9bf7376b9d9e8824f3
|
7
|
+
data.tar.gz: 7318b8a9beb572d8a6732734b4847ea7bd2c856b32def45c91ee88034eef122026d5f340e88d40b983c106f793b1f5df0047d7d28526b192f3b916c311439f12
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.github/workflows/main.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Nazar [](https://github.com/krzyzak/nazar/actions) [](https://badge.fury.io/rb/nazar) [](https://codeclimate.com/github/krzyzak/nazar)
|
1
|
+
# Nazar [](https://github.com/krzyzak/nazar/actions) [](https://badge.fury.io/rb/nazar) [](https://codeclimate.com/github/krzyzak/nazar) [](https://codeclimate.com/github/krzyzak/nazar/test_coverage)
|
2
2
|
|
3
3
|
Nazar improves defvault inspect output for console applications (supports IRB and Pry).
|
4
4
|
|
@@ -15,6 +15,12 @@ module Nazar
|
|
15
15
|
@klass = collection.first&.class
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.valid?(data)
|
19
|
+
data.is_a?(ActiveRecord::Associations::CollectionProxy) ||
|
20
|
+
data.is_a?(ActiveRecord::Relation) ||
|
21
|
+
(data.is_a?(Array) && data.first.is_a?(ActiveRecord::Base))
|
22
|
+
end
|
23
|
+
|
18
24
|
def summary
|
19
25
|
collection.size
|
20
26
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nazar/formatter/sequel_interface'
|
4
|
+
|
5
|
+
module Nazar
|
6
|
+
module Formatter
|
7
|
+
class SequelCollection
|
8
|
+
include SequelInterface
|
9
|
+
|
10
|
+
def initialize(collection)
|
11
|
+
@collection = collection
|
12
|
+
@attributes = collection.first&.values
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.valid?(data)
|
16
|
+
data.is_a?(Array) && data.first.is_a?(Sequel::Model)
|
17
|
+
end
|
18
|
+
|
19
|
+
def summary
|
20
|
+
collection.size
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nazar
|
4
|
+
module Formatter
|
5
|
+
module SequelInterface
|
6
|
+
attr_reader :collection, :klass, :attributes
|
7
|
+
|
8
|
+
def valid?
|
9
|
+
!!attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
def headers
|
13
|
+
HeadersFormatter.new(attributes.keys).format
|
14
|
+
end
|
15
|
+
|
16
|
+
def cells
|
17
|
+
@cells ||= begin
|
18
|
+
schema = collection.first.db_schema
|
19
|
+
|
20
|
+
collection.map do |item|
|
21
|
+
item.values.map do |column, value|
|
22
|
+
CellFormatter.new(value, type: schema.dig(column, :type)).format
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def summary
|
29
|
+
collection.size
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nazar/formatter/sequel_interface'
|
4
|
+
|
5
|
+
module Nazar
|
6
|
+
module Formatter
|
7
|
+
class SequelItem
|
8
|
+
include SequelInterface
|
9
|
+
|
10
|
+
def initialize(item)
|
11
|
+
@collection = [item]
|
12
|
+
@attributes = item.values
|
13
|
+
@klass = item.class
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.valid?(data)
|
17
|
+
data.is_a?(Sequel::Model)
|
18
|
+
end
|
19
|
+
|
20
|
+
def summary
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/nazar/version.rb
CHANGED
data/lib/nazar/view.rb
CHANGED
@@ -27,48 +27,13 @@ module Nazar
|
|
27
27
|
attr_reader :data
|
28
28
|
|
29
29
|
def formatter_klass
|
30
|
-
@formatter_klass ||=
|
31
|
-
when boolean?
|
32
|
-
nil
|
33
|
-
when acttive_record_collection?
|
34
|
-
Formatter::ActiveRecordCollection
|
35
|
-
when active_record_item?
|
36
|
-
Formatter::ActiveRecordItem
|
37
|
-
when csv_table?
|
38
|
-
Formatter::CSVTable
|
39
|
-
end
|
30
|
+
@formatter_klass ||= Nazar.formatters.find { |klass| klass.valid?(data) }
|
40
31
|
end
|
41
32
|
|
42
33
|
def formatter
|
43
34
|
@formatter ||= formatter_klass.new(data)
|
44
35
|
end
|
45
36
|
|
46
|
-
def boolean?
|
47
|
-
proc { data === true || data === false } # rubocop:disable Style/CaseEquality
|
48
|
-
end
|
49
|
-
|
50
|
-
def acttive_record_collection?
|
51
|
-
return false unless Nazar.extensions.include?(:active_record)
|
52
|
-
|
53
|
-
proc do
|
54
|
-
data.is_a?(ActiveRecord::Associations::CollectionProxy) ||
|
55
|
-
data.is_a?(ActiveRecord::Relation) ||
|
56
|
-
(data.is_a?(Array) && data.first.is_a?(ActiveRecord::Base))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def active_record_item?
|
61
|
-
return false unless Nazar.extensions.include?(:active_record)
|
62
|
-
|
63
|
-
proc { data.is_a?(ActiveRecord::Base) }
|
64
|
-
end
|
65
|
-
|
66
|
-
def csv_table?
|
67
|
-
return false unless Nazar.extensions.include?(:csv)
|
68
|
-
|
69
|
-
proc { data.is_a?(CSV::Table) }
|
70
|
-
end
|
71
|
-
|
72
37
|
def add_summary
|
73
38
|
table.add_separator
|
74
39
|
table.add_row [pastel.bold('Total'), { value: summary, colspan: headers.size - 1 }]
|
data/lib/nazar.rb
CHANGED
@@ -25,8 +25,8 @@ module Nazar
|
|
25
25
|
end
|
26
26
|
|
27
27
|
class << self
|
28
|
-
def
|
29
|
-
@
|
28
|
+
def formatters
|
29
|
+
@formatters ||= Set.new
|
30
30
|
end
|
31
31
|
|
32
32
|
def enable!(extensions: [:active_record, :csv])
|
@@ -34,6 +34,7 @@ module Nazar
|
|
34
34
|
|
35
35
|
load_active_record! if extensions.include?(:active_record)
|
36
36
|
load_csv! if extensions.include?(:csv)
|
37
|
+
load_sequel! if extensions.include?(:sequel)
|
37
38
|
|
38
39
|
enable_for_irb! if defined?(IRB)
|
39
40
|
enable_for_pry! if defined?(Pry)
|
@@ -42,18 +43,29 @@ module Nazar
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def load_csv!
|
45
|
-
extensions << :csv
|
46
|
-
|
47
46
|
require 'csv'
|
48
|
-
|
47
|
+
|
48
|
+
register_formatter!('CSVTable', 'nazar/formatter/csv_table')
|
49
49
|
end
|
50
50
|
|
51
51
|
def load_active_record!
|
52
|
-
extensions << :active_record
|
53
|
-
|
54
52
|
require 'active_record'
|
55
|
-
|
56
|
-
|
53
|
+
|
54
|
+
register_formatter!('ActiveRecordCollection', 'nazar/formatter/active_record_collection')
|
55
|
+
register_formatter!('ActiveRecordItem', 'nazar/formatter/active_record_item')
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_sequel!
|
59
|
+
require 'sequel'
|
60
|
+
|
61
|
+
register_formatter!('SequelCollection', 'nazar/formatter/sequel_collection')
|
62
|
+
register_formatter!('SequelItem', 'nazar/formatter/sequel_item')
|
63
|
+
end
|
64
|
+
|
65
|
+
def register_formatter!(klass_name, path)
|
66
|
+
require path
|
67
|
+
|
68
|
+
formatters << Nazar::Formatter.const_get(klass_name)
|
57
69
|
end
|
58
70
|
|
59
71
|
def enable_for_irb!
|
data/nazar.gemspec
CHANGED
@@ -28,7 +28,9 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.add_development_dependency 'activerecord', '>= 3.0', '< 6.2'
|
30
30
|
spec.add_development_dependency 'rubocop', '~> 1.21'
|
31
|
-
spec.add_development_dependency '
|
31
|
+
spec.add_development_dependency 'sequel', '~> 5.0'
|
32
|
+
spec.add_development_dependency 'simplecov', '~> 0.20'
|
33
|
+
spec.add_development_dependency 'sqlite3', '~> 1.0'
|
32
34
|
|
33
35
|
spec.add_runtime_dependency 'dry-configurable', '~> 0.12'
|
34
36
|
spec.add_runtime_dependency 'pastel', '~> 0.8'
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nazar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michał Krzyżanowski
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
FlwFUDGjWAe8lcsjyGp1dox0FK91TAHdZW1op8LYnOcO2DM8Mgzu4Gp7mibATEnx
|
37
37
|
ooN2pwmH
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2021-09-
|
39
|
+
date: 2021-09-24 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
@@ -72,20 +72,48 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '1.21'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: sequel
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '5.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '5.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: simplecov
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.20'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.20'
|
75
103
|
- !ruby/object:Gem::Dependency
|
76
104
|
name: sqlite3
|
77
105
|
requirement: !ruby/object:Gem::Requirement
|
78
106
|
requirements:
|
79
|
-
- - "
|
107
|
+
- - "~>"
|
80
108
|
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
109
|
+
version: '1.0'
|
82
110
|
type: :development
|
83
111
|
prerelease: false
|
84
112
|
version_requirements: !ruby/object:Gem::Requirement
|
85
113
|
requirements:
|
86
|
-
- - "
|
114
|
+
- - "~>"
|
87
115
|
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
116
|
+
version: '1.0'
|
89
117
|
- !ruby/object:Gem::Dependency
|
90
118
|
name: dry-configurable
|
91
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,6 +195,9 @@ files:
|
|
167
195
|
- lib/nazar/formatter/active_record_interface.rb
|
168
196
|
- lib/nazar/formatter/active_record_item.rb
|
169
197
|
- lib/nazar/formatter/csv_table.rb
|
198
|
+
- lib/nazar/formatter/sequel_collection.rb
|
199
|
+
- lib/nazar/formatter/sequel_interface.rb
|
200
|
+
- lib/nazar/formatter/sequel_item.rb
|
170
201
|
- lib/nazar/headers_formatter.rb
|
171
202
|
- lib/nazar/renderer.rb
|
172
203
|
- lib/nazar/version.rb
|
metadata.gz.sig
CHANGED
Binary file
|