indexmap 0.8.0 → 0.8.1

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: 7e1e66f1d2afc109e4475d63d4c24c4e66d4da6a50e729b1f67f325bf729b792
4
- data.tar.gz: ce2d2d9f892c510b337e7c2155cc304044a9182722588172456c82b737e196d3
3
+ metadata.gz: 2f78184d7ab33df85d653a915d6b9e42f7c5409fe0e01bb81991b358616cf4f5
4
+ data.tar.gz: 739a22b6445ca41a090d296c7c30ea3e96fd08c120fce59dbca41ca76c5c57b5
5
5
  SHA512:
6
- metadata.gz: 0ad6376f15ef8e5f734c952ae209b472cdefeeb195c641c05e84413f58a3f699f33a8dd6145d661df14c3603fa26268829fae0028da66496bc222f85a3a3c21b
7
- data.tar.gz: 2a1c8520caabe2cd2650dda8fd62e77fb9a3a55f85d508b38eb2529d1a658701c15fb65a168e65d278587b55ecbeae15d6bba929b17a1d1855dace51e6d205cd
6
+ metadata.gz: a78824d383358e1bbc36ebccc37e5cda6d2311a1d37cfd5941f09c7f3a39d30a8023b94dfffdb812b37dd95e754ef908e6a73a3368a861bb761c960b192e19ef
7
+ data.tar.gz: 89b5cca3351e953d92a7d0b712b56a7856c47564168e759dcd6dbb5e672e7d714ef62e864f1172bc4b4cbedb129801da9bae68fd1542d8d773f77a13314cfc63
data/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.8.1] - 2026-07-21
9
+
10
+
11
+ ### Added
12
+
13
+ - add lazy install generator ([#17](https://github.com/ethos-link/indexmap/pull/17))
14
+
15
+
16
+
8
17
  ## [0.8.0] - 2026-07-21
9
18
 
10
19
 
data/README.md CHANGED
@@ -72,20 +72,18 @@ Indexmap::Writer.new(
72
72
 
73
73
  ## Rails Usage
74
74
 
75
- For an app that uses Indexmap through rake tasks, load the task entrypoint only
76
- when an Indexmap task is requested. In the application's `Rakefile`, before
77
- `require_relative "config/application"`:
75
+ Run the install generator after adding the gem:
78
76
 
79
- ```ruby
80
- list_tasks = Rake.application.options.show_tasks || ARGV.any? { |argument| ["-T", "--tasks"].include?(argument) }
81
- require "indexmap/tasks" if list_tasks || ARGV.any? { |argument| argument.start_with?("indexmap:") }
77
+ ```bash
78
+ bin/rails generate indexmap:install
82
79
  ```
83
80
 
84
- This preserves `bin/rails --tasks` and the `indexmap:*` tasks without loading
85
- Indexmap during normal Rails boot. Runtime callers and jobs should explicitly
86
- `require "indexmap"` immediately before configuring or using the gem.
81
+ The generator creates `config/initializers/indexmap.rb` with an idempotent
82
+ `IndexmapConfiguration.apply` loader and adds conditional `indexmap/tasks`
83
+ loading to the application's `Rakefile`. This preserves `bin/rails --tasks` and
84
+ the `indexmap:*` tasks without loading Indexmap during normal Rails boot.
87
85
 
88
- In an initializer:
86
+ Customize the `Indexmap.configure` block inside the generated initializer:
89
87
 
90
88
  ```ruby
91
89
  Indexmap.configure do |config|
@@ -109,6 +107,17 @@ Indexmap.configure do |config|
109
107
  end
110
108
  ```
111
109
 
110
+ Runtime callers and jobs must apply the generated configuration before using
111
+ Indexmap:
112
+
113
+ ```ruby
114
+ IndexmapConfiguration.apply
115
+ Indexmap.create
116
+ ```
117
+
118
+ Rake tasks apply it automatically because `indexmap/tasks` loads the gem before
119
+ Rails evaluates the initializer.
120
+
112
121
  Then run:
113
122
 
114
123
  ```bash
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module Indexmap
6
+ module Generators
7
+ class InstallGenerator < Rails::Generators::Base
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ desc "Create a lazy-safe Indexmap initializer and task loader"
11
+
12
+ def create_initializer
13
+ template "initializer.rb.tt", "config/initializers/indexmap.rb"
14
+ end
15
+
16
+ def configure_rakefile
17
+ rakefile = File.join(destination_root, "Rakefile")
18
+ return unless File.exist?(rakefile)
19
+ return if File.read(rakefile).include?('require "indexmap/tasks"')
20
+
21
+ inject_into_file "Rakefile", rakefile_setup, before: /^require_relative ["']config\/application["']/
22
+ end
23
+
24
+ private
25
+
26
+ def rakefile_setup
27
+ <<~RUBY
28
+ indexmap_tasks_requested = Rake.application.options.show_tasks ||
29
+ ARGV.any? { |argument| ["-T", "--tasks"].include?(argument) }
30
+ require "indexmap/tasks" if indexmap_tasks_requested ||
31
+ ARGV.any? { |argument| argument.start_with?("indexmap:") }
32
+
33
+ RUBY
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IndexmapConfiguration
4
+ MUTEX = Mutex.new
5
+
6
+ def self.apply
7
+ return if @applied
8
+
9
+ MUTEX.synchronize do
10
+ return if @applied
11
+
12
+ require "indexmap"
13
+
14
+ Indexmap.configure do |config|
15
+ config.base_url = -> { ENV.fetch("INDEXMAP_BASE_URL", "http://localhost:3000") }
16
+ config.storage = lambda {
17
+ Indexmap::Storage::Filesystem.new(
18
+ path: Rails.public_path,
19
+ public_url: config.base_url
20
+ )
21
+ }
22
+
23
+ # Configure the sitemap data owned by your application:
24
+ # config.sections = -> { Sitemap.sections }
25
+ end
26
+
27
+ @applied = true
28
+ end
29
+ end
30
+ end
31
+
32
+ IndexmapConfiguration.apply if defined?(Indexmap)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Indexmap
4
- VERSION = "0.8.0"
4
+ VERSION = "0.8.1"
5
5
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "generators/indexmap/install_generator"
5
+ require "open3"
6
+ require "rbconfig"
7
+
8
+ class IndexmapInstallGeneratorTest < Minitest::Test
9
+ def test_generates_lazy_initializer_and_task_loader
10
+ Dir.mktmpdir do |destination|
11
+ File.write(File.join(destination, "Rakefile"), <<~RUBY)
12
+ require_relative "config/application"
13
+ Rails.application.load_tasks
14
+ RUBY
15
+
16
+ Indexmap::Generators::InstallGenerator.start([], destination_root: destination)
17
+
18
+ initializer = File.join(destination, "config/initializers/indexmap.rb")
19
+ rakefile = File.read(File.join(destination, "Rakefile"))
20
+
21
+ assert File.exist?(initializer)
22
+ assert_includes File.read(initializer), "module IndexmapConfiguration"
23
+ assert_includes File.read(initializer), "IndexmapConfiguration.apply if defined?(Indexmap)"
24
+ assert_includes rakefile, 'require "indexmap/tasks"'
25
+ assert_operator rakefile.index('require "indexmap/tasks"'), :<, rakefile.index('require_relative "config/application"')
26
+
27
+ _stdout, stderr, status = Open3.capture3(RbConfig.ruby, initializer)
28
+ assert status.success?, stderr
29
+
30
+ script = <<~RUBY
31
+ require "pathname"
32
+
33
+ module Rails
34
+ def self.public_path
35
+ Pathname.new("public")
36
+ end
37
+ end
38
+
39
+ require "indexmap"
40
+ load ARGV.fetch(0)
41
+
42
+ configuration = Indexmap.configuration
43
+ IndexmapConfiguration.apply
44
+ abort "configuration replaced" unless Indexmap.configuration.equal?(configuration)
45
+ abort "base URL missing" unless configuration.base_url == "http://localhost:3000"
46
+ RUBY
47
+ _stdout, stderr, status = Open3.capture3(
48
+ RbConfig.ruby,
49
+ "-I#{File.expand_path("../../lib", __dir__)}",
50
+ "-e",
51
+ script,
52
+ initializer
53
+ )
54
+ assert status.success?, stderr
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indexmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Fidalgo
@@ -175,6 +175,8 @@ files:
175
175
  - CHANGELOG.md
176
176
  - LICENSE.txt
177
177
  - README.md
178
+ - lib/generators/indexmap/install_generator.rb
179
+ - lib/generators/indexmap/templates/initializer.rb.tt
178
180
  - lib/indexmap.rb
179
181
  - lib/indexmap/configuration.rb
180
182
  - lib/indexmap/creator.rb
@@ -199,6 +201,7 @@ files:
199
201
  - lib/indexmap/writer.rb
200
202
  - lib/tasks/indexmap_tasks.rake
201
203
  - test/indexmap/configuration_test.rb
204
+ - test/indexmap/install_generator_test.rb
202
205
  - test/indexmap/lazy_loading_test.rb
203
206
  - test/indexmap/parser_test.rb
204
207
  - test/indexmap/pinger/google_test.rb