gamefic-autoload 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24affa079439426cf2ad1afbd586d34e477f92ac3024717e279cb31cb2251b12
4
- data.tar.gz: 48c9c8950f62578fe13c005c076c41502dc02c048fab88a16f20da4639d03fde
3
+ metadata.gz: 04b696560950dd00dded43fbbbd450634941882a6b26263cb4d72a59f74fd5dd
4
+ data.tar.gz: 7e27ccabfd5ca459398e068f47db88b8dc89da44f9d9e0c72481067c8f3e381c
5
5
  SHA512:
6
- metadata.gz: 56befe92e9ef38a0c9c0b1e54b9195fcdf9990db3109d163b5634c8fd63c6367c7ee9565e9bb9ea54bbb941e1c2436aca78f5d6c86be072c0bd4d2fbc303a73a
7
- data.tar.gz: 8db06531427d6f85cf5ca03d98b02dd8570ffe5814d7a5e1c3472ea31d344b4eb03deb7d9b32489bfe620ae09f8c3e344064a8f73fb81ccb42f7c343620f1806
6
+ metadata.gz: 513d92125e91177f25c1233ede8d573c16eee9add44096008c5726e11281d2c9efeea66c2dc912db95f42d0cc384c8747f483f804a0a44761d1c24a92b72b371
7
+ data.tar.gz: 45d91e12d10778ff2dde9d8be5547712f38ed95f00af50cb3f352ae475433bcdf27aabbbb5a5c4c9acc4481104b1b47cb417cc43b1b7b2b5bef62e28d93ecab5
data/CHANGELOG.md CHANGED
@@ -1,2 +1,5 @@
1
+ ## 1.1.0 - May 24, 2025
2
+ - Autoload.setup accepts block for loader configuration
3
+
1
4
  ## 1.0.0 - October 22, 2024
2
5
  - First release
data/README.md CHANGED
@@ -1,14 +1,16 @@
1
1
  # Gamefic::Autoload
2
2
 
3
- A Zeitwerk autoloader for Gamefic projects.
3
+ A [Zeitwerk](https://github.com/fxn/zeitwerk) autoloader for Gamefic projects.
4
4
 
5
5
  Using Gamefic::Autoload gives the Gamefic::SDK a way to use autoloading in web apps.
6
6
 
7
7
  ## Installation
8
8
 
9
- The Gamefic SDK installs gamefic-autoloader by default. If you need to set it up in a bespoke project, add it to your Gemfile:
9
+ The Gamefic SDK installs gamefic-autoload by default. If you need to set it up in a bespoke project, add it to your Gemfile:
10
10
 
11
- gem 'gamefic-autoloader'
11
+ ```ruby
12
+ gem 'gamefic-autoloader'
13
+ ```
12
14
 
13
15
  Then set it up in whatever directory needs autoloading (e.g., `lib/my_project.rb`):
14
16
 
@@ -22,11 +24,21 @@ end
22
24
 
23
25
  ## Usage
24
26
 
25
- Gamefic::Autoload sets up autoloading in your directory using standard Zeitwerk conventions. With the above example, you could define a class named `MyProject::MyClass` in
27
+ Gamefic::Autoload sets up Zeitwerk autoload in your directory using standard Zeitwerk conventions. With the above example, you could define a class named `MyProject::MyClass` in
26
28
  `lib/my_project/my_class.rb`, and it would be automatically loaded without the need to `require` the file.
27
29
 
28
30
  For Opal-based web apps, The Gamefic SDK will create an `autoload.rb` file that preloads your files, classes, and modules in the same manner that Zeitwerk does.
29
31
 
32
+ If you need to customize the autoloader, you can also pass an optional `namespace` and block to the `setup` method:
33
+
34
+ ```ruby
35
+ Gamefic::Autoload.setup(__dir__, namespace: Object) do |loader|
36
+ loader.inflector.inflect("xml" => "XML")
37
+ end
38
+ ```
39
+
40
+ See the [Zeitwerk documentation](https://github.com/fxn/zeitwerk) for more information about configuring loaders.
41
+
30
42
  ## Development
31
43
 
32
44
  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.
@@ -35,4 +47,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
35
47
 
36
48
  ## Contributing
37
49
 
38
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gamefic-autoload.
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/castwide/gamefic-autoload.
@@ -1,46 +1,47 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/gamefic/autoload/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'gamefic-autoload'
7
- spec.version = Gamefic::Autoload::VERSION
8
- spec.authors = ['Fred Snyder']
9
- spec.email = ['fsnyder@castwide.com']
10
- spec.homepage = 'https://gamefic.com'
11
- spec.license = 'MIT'
12
-
13
- spec.summary = 'Code loading for Gamefic projects'
14
- # spec.description = "TODO: Write a longer description or delete this line."
15
- # spec.homepage = "TODO: Put your gem's website or public repo URL here."
16
- spec.required_ruby_version = '>= 2.6.0'
17
-
18
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
19
-
20
- spec.metadata['homepage_uri'] = spec.homepage
21
- spec.metadata['source_code_uri'] = 'https://github.com/castwide/gamefic-autoload'
22
- spec.metadata['changelog_uri'] = 'https://github.com/castwide/gamefic-autoload/blob/master/CHANGELOG.md'
23
-
24
- # Specify which files should be added to the gem when it is released.
25
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
- spec.files = Dir.chdir(__dir__) do
27
- `git ls-files -z`.split("\x0").reject do |f|
28
- (File.expand_path(f) == __FILE__) ||
29
- f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
30
- end
31
- end
32
- spec.bindir = 'exe'
33
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
- spec.require_paths = ['lib']
35
-
36
- # Uncomment to register a new dependency of your gem
37
- # spec.add_dependency "example-gem", "~> 1.0"
38
- spec.add_dependency 'gamefic', '~> 4.0'
39
- spec.add_dependency 'zeitwerk', '~> 2.6'
40
-
41
- spec.add_development_dependency 'rake', '~> 13.0'
42
- spec.add_development_dependency 'rspec', '~> 3.0'
43
-
44
- # For more information and examples about making a new gem, check out our
45
- # guide at: https://bundler.io/guides/creating_gem.html
46
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/gamefic/autoload/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'gamefic-autoload'
7
+ spec.version = Gamefic::Autoload::VERSION
8
+ spec.authors = ['Fred Snyder']
9
+ spec.email = ['fsnyder@castwide.com']
10
+ spec.homepage = 'https://gamefic.com'
11
+ spec.license = 'MIT'
12
+
13
+ spec.summary = 'Code loading for Gamefic projects'
14
+ # spec.description = "TODO: Write a longer description or delete this line."
15
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
16
+ spec.required_ruby_version = '>= 2.6.0'
17
+
18
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/castwide/gamefic-autoload'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/castwide/gamefic-autoload/blob/master/CHANGELOG.md'
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(__dir__) do
27
+ `git ls-files -z`.split("\x0").reject do |f|
28
+ (File.expand_path(f) == __FILE__) ||
29
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
30
+ end
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ # Uncomment to register a new dependency of your gem
37
+ # spec.add_dependency "example-gem", "~> 1.0"
38
+ spec.add_dependency 'gamefic', '~> 4.0'
39
+ spec.add_dependency 'zeitwerk', '~> 2.6'
40
+
41
+ spec.add_development_dependency 'rake', '~> 13.0'
42
+ spec.add_development_dependency 'rspec', '~> 3.0'
43
+ spec.add_development_dependency 'simplecov', '~> 0.22'
44
+
45
+ # For more information and examples about making a new gem, check out our
46
+ # guide at: https://bundler.io/guides/creating_gem.html
47
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gamefic
4
4
  module Autoload
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
@@ -11,23 +11,41 @@ module Gamefic
11
11
  # loading conventions in Opal-based web apps.
12
12
  #
13
13
  module Autoload
14
- def self.setup(directory, namespace: Object)
14
+ # Enable autoloading in a directory. See the Zeitwerk documentation for
15
+ # more information.
16
+ #
17
+ # @param directory [String] The directory name
18
+ # @param namespace [Module] The directory's root namespace
19
+ # @yieldparam [Zeitwerk::Loader]
20
+ # @return [Zeitwerk::Loader]
21
+ def self.setup(directory, namespace: Object, &block)
15
22
  if RUBY_ENGINE == 'opal'
16
23
  Gamefic.logger.info 'Opal engine detected - Gamefic::Autoload skipped'
17
24
  else
18
- register_and_setup directory, namespace
25
+ register_and_setup directory, namespace, &block
19
26
  end
20
27
  end
21
28
 
29
+ # A list of all the directories that use autoloading.
30
+ #
31
+ # @return [Array<String>]
22
32
  def self.registered
23
33
  registry.keys
24
34
  end
25
35
 
36
+ # The history of a directory's load events.
37
+ #
38
+ # @return [Array<Hash>]
26
39
  def self.history(directory)
27
40
  registry[directory].eager_load
28
41
  histories[directory]
29
42
  end
30
43
 
44
+ # Translate a directory's load history into lines of Ruby source code that
45
+ # can replicate the autoload process without Zeitwerk.
46
+ #
47
+ # @param directory [String]
48
+ # @return [Array<String>]
31
49
  def self.encode(directory)
32
50
  history(directory).map do |hash|
33
51
  if File.file?(hash[:file])
@@ -39,12 +57,17 @@ module Gamefic
39
57
  end
40
58
  end
41
59
 
60
+ # Encode all of the registered directories.
61
+ #
62
+ # @return [Array<String>]
42
63
  def self.encode_all
43
64
  registered.flat_map { |directory| encode(directory) }
44
65
  end
45
66
 
46
67
  class << self
47
- def register_and_setup(directory, namespace)
68
+ private
69
+
70
+ def register_and_setup(directory, namespace, &block)
48
71
  registry[directory] = Zeitwerk::Loader.new.tap do |loader|
49
72
  histories[directory] = []
50
73
  loader.push_dir directory, namespace: namespace
@@ -52,8 +75,8 @@ module Gamefic
52
75
  line = { name: name, const: const, file: file }
53
76
  histories[directory].push line
54
77
  end
78
+ block&.call(loader)
55
79
  loader.setup
56
- loader.eager_load
57
80
  end
58
81
  end
59
82
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamefic-autoload
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-22 00:00:00.000000000 Z
11
+ date: 2025-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gamefic
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.22'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.22'
69
83
  description:
70
84
  email:
71
85
  - fsnyder@castwide.com
@@ -104,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
118
  - !ruby/object:Gem::Version
105
119
  version: '0'
106
120
  requirements: []
107
- rubygems_version: 3.3.7
121
+ rubygems_version: 3.5.22
108
122
  signing_key:
109
123
  specification_version: 4
110
124
  summary: Code loading for Gamefic projects