Skip to content

Commit

Permalink
Merge pull request #539 from DannyBen/refactor/autoloads
Browse files Browse the repository at this point in the history
Refactor autoloading with `requires` 1.1.0
  • Loading branch information
DannyBen committed Jul 26, 2024
2 parents ef78689 + 020543d commit 3fd3aab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 44 deletions.
1 change: 1 addition & 0 deletions bashly.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |s|
s.add_dependency 'gtx', '~> 0.1'
s.add_dependency 'lp', '~> 0.2'
s.add_dependency 'mister_bin', '~> 0.7'
s.add_dependency 'requires', '~> 1.1.0'
s.add_dependency 'tty-markdown', '~> 0.7'

# Ruby 3.0 comes with Psych 3.3.0, which does not have the `unsafe_load`
Expand Down
58 changes: 19 additions & 39 deletions lib/bashly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,33 @@
require 'lp'
end

require 'bashly/extensions/array'
require 'bashly/extensions/file'
require 'bashly/extensions/string'
require 'bashly/extensions/yaml'
require 'bashly/exceptions'
require 'requires'
requires 'bashly/extensions'
requires 'bashly/exceptions'

module Bashly
autoload :CLI, 'bashly/cli'
autoload :Config, 'bashly/config'
autoload :ConfigValidator, 'bashly/config_validator'
autoload :Library, 'bashly/library'
autoload :LibrarySource, 'bashly/library_source'
autoload :LibrarySourceConfig, 'bashly/library_source_config'
autoload :MessageStrings, 'bashly/message_strings'
autoload :RenderContext, 'bashly/render_context'
autoload :RenderSource, 'bashly/render_source'
autoload :VERSION, 'bashly/version'
autoloads 'bashly/refinements', %i[ComposeRefinements]

autoload :AssetHelper, 'bashly/concerns/asset_helper'
autoload :Completions, 'bashly/concerns/completions'
autoload :ComposeRefinements, 'bashly/refinements/compose_refinements'
autoload :Renderable, 'bashly/concerns/renderable'
autoload :Settings, 'bashly/settings'
autoload :ValidationHelpers, 'bashly/concerns/validation_helpers'
autoloads 'bashly', %i[
CLI Config ConfigValidator Library LibrarySource LibrarySourceConfig
MessageStrings RenderContext RenderSource Settings VERSION
]

autoloads 'bashly/concerns', %i[
AssetHelper Completions Renderable ValidationHelpers
]

module Script
autoload :Argument, 'bashly/script/argument'
autoload :Base, 'bashly/script/base'
autoload :CatchAll, 'bashly/script/catch_all'
autoload :Command, 'bashly/script/command'
autoload :Dependency, 'bashly/script/dependency'
autoload :EnvironmentVariable, 'bashly/script/environment_variable'
autoload :Flag, 'bashly/script/flag'
autoload :Wrapper, 'bashly/script/wrapper'
autoloads 'bashly/script', %i[
Argument Base CatchAll Command Dependency EnvironmentVariable Flag
Wrapper
]
end

module Commands
autoload :Add, 'bashly/commands/add'
autoload :Base, 'bashly/commands/base'
autoload :Completions, 'bashly/commands/completions'
autoload :Doc, 'bashly/commands/doc'
autoload :Generate, 'bashly/commands/generate'
autoload :Init, 'bashly/commands/init'
autoload :Preview, 'bashly/commands/preview'
autoload :Render, 'bashly/commands/render'
autoload :Shell, 'bashly/commands/shell'
autoload :Validate, 'bashly/commands/validate'
autoloads 'bashly/commands', %i[
Add Base Completions Doc Generate Init Preview Render Shell Validate
]
end

module Libraries
Expand Down
2 changes: 1 addition & 1 deletion lib/bashly/commands/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def terminal
terminal = MisterBin::Terminal.new runner, {
autocomplete: autocomplete,
show_usage: true,
prompt: "$ bashly ",
prompt: '$ bashly ',
}

terminal.on('help') { runner.run %w[--help] }
Expand Down
8 changes: 4 additions & 4 deletions support/runfile/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def examples
filter_dirs('examples').map { |dir| new dir }
end

def fixtures
def fixtures
filter_dirs('spec/fixtures/workspaces').map { |dir| new dir, type: :fixture }
end

Expand All @@ -20,7 +20,6 @@ def all
def filter_dirs(base_dir)
Dir["#{base_dir}/*"].select { |f| File.directory? f }
end

end

attr_reader :dir, :type
Expand All @@ -31,7 +30,7 @@ def initialize(dir, type: :example)
end

def inspect
%Q[#<Example type=:#{type}, dir="#{dir}">]
%[#<Example type=:#{type}, dir="#{dir}">]
end

def config
Expand Down Expand Up @@ -59,7 +58,8 @@ def readme_path
end

def regenerate_readme
raise "#regenerate_readme called on a fixture" if type == :fixture
raise '#regenerate_readme called on a fixture' if type == :fixture

File.write readme_path, generated_readme
end

Expand Down

0 comments on commit 3fd3aab

Please sign in to comment.