gamefic-autoload 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 24affa079439426cf2ad1afbd586d34e477f92ac3024717e279cb31cb2251b12
4
+ data.tar.gz: 48c9c8950f62578fe13c005c076c41502dc02c048fab88a16f20da4639d03fde
5
+ SHA512:
6
+ metadata.gz: 56befe92e9ef38a0c9c0b1e54b9195fcdf9990db3109d163b5634c8fd63c6367c7ee9565e9bb9ea54bbb941e1c2436aca78f5d6c86be072c0bd4d2fbc303a73a
7
+ data.tar.gz: 8db06531427d6f85cf5ca03d98b02dd8570ffe5814d7a5e1c3472ea31d344b4eb03deb7d9b32489bfe620ae09f8c3e344064a8f73fb81ccb42f7c343620f1806
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 1.0.0 - October 22, 2024
2
+ - First release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ gamefic-autoload
2
+ Copyright (c) 2024 by Fred Snyder for Castwide Technologies
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Gamefic::Autoload
2
+
3
+ A Zeitwerk autoloader for Gamefic projects.
4
+
5
+ Using Gamefic::Autoload gives the Gamefic::SDK a way to use autoloading in web apps.
6
+
7
+ ## Installation
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:
10
+
11
+ gem 'gamefic-autoloader'
12
+
13
+ Then set it up in whatever directory needs autoloading (e.g., `lib/my_project.rb`):
14
+
15
+ ```ruby
16
+ require 'gamefic-autoload'
17
+
18
+ module MyProject
19
+ Gamefic::Autoload.setup(__dir__)
20
+ end
21
+ ```
22
+
23
+ ## Usage
24
+
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
26
+ `lib/my_project/my_class.rb`, and it would be automatically loaded without the need to `require` the file.
27
+
28
+ 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
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gamefic-autoload.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,46 @@
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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gamefic
4
+ module Autoload
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gamefic'
4
+ require 'gamefic/autoload/version'
5
+ require 'zeitwerk' unless RUBY_ENGINE == 'opal'
6
+
7
+ module Gamefic
8
+ # A Zeitwerk autoloader for Gamefic.
9
+ #
10
+ # Gamefic::Autoload gives the Gamefic SDK a way to use Zeitwerk's code
11
+ # loading conventions in Opal-based web apps.
12
+ #
13
+ module Autoload
14
+ def self.setup(directory, namespace: Object)
15
+ if RUBY_ENGINE == 'opal'
16
+ Gamefic.logger.info 'Opal engine detected - Gamefic::Autoload skipped'
17
+ else
18
+ register_and_setup directory, namespace
19
+ end
20
+ end
21
+
22
+ def self.registered
23
+ registry.keys
24
+ end
25
+
26
+ def self.history(directory)
27
+ registry[directory].eager_load
28
+ histories[directory]
29
+ end
30
+
31
+ def self.encode(directory)
32
+ history(directory).map do |hash|
33
+ if File.file?(hash[:file])
34
+ path = hash[:file].sub(%r{^#{directory}/?}, '').sub(/\.rb$/, '')
35
+ "require '#{path}'"
36
+ else
37
+ "#{hash[:const].is_a?(Class) ? 'class ' : 'module'} #{hash[:const]}; end"
38
+ end
39
+ end
40
+ end
41
+
42
+ def self.encode_all
43
+ registered.flat_map { |directory| encode(directory) }
44
+ end
45
+
46
+ class << self
47
+ def register_and_setup(directory, namespace)
48
+ registry[directory] = Zeitwerk::Loader.new.tap do |loader|
49
+ histories[directory] = []
50
+ loader.push_dir directory, namespace: namespace
51
+ loader.on_load do |name, const, file|
52
+ line = { name: name, const: const, file: file }
53
+ histories[directory].push line
54
+ end
55
+ loader.setup
56
+ loader.eager_load
57
+ end
58
+ end
59
+
60
+ def registry
61
+ @registry ||= {}
62
+ end
63
+
64
+ def histories
65
+ @histories ||= {}
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gamefic/autoload'
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gamefic-autoload
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Fred Snyder
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gamefic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: zeitwerk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - fsnyder@castwide.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".rspec"
77
+ - CHANGELOG.md
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - gamefic-autoload.gemspec
82
+ - lib/gamefic-autoload.rb
83
+ - lib/gamefic/autoload.rb
84
+ - lib/gamefic/autoload/version.rb
85
+ homepage: https://gamefic.com
86
+ licenses:
87
+ - MIT
88
+ metadata:
89
+ homepage_uri: https://gamefic.com
90
+ source_code_uri: https://github.com/castwide/gamefic-autoload
91
+ changelog_uri: https://github.com/castwide/gamefic-autoload/blob/master/CHANGELOG.md
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.6.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.3.7
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Code loading for Gamefic projects
111
+ test_files: []