nazar 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f20eb7af67e1ef9f7acb2831217ce27b05f654b7f076b4c85f82910bfd1e67b7
4
- data.tar.gz: 264bca42da833684146e1aeb1d711fffa7f8811055a7c785bb423e263c1a42b5
3
+ metadata.gz: bc538e2fec48e0daf00bd670d1c5aa204f9caa6a045397cfcf32e92d433b379f
4
+ data.tar.gz: 17658ef498b4c1f9f14a8ba91e3ad53aa3de347a95302042647b8e30decd6d91
5
5
  SHA512:
6
- metadata.gz: '0779267b1cb0b41686eda05457056b451353f54164faaa8fbd18a0dd24828fbaaf75d6ab03b7d4aa11da340abf9cc9fdfdc3eb38a2174b9e684649848cdc897a'
7
- data.tar.gz: e3a44313685cb330e4ad47cdcdbeaa11e584060816ebdaa8020726be55b49be90dc04373c6d3f3c0c9d3e23d9aa3bb7b1feb8a2752de6a864a3f5634d20e51d2
6
+ metadata.gz: bdd620ad635fdfde0337d339c28b570e412bbd7d7d1e6701f76cf9ad028eb92c22a77e013ad7ef7e460dd1114e2e9ffb66039ca18276455a255445ce156ccc1c
7
+ data.tar.gz: 9737cb971cc7a46118640e352e90745915101f409ba5297b432e046343715e53261f17c4bad80f332ec1878ff2e8911742be5f6bdefe42e50fa280f3674187fd
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- W��:�Uw xk��Jx�SY���9`9�~s�]a[y4��bx��m��䠷���9Y��~꒡N#.��e�|�&��S#!#yg2f:����V�`�Ǻjq�;�/uJd����0bN����T��1�)��&�{$�k���@������ U��dJx@���_��bQ^A��9
2
- #K�.�n%Kr)s��J��̌�{8S��xMP��'csb7g�柹�3`�g�|������̴#p鏠HƇ�yϢ5i���j.�M9�`٣ Iz��?��Wl���}3��l��c�4�
1
+ �y1����J�� ;���5���:b��܈ې��*Wީg=JT�od�]�uV��Vnc-zC͉�r�r_����aJCM��g��Ǹd�%#z�<�[*-(���/
2
+ ȁ8k~A �h)Ǫ"Zy�W����M;0o��;�^�)NL}��� ѵ��g ;�9Z⋠� ��V� ]f�I���4���U���t�Q� TU��y���L.���r���4E��#<���B���>��y[��t<�}Rձa�||�ݦu~g��HЊH�Nr�1{|U1(���<P�MG~Xh�K�O��bU�10![|��>�T��Z�� V6�Ԟ��[j&�c@x 0���I�=�~O2��D'�����@��`��Hc��տ!.��
@@ -0,0 +1,38 @@
1
+ # This is a basic workflow to help you get started with Actions
2
+
3
+ name: CI
4
+
5
+ # Controls when the workflow will run
6
+ on: [push]
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.7
16
+ bundler-cache: true
17
+
18
+ - name: Bundle
19
+ run: bundle
20
+ rubocop:
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: 2.7
27
+ bundler-cache: true
28
+ - run: bundle exec rubocop --format simple
29
+ specs:
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - uses: actions/checkout@v2
33
+ - uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: 2.7
36
+ bundler-cache: true
37
+ - name: Specs
38
+ run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -1,4 +1,15 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
3
  Style/Documentation:
4
- Enabled: false
4
+ Enabled: false
5
+ Style/SymbolArray:
6
+ EnforcedStyle: brackets
7
+ Style/WordArray:
8
+ EnforcedStyle: brackets
9
+ Metrics/BlockLength:
10
+ Exclude:
11
+ - 'spec/**/*_spec.rb'
12
+ Layout/CaseIndentation:
13
+ EnforcedStyle: end
14
+ Layout/EndAlignment:
15
+ EnforcedStyleAlignWith: variable
data/README.md CHANGED
@@ -1,36 +1,12 @@
1
- # Nazar
1
+ # Nazar [![Build Status](https://github.com/krzyzak/nazar/actions/workflows/main.yml/badge.svg)](https://github.com/krzyzak/nazar/actions) [![Code Climate](https://codeclimate.com/github/krzyzak/nazar/badges/gpa.svg)](https://codeclimate.com/github/krzyzak/nazar)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nazar`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Nazar improves defvault inspect output for console applications (supports IRB and Pry).
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ **Nazar is under heavy development now. Expect bumpy ride or wait until the API will stabilise a bit ;)**
6
6
 
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'nazar'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install nazar
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
7
+ [![asciicast](https://asciinema.org/a/436814.png)](https://asciinema.org/a/436814)
32
8
 
33
9
  ## Contributing
34
10
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nazar.
11
+ Bug reports and pull requests are welcome on GitHub at https://github.com/krzyzak/nazar.
36
12
 
@@ -11,8 +11,8 @@ module Nazar
11
11
  case type
12
12
  when :boolean
13
13
  format_boolean(value)
14
- when :numeric
15
- Pastel.new.bright_blue(value)
14
+ when :integer
15
+ Pastel.new(enabled: Nazar.config.colors.enabled).bright_blue(value)
16
16
  else
17
17
  value.nil? ? format_nil : value.to_s
18
18
  end
@@ -26,11 +26,11 @@ module Nazar
26
26
  return format_nil if value.nil?
27
27
 
28
28
  true_value, false_value = Nazar.config.formatter.boolean
29
- Formatter::TRUTHY_VALUES.include?(value) ? true_value : false_value
29
+ Formatter::TRUTHY_VALUES.include?(value.to_s.downcase) ? true_value : false_value
30
30
  end
31
31
 
32
32
  def format_nil
33
- Pastel.new.dim(Nazar.config.formatter.nil)
33
+ Pastel.new(enabled: Nazar.config.colors.enabled).dim(Nazar.config.formatter.nil)
34
34
  end
35
35
  end
36
36
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'nazar/formatter/active_record_interface'
3
4
 
4
5
  module Nazar
@@ -8,8 +9,10 @@ module Nazar
8
9
 
9
10
  def initialize(collection)
10
11
  @collection = collection
11
- @attributes = collection.first.attributes
12
- @klass = collection.first.class
12
+ @collection.load if @collection.respond_to?(:loaded?) && !@collection.loaded?
13
+
14
+ @attributes = collection.first&.attributes
15
+ @klass = collection.first&.class
13
16
  end
14
17
 
15
18
  def summary
@@ -1,8 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nazar
2
4
  module Formatter
3
5
  module ActiveRecordInterface
4
6
  attr_reader :collection, :klass, :attributes
5
7
 
8
+ def valid?
9
+ !!(attributes && klass)
10
+ end
11
+
6
12
  def headers
7
13
  HeadersFormatter.new(attributes.keys).format
8
14
  end
@@ -16,4 +22,4 @@ module Nazar
16
22
  end
17
23
  end
18
24
  end
19
- end
25
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'nazar/formatter/active_record_interface'
3
4
 
4
5
  module Nazar
@@ -9,6 +9,10 @@ module Nazar
9
9
  @collection = collection
10
10
  end
11
11
 
12
+ def valid?
13
+ collection.present?
14
+ end
15
+
12
16
  def headers
13
17
  HeadersFormatter.new(collection.headers).format
14
18
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Nazar
4
4
  module Formatter
5
- TRUTHY_VALUES = ['true', 'yes', true].freeze
6
- FALSY_VALUES = ['false', 'no', false].freeze
5
+ TRUTHY_VALUES = ['true', 'yes'].freeze
6
+ FALSY_VALUES = ['false', 'no'].freeze
7
7
  end
8
8
  end
@@ -15,7 +15,7 @@ module Nazar
15
15
  attr_reader :headers
16
16
 
17
17
  def pastel
18
- @pastel ||= Pastel.new
18
+ @pastel ||= Pastel.new(enabled: Nazar.config.colors.enabled)
19
19
  end
20
20
  end
21
21
  end
@@ -18,10 +18,6 @@ module Nazar
18
18
 
19
19
  attr_reader :data
20
20
 
21
- def render_table?
22
- view.enabled?
23
- end
24
-
25
21
  def view
26
22
  @view ||= View.new(data)
27
23
  end
data/lib/nazar/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nazar
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.4'
5
5
  end
data/lib/nazar/view.rb CHANGED
@@ -13,13 +13,13 @@ module Nazar
13
13
  def render
14
14
  return unless supported_data?
15
15
 
16
- add_summary if summary
17
-
18
- table
16
+ table.tap do
17
+ add_summary if summary
18
+ end
19
19
  end
20
20
 
21
21
  def supported_data?
22
- !!formatter_klass
22
+ !!formatter_klass && formatter.valid?
23
23
  end
24
24
 
25
25
  private
@@ -27,21 +27,23 @@ module Nazar
27
27
  attr_reader :data
28
28
 
29
29
  def formatter_klass
30
- case data
30
+ @formatter_klass ||= case data
31
31
  when acttive_record_collection?
32
32
  Formatter::ActiveRecordCollection
33
33
  when active_record_item?
34
34
  Formatter::ActiveRecordItem
35
- when CSV::Table
35
+ when csv_table?
36
36
  Formatter::CSVTable
37
37
  end
38
38
  end
39
39
 
40
40
  def formatter
41
- formatter_klass.new(data)
41
+ @formatter ||= formatter_klass.new(data)
42
42
  end
43
43
 
44
44
  def acttive_record_collection?
45
+ return false unless Nazar.extensions.include?(:active_record)
46
+
45
47
  proc do
46
48
  data.is_a?(ActiveRecord::Associations::CollectionProxy) ||
47
49
  data.is_a?(ActiveRecord::Relation) ||
@@ -50,12 +52,20 @@ module Nazar
50
52
  end
51
53
 
52
54
  def active_record_item?
55
+ return false unless Nazar.extensions.include?(:active_record)
56
+
53
57
  proc { data.is_a?(ActiveRecord::Base) }
54
58
  end
55
59
 
60
+ def csv_table?
61
+ return false unless Nazar.extensions.include?(:csv)
62
+
63
+ proc { data.is_a?(CSV::Table) }
64
+ end
65
+
56
66
  def add_summary
57
67
  table.add_separator
58
- table.add_row [Pastel.new.bold('Total'), { value: summary, colspan: headers.size - 1 }]
68
+ table.add_row [pastel.bold('Total'), { value: summary, colspan: headers.size - 1 }]
59
69
  end
60
70
 
61
71
  def table
@@ -65,5 +75,9 @@ module Nazar
65
75
  style: { border: :unicode_thick_edge }
66
76
  )
67
77
  end
78
+
79
+ def pastel
80
+ @pastel ||= Pastel.new(enabled: Nazar.config.colors.enabled)
81
+ end
68
82
  end
69
83
  end
data/lib/nazar.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record'
4
- require 'csv'
5
3
  require 'dry-configurable'
6
4
  require 'terminal-table'
7
5
  require 'pastel'
@@ -12,9 +10,6 @@ require 'nazar/cell_formatter'
12
10
  require 'nazar/headers_formatter'
13
11
  require 'nazar/renderer'
14
12
  require 'nazar/formatter'
15
- require 'nazar/formatter/csv_table'
16
- require 'nazar/formatter/active_record_collection'
17
- require 'nazar/formatter/active_record_item'
18
13
  require 'nazar/view'
19
14
 
20
15
  module Nazar
@@ -25,44 +20,71 @@ module Nazar
25
20
  setting :boolean, default: ['✓', '✗']
26
21
  end
27
22
 
28
- def self.enable!
29
- return if @enabled
23
+ setting :colors do
24
+ setting :enabled, default: ENV.fetch('ENABLE_TTY_COLORS') { TTY::Color.color? ? 'true' : 'false' } == 'true'
25
+ end
30
26
 
31
- enable_for_irb! if defined?(IRB)
32
- enable_for_pry! if defined?(Pry)
27
+ class << self
28
+ def extensions
29
+ @extensions ||= Set.new
30
+ end
33
31
 
34
- @enabled = true
35
- end
32
+ def enable!(extensions: [:active_record, :csv])
33
+ return if @enabled
34
+
35
+ load_active_record! if extensions.include?(:active_record) || defined?(ActiveRecord)
36
+
37
+ enable_for_irb! if defined?(IRB)
38
+ enable_for_pry! if defined?(Pry)
39
+
40
+ @enabled = true
41
+ end
42
+
43
+ def load_csv!
44
+ extensions << :csv
45
+
46
+ require 'csv'
47
+ require 'nazar/formatter/csv_table'
48
+ end
49
+
50
+ def load_active_record!
51
+ extensions << :active_record
36
52
 
37
- def self.enable_for_irb!
38
- ::IRB::Irb.class_eval do
39
- alias_method :__original_output_value__, :output_value
40
- def output_value(omit = false) # rubocop:disable Style/OptionalBooleanParameter
41
- ::Nazar::Renderer.new(@context.last_value).render || __original_output_value__(omit)
53
+ require 'active_record'
54
+ require 'nazar/formatter/active_record_collection'
55
+ require 'nazar/formatter/active_record_item'
56
+ end
57
+
58
+ def enable_for_irb!
59
+ ::IRB::Irb.class_eval do
60
+ alias_method :__original_output_value__, :output_value
61
+ def output_value(omit = false) # rubocop:disable Style/OptionalBooleanParameter
62
+ ::Nazar::Renderer.new(@context.last_value).render || __original_output_value__(omit)
63
+ end
42
64
  end
43
65
  end
44
- end
45
66
 
46
- def self.enable_for_pry!
47
- @__original_pry_print = Pry.config.print
48
- Pry.config.print = proc do |output, value, instance|
49
- output.puts Nazar::Renderer.new(value).render || @__original_pry_print.call(output, value, instance)
67
+ def enable_for_pry!
68
+ @__original_pry_print = Pry.config.print
69
+ Pry.config.print = proc do |output, value, instance|
70
+ output.puts Nazar::Renderer.new(value).render || @__original_pry_print.call(output, value, instance)
71
+ end
50
72
  end
51
- end
52
73
 
53
- def self.disable!
54
- return unless @enabled
74
+ def disable!
75
+ return unless @enabled
55
76
 
56
- disable_for_irb! if defined?(IRB)
77
+ disable_for_irb! if defined?(IRB)
57
78
 
58
- @enabled = false
59
- end
79
+ @enabled = false
80
+ end
60
81
 
61
- def self.disable_for_irb!
62
- ::IRB::Irb.send(:alias_method, :output_value, :__original_output_value__)
63
- end
82
+ def disable_for_irb!
83
+ ::IRB::Irb.send(:alias_method, :output_value, :__original_output_value__)
84
+ end
64
85
 
65
- def self.disable_for_pry!
66
- nil
86
+ def disable_for_pry!
87
+ nil
88
+ end
67
89
  end
68
90
  end
data/nazar.gemspec CHANGED
@@ -24,11 +24,12 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ['lib']
25
25
 
26
26
  spec.cert_chain = ['certs/krzyzak.pem']
27
- spec.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
27
+ spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $PROGRAM_NAME =~ /gem\z/
28
28
 
29
+ spec.add_development_dependency 'activerecord', '>= 3.0', '< 6.2'
29
30
  spec.add_development_dependency 'rubocop', '~> 1.21'
31
+ spec.add_development_dependency 'sqlite3'
30
32
 
31
- spec.add_runtime_dependency 'activerecord', '>= 3.0', '< 6.2'
32
33
  spec.add_runtime_dependency 'dry-configurable', '~> 0.12'
33
34
  spec.add_runtime_dependency 'pastel', '~> 0.8'
34
35
  spec.add_runtime_dependency 'terminal-table', '~> 3.0'
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.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Krzyżanowski
@@ -36,8 +36,28 @@ cert_chain:
36
36
  FlwFUDGjWAe8lcsjyGp1dox0FK91TAHdZW1op8LYnOcO2DM8Mgzu4Gp7mibATEnx
37
37
  ooN2pwmH
38
38
  -----END CERTIFICATE-----
39
- date: 2021-09-17 00:00:00.000000000 Z
39
+ date: 2021-09-21 00:00:00.000000000 Z
40
40
  dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '6.2'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '3.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '6.2'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: rubocop
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -53,25 +73,19 @@ dependencies:
53
73
  - !ruby/object:Gem::Version
54
74
  version: '1.21'
55
75
  - !ruby/object:Gem::Dependency
56
- name: activerecord
76
+ name: sqlite3
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - ">="
60
80
  - !ruby/object:Gem::Version
61
- version: '3.0'
62
- - - "<"
63
- - !ruby/object:Gem::Version
64
- version: '6.2'
65
- type: :runtime
81
+ version: '0'
82
+ type: :development
66
83
  prerelease: false
67
84
  version_requirements: !ruby/object:Gem::Requirement
68
85
  requirements:
69
86
  - - ">="
70
87
  - !ruby/object:Gem::Version
71
- version: '3.0'
72
- - - "<"
73
- - !ruby/object:Gem::Version
74
- version: '6.2'
88
+ version: '0'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: dry-configurable
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +149,7 @@ executables: []
135
149
  extensions: []
136
150
  extra_rdoc_files: []
137
151
  files:
152
+ - ".github/workflows/main.yml"
138
153
  - ".gitignore"
139
154
  - ".rspec"
140
155
  - ".rubocop.yml"
metadata.gz.sig CHANGED
Binary file