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 +4 -4
- data/.rubocop.yml +70 -0
- data/Gemfile +8 -2
- data/Gemfile.lock +167 -15
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/helium-console-rails.gemspec +21 -17
- data/lib/helium/console/rails/railtie.rb +13 -4
- data/lib/helium/console/rails/registry/active_record.rb +62 -14
- data/lib/helium/console/rails/registry/active_record_association.rb +63 -0
- data/lib/helium/console/rails/registry/active_record_associations/belongs_to.rb +39 -0
- data/lib/helium/console/rails/registry/active_record_relation.rb +19 -14
- data/lib/helium/console/rails/registry/time_with_zone.rb +7 -0
- data/lib/helium/console/rails/version.rb +3 -1
- data/lib/helium/console/rails.rb +6 -4
- metadata +24 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46c06d5fd799034446196de7003ba5c7aa2b6a5bc6be74d94553f5ecf7edc42c
|
4
|
+
data.tar.gz: 930923bae21e97256e349e9c251e7ad1dfadf95041f34bf2c77a39c0388deea7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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:
|
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.
|
11
|
-
helium-console (~> 0.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
|
-
|
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.
|
145
|
+
rspec-core (3.10.2)
|
28
146
|
rspec-support (~> 3.10.0)
|
29
|
-
rspec-expectations (3.10.
|
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.
|
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.
|
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.
|
200
|
+
2.2.20
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,31 +1,35 @@
|
|
1
|
-
|
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
|
5
|
+
require 'helium/console/rails/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
8
|
+
spec.name = 'helium-console-rails'
|
7
9
|
spec.version = Helium::Console::Rails::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
10
|
+
spec.authors = ['Stanislaw Klajn']
|
11
|
+
spec.email = ['sklajn@gmail.com']
|
10
12
|
|
11
|
-
spec.summary =
|
12
|
-
spec.homepage =
|
13
|
-
spec.license =
|
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[
|
16
|
-
spec.metadata[
|
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
|
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 =
|
26
|
+
spec.bindir = 'exe'
|
24
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = ['lib']
|
26
29
|
|
27
|
-
spec.add_dependency
|
28
|
-
spec.
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
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
|
-
|
7
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
6
|
+
return format_loaded if object.loaded?
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
if level == 1
|
9
|
+
object.load
|
10
|
+
format_loaded
|
11
|
+
else
|
12
|
+
format_unloaded
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
table.row(key.to_s, value)
|
22
|
+
y << line
|
23
|
+
end
|
21
24
|
end
|
25
|
+
end
|
22
26
|
|
23
|
-
|
27
|
+
def format_unloaded
|
28
|
+
"# #{format(object.klass, short: true)} relation #{red('(not loaded)')}"
|
24
29
|
end
|
25
30
|
|
26
31
|
def primary_key
|
data/lib/helium/console/rails.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
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__),
|
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.
|
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:
|
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.
|
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.
|
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:
|
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.
|
132
|
+
rubygems_version: 3.1.4
|
115
133
|
signing_key:
|
116
134
|
specification_version: 4
|
117
135
|
summary: Formatting for rails objects
|