Skip to content

Commit 020543d

Browse files
committed
refactor autoloading with requires 1.1.0
1 parent ef78689 commit 020543d

File tree

4 files changed

+25
-44
lines changed

4 files changed

+25
-44
lines changed

bashly.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
2121
s.add_dependency 'gtx', '~> 0.1'
2222
s.add_dependency 'lp', '~> 0.2'
2323
s.add_dependency 'mister_bin', '~> 0.7'
24+
s.add_dependency 'requires', '~> 1.1.0'
2425
s.add_dependency 'tty-markdown', '~> 0.7'
2526

2627
# Ruby 3.0 comes with Psych 3.3.0, which does not have the `unsafe_load`

lib/bashly.rb

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,33 @@
33
require 'lp'
44
end
55

6-
require 'bashly/extensions/array'
7-
require 'bashly/extensions/file'
8-
require 'bashly/extensions/string'
9-
require 'bashly/extensions/yaml'
10-
require 'bashly/exceptions'
6+
require 'requires'
7+
requires 'bashly/extensions'
8+
requires 'bashly/exceptions'
119

1210
module Bashly
13-
autoload :CLI, 'bashly/cli'
14-
autoload :Config, 'bashly/config'
15-
autoload :ConfigValidator, 'bashly/config_validator'
16-
autoload :Library, 'bashly/library'
17-
autoload :LibrarySource, 'bashly/library_source'
18-
autoload :LibrarySourceConfig, 'bashly/library_source_config'
19-
autoload :MessageStrings, 'bashly/message_strings'
20-
autoload :RenderContext, 'bashly/render_context'
21-
autoload :RenderSource, 'bashly/render_source'
22-
autoload :VERSION, 'bashly/version'
11+
autoloads 'bashly/refinements', %i[ComposeRefinements]
2312

24-
autoload :AssetHelper, 'bashly/concerns/asset_helper'
25-
autoload :Completions, 'bashly/concerns/completions'
26-
autoload :ComposeRefinements, 'bashly/refinements/compose_refinements'
27-
autoload :Renderable, 'bashly/concerns/renderable'
28-
autoload :Settings, 'bashly/settings'
29-
autoload :ValidationHelpers, 'bashly/concerns/validation_helpers'
13+
autoloads 'bashly', %i[
14+
CLI Config ConfigValidator Library LibrarySource LibrarySourceConfig
15+
MessageStrings RenderContext RenderSource Settings VERSION
16+
]
17+
18+
autoloads 'bashly/concerns', %i[
19+
AssetHelper Completions Renderable ValidationHelpers
20+
]
3021

3122
module Script
32-
autoload :Argument, 'bashly/script/argument'
33-
autoload :Base, 'bashly/script/base'
34-
autoload :CatchAll, 'bashly/script/catch_all'
35-
autoload :Command, 'bashly/script/command'
36-
autoload :Dependency, 'bashly/script/dependency'
37-
autoload :EnvironmentVariable, 'bashly/script/environment_variable'
38-
autoload :Flag, 'bashly/script/flag'
39-
autoload :Wrapper, 'bashly/script/wrapper'
23+
autoloads 'bashly/script', %i[
24+
Argument Base CatchAll Command Dependency EnvironmentVariable Flag
25+
Wrapper
26+
]
4027
end
4128

4229
module Commands
43-
autoload :Add, 'bashly/commands/add'
44-
autoload :Base, 'bashly/commands/base'
45-
autoload :Completions, 'bashly/commands/completions'
46-
autoload :Doc, 'bashly/commands/doc'
47-
autoload :Generate, 'bashly/commands/generate'
48-
autoload :Init, 'bashly/commands/init'
49-
autoload :Preview, 'bashly/commands/preview'
50-
autoload :Render, 'bashly/commands/render'
51-
autoload :Shell, 'bashly/commands/shell'
52-
autoload :Validate, 'bashly/commands/validate'
30+
autoloads 'bashly/commands', %i[
31+
Add Base Completions Doc Generate Init Preview Render Shell Validate
32+
]
5333
end
5434

5535
module Libraries

lib/bashly/commands/shell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def terminal
1919
terminal = MisterBin::Terminal.new runner, {
2020
autocomplete: autocomplete,
2121
show_usage: true,
22-
prompt: "$ bashly ",
22+
prompt: '$ bashly ',
2323
}
2424

2525
terminal.on('help') { runner.run %w[--help] }

support/runfile/example.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def examples
77
filter_dirs('examples').map { |dir| new dir }
88
end
99

10-
def fixtures
10+
def fixtures
1111
filter_dirs('spec/fixtures/workspaces').map { |dir| new dir, type: :fixture }
1212
end
1313

@@ -20,7 +20,6 @@ def all
2020
def filter_dirs(base_dir)
2121
Dir["#{base_dir}/*"].select { |f| File.directory? f }
2222
end
23-
2423
end
2524

2625
attr_reader :dir, :type
@@ -31,7 +30,7 @@ def initialize(dir, type: :example)
3130
end
3231

3332
def inspect
34-
%Q[#<Example type=:#{type}, dir="#{dir}">]
33+
%[#<Example type=:#{type}, dir="#{dir}">]
3534
end
3635

3736
def config
@@ -59,7 +58,8 @@ def readme_path
5958
end
6059

6160
def regenerate_readme
62-
raise "#regenerate_readme called on a fixture" if type == :fixture
61+
raise '#regenerate_readme called on a fixture' if type == :fixture
62+
6363
File.write readme_path, generated_readme
6464
end
6565

0 commit comments

Comments
 (0)