helium-console-rails 0.1.0 → 0.1.1

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: 4a790a5a4dca933ca5340cb3349bdf800de1862c43c527d3be8cd1ea9d063d12
4
- data.tar.gz: 92a6e194763772ce04ccaf816eef5a19107bc6096fc94b52d7e2b52334dbf1fe
3
+ metadata.gz: 46c06d5fd799034446196de7003ba5c7aa2b6a5bc6be74d94553f5ecf7edc42c
4
+ data.tar.gz: 930923bae21e97256e349e9c251e7ad1dfadf95041f34bf2c77a39c0388deea7
5
5
  SHA512:
6
- metadata.gz: 8c2d077e94a5514a1202ffdeded91156305d0b97d8410740cb7ef6c2761159fd60db2fd755a2082e86f55f417869142e1b14158afd32638a7bce022955d38b3e
7
- data.tar.gz: 62f704ca4d66a679470a5e1422f336a5cede332ae6023b402e8b1f1da32afeb7fb911b7fe40ad6ac15d098693beed472be283cf69f8145081b73b4b1a799899c
6
+ metadata.gz: 67d00c40acce53d73337737e99966f0356d58d724b060a54c3db67b5b0065ce33d902d4ccf6fc670c64f5c5814991a2cdeb8fa8ba5324d375356a627f0dd3580
7
+ data.tar.gz: 9974e2cd0f860a1cc8bc6906489b3c9c1b66bac323f659233e0d18c3e08d036e51e2a8deb9781a9b52e1a5023d6fb89275bcde2eea8a1ef6743b957c6f5a493f
data/.rubocop.yml ADDED
@@ -0,0 +1,70 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-rake
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+
8
+ Style/LambdaCall:
9
+ EnforcedStyle: braces
10
+
11
+ Layout/CaseIndentation:
12
+ EnforcedStyle: end
13
+ IndentOneStep: true
14
+
15
+ Style/NestedParenthesizedCalls:
16
+ AllowedMethods:
17
+ - be
18
+ - be_a
19
+ - be_an
20
+ - be_between
21
+ - be_falsey
22
+ - be_kind_of
23
+ - be_instance_of
24
+ - be_truthy
25
+ - be_within
26
+ - eq
27
+ - eql
28
+ - end_with
29
+ - expect
30
+ - include
31
+ - match
32
+ - raise_error
33
+ - respond_to
34
+ - start_with
35
+
36
+ Layout/EndAlignment:
37
+ EnforcedStyleAlignWith: start_of_line
38
+
39
+ Layout/MultilineMethodCallIndentation:
40
+ EnforcedStyle: indented
41
+
42
+ Style/Documentation:
43
+ Enabled: false
44
+
45
+ Bundler/OrderedGems:
46
+ Enabled: false
47
+
48
+ Style/EmptyMethod:
49
+ EnforcedStyle: expanded
50
+
51
+ Metrics/BlockLength:
52
+ IgnoredMethods:
53
+ - define_formatter_for
54
+ Exclude:
55
+ - "*.gemspec"
56
+ - "spec/**/*_spec.rb"
57
+
58
+ Metrics/MethodLength:
59
+ Max: 15
60
+
61
+ RSpec/MultipleExpectations:
62
+ Enabled: false
63
+
64
+ Style/NumericPredicate:
65
+ Enabled: false
66
+
67
+ Style/EachWithObject:
68
+ Enabled: false
69
+
70
+
data/Gemfile CHANGED
@@ -1,6 +1,12 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in helium-console-rails.gemspec
4
6
  gemspec
5
7
 
6
- gem 'helium-console', path: "../console"
8
+ # gem 'helium-console', path: '../console'
9
+ gem 'rubocop'
10
+ gem 'rubocop-rake'
11
+ gem 'rubocop-rspec'
12
+ gem 'rails'
data/Gemfile.lock CHANGED
@@ -1,48 +1,200 @@
1
- PATH
2
- remote: ../console
3
- specs:
4
- helium-console (0.1.1)
5
- pry
6
-
7
1
  PATH
8
2
  remote: .
9
3
  specs:
10
- helium-console-rails (0.1.0)
11
- helium-console (~> 0.1.1)
4
+ helium-console-rails (0.1.1)
5
+ helium-console (~> 0.1.12)
6
+ pry-rails (~> 0.3.9)
12
7
 
13
8
  GEM
14
9
  remote: https://rubygems.org/
15
10
  specs:
11
+ actioncable (6.1.4.4)
12
+ actionpack (= 6.1.4.4)
13
+ activesupport (= 6.1.4.4)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (6.1.4.4)
17
+ actionpack (= 6.1.4.4)
18
+ activejob (= 6.1.4.4)
19
+ activerecord (= 6.1.4.4)
20
+ activestorage (= 6.1.4.4)
21
+ activesupport (= 6.1.4.4)
22
+ mail (>= 2.7.1)
23
+ actionmailer (6.1.4.4)
24
+ actionpack (= 6.1.4.4)
25
+ actionview (= 6.1.4.4)
26
+ activejob (= 6.1.4.4)
27
+ activesupport (= 6.1.4.4)
28
+ mail (~> 2.5, >= 2.5.4)
29
+ rails-dom-testing (~> 2.0)
30
+ actionpack (6.1.4.4)
31
+ actionview (= 6.1.4.4)
32
+ activesupport (= 6.1.4.4)
33
+ rack (~> 2.0, >= 2.0.9)
34
+ rack-test (>= 0.6.3)
35
+ rails-dom-testing (~> 2.0)
36
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
+ actiontext (6.1.4.4)
38
+ actionpack (= 6.1.4.4)
39
+ activerecord (= 6.1.4.4)
40
+ activestorage (= 6.1.4.4)
41
+ activesupport (= 6.1.4.4)
42
+ nokogiri (>= 1.8.5)
43
+ actionview (6.1.4.4)
44
+ activesupport (= 6.1.4.4)
45
+ builder (~> 3.1)
46
+ erubi (~> 1.4)
47
+ rails-dom-testing (~> 2.0)
48
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
+ activejob (6.1.4.4)
50
+ activesupport (= 6.1.4.4)
51
+ globalid (>= 0.3.6)
52
+ activemodel (6.1.4.4)
53
+ activesupport (= 6.1.4.4)
54
+ activerecord (6.1.4.4)
55
+ activemodel (= 6.1.4.4)
56
+ activesupport (= 6.1.4.4)
57
+ activestorage (6.1.4.4)
58
+ actionpack (= 6.1.4.4)
59
+ activejob (= 6.1.4.4)
60
+ activerecord (= 6.1.4.4)
61
+ activesupport (= 6.1.4.4)
62
+ marcel (~> 1.0.0)
63
+ mini_mime (>= 1.1.0)
64
+ activesupport (6.1.4.4)
65
+ concurrent-ruby (~> 1.0, >= 1.0.2)
66
+ i18n (>= 1.6, < 2)
67
+ minitest (>= 5.1)
68
+ tzinfo (~> 2.0)
69
+ zeitwerk (~> 2.3)
70
+ ast (2.4.2)
71
+ builder (3.2.4)
16
72
  coderay (1.1.3)
17
- diff-lcs (1.4.4)
73
+ colorize (0.8.1)
74
+ concurrent-ruby (1.1.9)
75
+ crass (1.0.6)
76
+ diff-lcs (1.5.0)
77
+ erubi (1.10.0)
78
+ globalid (1.0.0)
79
+ activesupport (>= 5.0)
80
+ helium-console (0.1.13)
81
+ colorize
82
+ pry
83
+ i18n (1.9.1)
84
+ concurrent-ruby (~> 1.0)
85
+ loofah (2.13.0)
86
+ crass (~> 1.0.2)
87
+ nokogiri (>= 1.5.9)
88
+ mail (2.7.1)
89
+ mini_mime (>= 0.1.1)
90
+ marcel (1.0.2)
18
91
  method_source (1.0.0)
92
+ mini_mime (1.1.2)
93
+ mini_portile2 (2.7.1)
94
+ minitest (5.15.0)
95
+ nio4r (2.5.8)
96
+ nokogiri (1.13.1)
97
+ mini_portile2 (~> 2.7.0)
98
+ racc (~> 1.4)
99
+ parallel (1.21.0)
100
+ parser (3.1.0.0)
101
+ ast (~> 2.4.1)
19
102
  pry (0.14.1)
20
103
  coderay (~> 1.1)
21
104
  method_source (~> 1.0)
105
+ pry-rails (0.3.9)
106
+ pry (>= 0.10.4)
107
+ racc (1.6.0)
108
+ rack (2.2.3)
109
+ rack-test (1.1.0)
110
+ rack (>= 1.0, < 3)
111
+ rails (6.1.4.4)
112
+ actioncable (= 6.1.4.4)
113
+ actionmailbox (= 6.1.4.4)
114
+ actionmailer (= 6.1.4.4)
115
+ actionpack (= 6.1.4.4)
116
+ actiontext (= 6.1.4.4)
117
+ actionview (= 6.1.4.4)
118
+ activejob (= 6.1.4.4)
119
+ activemodel (= 6.1.4.4)
120
+ activerecord (= 6.1.4.4)
121
+ activestorage (= 6.1.4.4)
122
+ activesupport (= 6.1.4.4)
123
+ bundler (>= 1.15.0)
124
+ railties (= 6.1.4.4)
125
+ sprockets-rails (>= 2.0.0)
126
+ rails-dom-testing (2.0.3)
127
+ activesupport (>= 4.2.0)
128
+ nokogiri (>= 1.6)
129
+ rails-html-sanitizer (1.4.2)
130
+ loofah (~> 2.3)
131
+ railties (6.1.4.4)
132
+ actionpack (= 6.1.4.4)
133
+ activesupport (= 6.1.4.4)
134
+ method_source
135
+ rake (>= 0.13)
136
+ thor (~> 1.0)
137
+ rainbow (3.1.1)
22
138
  rake (10.5.0)
139
+ regexp_parser (2.2.0)
140
+ rexml (3.2.5)
23
141
  rspec (3.10.0)
24
142
  rspec-core (~> 3.10.0)
25
143
  rspec-expectations (~> 3.10.0)
26
144
  rspec-mocks (~> 3.10.0)
27
- rspec-core (3.10.1)
145
+ rspec-core (3.10.2)
28
146
  rspec-support (~> 3.10.0)
29
- rspec-expectations (3.10.1)
147
+ rspec-expectations (3.10.2)
30
148
  diff-lcs (>= 1.2.0, < 2.0)
31
149
  rspec-support (~> 3.10.0)
32
- rspec-mocks (3.10.2)
150
+ rspec-mocks (3.10.3)
33
151
  diff-lcs (>= 1.2.0, < 2.0)
34
152
  rspec-support (~> 3.10.0)
35
- rspec-support (3.10.2)
153
+ rspec-support (3.10.3)
154
+ rubocop (1.25.1)
155
+ parallel (~> 1.10)
156
+ parser (>= 3.1.0.0)
157
+ rainbow (>= 2.2.2, < 4.0)
158
+ regexp_parser (>= 1.8, < 3.0)
159
+ rexml
160
+ rubocop-ast (>= 1.15.1, < 2.0)
161
+ ruby-progressbar (~> 1.7)
162
+ unicode-display_width (>= 1.4.0, < 3.0)
163
+ rubocop-ast (1.15.1)
164
+ parser (>= 3.0.1.1)
165
+ rubocop-rake (0.6.0)
166
+ rubocop (~> 1.0)
167
+ rubocop-rspec (2.8.0)
168
+ rubocop (~> 1.19)
169
+ ruby-progressbar (1.11.0)
170
+ sprockets (4.0.2)
171
+ concurrent-ruby (~> 1.0)
172
+ rack (> 1, < 3)
173
+ sprockets-rails (3.4.2)
174
+ actionpack (>= 5.2)
175
+ activesupport (>= 5.2)
176
+ sprockets (>= 3.0.0)
177
+ thor (1.2.1)
178
+ tzinfo (2.0.4)
179
+ concurrent-ruby (~> 1.0)
180
+ unicode-display_width (2.1.0)
181
+ websocket-driver (0.7.5)
182
+ websocket-extensions (>= 0.1.0)
183
+ websocket-extensions (0.1.5)
184
+ zeitwerk (2.5.4)
36
185
 
37
186
  PLATFORMS
38
187
  ruby
39
188
 
40
189
  DEPENDENCIES
41
190
  bundler (~> 2.0)
42
- helium-console!
43
191
  helium-console-rails!
192
+ rails
44
193
  rake (~> 10.0)
45
194
  rspec (~> 3.0)
195
+ rubocop
196
+ rubocop-rake
197
+ rubocop-rspec
46
198
 
47
199
  BUNDLED WITH
48
- 2.0.2
200
+ 2.2.20
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "helium/console/rails"
4
+ require 'bundler/setup'
5
+ require 'helium/console/rails'
5
6
 
6
- require "pry"
7
+ require 'pry'
7
8
  Pry.start
@@ -1,31 +1,35 @@
1
- lib = File.expand_path("lib", __dir__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "helium/console/rails/version"
5
+ require 'helium/console/rails/version'
4
6
 
5
7
  Gem::Specification.new do |spec|
6
- spec.name = "helium-console-rails"
8
+ spec.name = 'helium-console-rails'
7
9
  spec.version = Helium::Console::Rails::VERSION
8
- spec.authors = ["Stanislaw Klajn"]
9
- spec.email = ["sklajn@gmail.com"]
10
+ spec.authors = ['Stanislaw Klajn']
11
+ spec.email = ['sklajn@gmail.com']
10
12
 
11
- spec.summary = %q{Formatting for rails objects}
12
- spec.homepage = "https://github.com/helium-rb/console-rails"
13
- spec.license = "MIT"
13
+ spec.summary = 'Formatting for rails objects'
14
+ spec.homepage = 'https://github.com/helium-rb/console-rails'
15
+ spec.license = 'MIT'
14
16
 
15
- spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = "https://github.com/helium-rb/console-rails"
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/helium-rb/console-rails'
19
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
17
20
 
18
21
  # Specify which files should be added to the gem when it is released.
19
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
25
  end
23
- spec.bindir = "exe"
26
+ spec.bindir = 'exe'
24
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
28
+ spec.require_paths = ['lib']
26
29
 
27
- spec.add_dependency "helium-console", "~> 0.1.1"
28
- spec.add_development_dependency "bundler", "~> 2.0"
29
- spec.add_development_dependency "rake", "~> 10.0"
30
- spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_dependency 'helium-console', '~> 0.1.12'
31
+ spec.add_dependency 'pry-rails', '~> 0.3.9'
32
+ spec.add_development_dependency 'bundler', '~> 2.0'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
35
  end
@@ -1,7 +1,16 @@
1
- module Helium::Console::Rails
2
- class Railtie < Rails::Railtie
3
- initializer "helium.console" do
4
- Helium::Console::Rails.load!
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry-rails/railtie'
4
+
5
+ module Helium
6
+ class Console
7
+ module Rails
8
+ class Railtie < ::Rails::Railtie
9
+ console do
10
+ Helium::Console::Rails.load!
11
+ ::Rails.application.config.console = ::Helium::Console
12
+ end
13
+ end
5
14
  end
6
15
  end
7
16
  end
@@ -1,19 +1,67 @@
1
- if defined? ActiveRecord
2
- Helium::Console.define_formatter_for ActiveRecord::Base do
3
- def call
4
- primary_key = object.class.primary_key
1
+ # frozen_string_literal: true
5
2
 
6
- table = Helium::Console::Table.new(runner: '| ', after_key: ": ", format_keys: false)
7
- table.row(primary_key, object.attributes[primary_key]) if primary_key
3
+ Helium::Console.define_formatter_for 'ActiveRecord::Base' do
4
+ def render_compact
5
+ [
6
+ light_black('#'),
7
+ format(object.class, :compact),
8
+ "(#{light_blue primary_key.to_s}: #{format object[primary_key], :compact, max_width: nil})"
9
+ ].join
10
+ end
8
11
 
9
- object.attributes.sort_by(&:first).each do |key, value|
10
- next if key == primary_key
11
- table.row(key.to_s, value)
12
- end
13
- [
14
- "# #{object.class.name}",
15
- format(table, **options)
16
- ].join($/)
12
+ def render_partial
13
+ table = Helium::Console::Table.new(runner: '| ', after_key: ': ', format_keys: false)
14
+
15
+ attributes.each do |key, value|
16
+ table.row(light_blue(key.to_s), value)
17
+ end
18
+
19
+ yield_lines do |y|
20
+ y << "# #{format object.class, short: true}"
21
+ format(table).lines.each { |line| y << line }
17
22
  end
18
23
  end
24
+
25
+ private
26
+
27
+ def attributes
28
+ attrs = object.attributes.symbolize_keys
29
+
30
+ primary_key = extract!(self.primary_key, from: attrs)
31
+ timestamps = extract!(:created_at, :updated_at, from: attrs)
32
+ associations = extract_associations(from: attrs)
33
+
34
+ attrs.delete(inheritance_column) if attrs[inheritance_column] == object.class.name
35
+
36
+ [
37
+ *primary_key,
38
+ *attrs.sort_by(&:first),
39
+ *timestamps,
40
+ *associations
41
+ ]
42
+ end
43
+
44
+ def extract_associations(from:)
45
+ object.class.reflect_on_all_associations
46
+ .map(&:name)
47
+ .sort
48
+ .map { |name| [name.to_sym, object.association(name)] }
49
+ .each do |_name, association|
50
+ from.delete(association.reflection.foreign_key.to_sym) if association.reflection.belongs_to?
51
+ end
52
+ end
53
+
54
+ def extract!(*keys, from:)
55
+ keys
56
+ .map { |key| [key, from.delete(key)] if from.key?(key) }
57
+ .compact
58
+ end
59
+
60
+ def inheritance_column
61
+ object.class.inheritance_column.to_sym
62
+ end
63
+
64
+ def primary_key
65
+ object.class.primary_key.to_sym
66
+ end
19
67
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined? ActiveRecord
4
+ Helium::Console.define_formatter_for ActiveRecord::Associations::HasOneThroughAssociation do
5
+ def call
6
+ return format(object.target) if object.loaded?
7
+
8
+ through = object.reflection.through_reflection.name
9
+ "#{light_magenta 'one'} #{format object.reflection.klass,
10
+ short: true} #{light_magenta 'through'} #{format through}"
11
+ end
12
+ end
13
+
14
+ Helium::Console.define_formatter_for ActiveRecord::Associations::HasOneAssociation do
15
+ def call
16
+ return format(object.target) if object.loaded?
17
+
18
+ foreign_key = object.reflection.foreign_key
19
+ pk_value = object.owner[object.reflection.association_primary_key]
20
+ "#{light_magenta 'one'} #{format object.reflection.klass,
21
+ short: true}(#{light_blue foreign_key}: #{format pk_value})"
22
+ end
23
+ end
24
+
25
+ Helium::Console.define_formatter_for ActiveRecord::Associations::HasManyAssociation do
26
+ def call
27
+ return format(object.target) if object.loaded?
28
+
29
+ foreign_key = object.reflection.foreign_key
30
+ pk_value = object.owner[object.reflection.association_primary_key]
31
+ "#{light_magenta 'many'} #{format object.reflection.klass,
32
+ short: true}(#{light_blue foreign_key}: #{format pk_value})"
33
+ end
34
+ end
35
+
36
+ Helium::Console.define_formatter_for ActiveRecord::Associations::HasManyThroughAssociation do
37
+ def call
38
+ return format(object.target) if object.loaded?
39
+
40
+ through = object.reflection.through_reflection.name
41
+ "#{light_magenta 'many'} #{format object.reflection.klass,
42
+ short: true} #{light_magenta 'through'} #{format through}"
43
+ end
44
+ end
45
+
46
+ Helium::Console.define_formatter_for ActiveRecord::Associations::BelongsToPolymorphicAssociation do
47
+ def call
48
+ return format(object.target) if object.loaded?
49
+ return format(nil) if object.klass.nil?
50
+
51
+ primary_key = object.klass.primary_key
52
+ fk_value = object.owner[object.reflection.foreign_key]
53
+
54
+ "#{light_magenta 'one'} #{format object.klass, short: true}(#{light_blue primary_key}: #{format fk_value})"
55
+ end
56
+ end
57
+
58
+ Helium::Console.define_formatter_for ActiveRecord::Associations::Association do
59
+ def call
60
+ object.reflection.macro.to_s
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,39 @@
1
+ Helium::Console.define_formatter_for 'ActiveRecord::Associations::BelongsToAssociation' do
2
+ def render_compact
3
+ return format(object.target, :compact) if object.loaded?
4
+
5
+ [
6
+ light_magenta('one'),
7
+ format(object.reflection.klass, :compact)
8
+ ].join(' ')
9
+ end
10
+
11
+ def render_inline
12
+ return format(object.target, :inline) if object.loaded?
13
+
14
+ [
15
+ light_magenta('one'),
16
+ format(object.reflection.klass, :compact),
17
+ "(#{light_blue primary_key}: #{format foreign_key_value})"
18
+ ].join(' ')
19
+ end
20
+
21
+ def render_full
22
+ [
23
+ format(object.owner, :compact),
24
+ light_magenta('belongs to'),
25
+ light_blue(object.reflection.name.to_s),
26
+ light_magenta('association'),
27
+ ].join(' ')
28
+ end
29
+
30
+ private
31
+
32
+ def primary_key
33
+ object.reflection.association_primary_key
34
+ end
35
+
36
+ def foreign_key_value
37
+ object.owner[object.reflection.foreign_key]
38
+ end
39
+ end
@@ -1,26 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined? ActiveRecord
2
4
  Helium::Console.define_formatter_for ActiveRecord::Relation do
3
5
  def call
4
- # primary_key = object.class.primary_key
6
+ return format_loaded if object.loaded?
5
7
 
6
- table = Helium::Console::Table.new(runner: " ", after_key: ": ", format_keys: false)
7
- formatted = object.map { |record| format_record(record) }
8
- [
9
- ["#", object.klass.name, "relation (#{object.size} element#{:s if object.size > 1})"].join(" "),
10
- formatted.join("#{$/}|#{$/}")
11
- ].join($/)
8
+ if level == 1
9
+ object.load
10
+ format_loaded
11
+ else
12
+ format_unloaded
13
+ end
12
14
  end
13
15
 
14
- def format_record(record)
15
- table = Helium::Console::Table.new(runner: '| ', after_key: ": ", format_keys: false)
16
- table.row(primary_key, record.attributes[primary_key]) if primary_key
16
+ def format_loaded
17
+ yield_lines do |y|
18
+ y << "# #{format(object.klass, short: true)} relation (#{object.size} element#{:s if object.size > 1})"
19
+ format(object.to_a).lines.each.with_index do |line, index|
20
+ next if index.zero?
17
21
 
18
- record.attributes.sort_by(&:first).each do |key, value|
19
- next if key == primary_key
20
- table.row(key.to_s, value)
22
+ y << line
23
+ end
21
24
  end
25
+ end
22
26
 
23
- format(table, **options, max_width: max_width - 2)
27
+ def format_unloaded
28
+ "# #{format(object.klass, short: true)} relation #{red('(not loaded)')}"
24
29
  end
25
30
 
26
31
  def primary_key
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ Helium::Console.define_formatter_for ActiveSupport::TimeWithZone do
4
+ def call
5
+ "#{format object.time} #{blue "(#{object.time_zone.name})"}"
6
+ end
7
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Helium
2
4
  class Console
3
5
  module Rails
4
- VERSION = "0.1.0"
6
+ VERSION = '0.1.1'
5
7
  end
6
8
  end
7
9
  end
@@ -1,12 +1,14 @@
1
- require "helium/console"
2
- require "helium/console/rails/version"
3
- require "helium/console/rails/railtie"
1
+ # frozen_string_literal: true
2
+
3
+ require 'helium/console'
4
+ require 'helium/console/rails/version'
5
+ require 'helium/console/rails/railtie'
4
6
 
5
7
  module Helium
6
8
  class Console
7
9
  module Rails
8
10
  def self.load!
9
- Dir.glob(File.join(File.dirname(__FILE__), "rails", "registry", "**/*.rb")).each do |file|
11
+ Dir.glob(File.join(File.dirname(__FILE__), 'rails', 'registry', '**/*.rb')).sort.each do |file|
10
12
  require file
11
13
  end
12
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helium-console-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislaw Klajn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-05 00:00:00.000000000 Z
11
+ date: 2022-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: helium-console
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.1
19
+ version: 0.1.12
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.1
26
+ version: 0.1.12
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.9
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +89,7 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - ".gitignore"
77
91
  - ".rspec"
92
+ - ".rubocop.yml"
78
93
  - ".travis.yml"
79
94
  - CODE_OF_CONDUCT.md
80
95
  - Gemfile
@@ -88,7 +103,10 @@ files:
88
103
  - lib/helium/console/rails.rb
89
104
  - lib/helium/console/rails/railtie.rb
90
105
  - lib/helium/console/rails/registry/active_record.rb
106
+ - lib/helium/console/rails/registry/active_record_association.rb
107
+ - lib/helium/console/rails/registry/active_record_associations/belongs_to.rb
91
108
  - lib/helium/console/rails/registry/active_record_relation.rb
109
+ - lib/helium/console/rails/registry/time_with_zone.rb
92
110
  - lib/helium/console/rails/version.rb
93
111
  homepage: https://github.com/helium-rb/console-rails
94
112
  licenses:
@@ -104,14 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
122
  requirements:
105
123
  - - ">="
106
124
  - !ruby/object:Gem::Version
107
- version: '0'
125
+ version: 2.5.0
108
126
  required_rubygems_version: !ruby/object:Gem::Requirement
109
127
  requirements:
110
128
  - - ">="
111
129
  - !ruby/object:Gem::Version
112
130
  version: '0'
113
131
  requirements: []
114
- rubygems_version: 3.0.6
132
+ rubygems_version: 3.1.4
115
133
  signing_key:
116
134
  specification_version: 4
117
135
  summary: Formatting for rails objects