lux-hammer 0.3.10 → 0.3.12

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/AGENTS.md +12 -2
  4. data/lib/lux-hammer.rb +44 -23
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81af43fc44619384d2b62f58e7d3178a1b6edb22cbb1ef4e836b73e2ee469913
4
- data.tar.gz: 47d012b5e54d1e8df3441de01eeaee3e3267f71c4ac8545b80f413d419bd3fc6
3
+ metadata.gz: 75362aef2908fdd2a3f4e32ab8c6ce7a4c4ae52fce795f5bca5437325a92da49
4
+ data.tar.gz: 0d318814ed2cdd0da35ca2b66e7637c62d5d2efece0cb24f60da1c5e02f4ad1f
5
5
  SHA512:
6
- metadata.gz: d1dd7d495b96a6f7023601427dadcd492e593934c6407eb48dcb7c53fea26e33ea44ec40ef3a69856199fa75dd9d6278a8d32b14cbd4733b692dbbfe662f97ee
7
- data.tar.gz: 2a9b223844fd645a79403c653a2bf25be28ba5654eef8562738b2f3768b0a72bddfd8b5ceb3dfe68ac7c583ecaaefc18fcee4d64f3f47964a93ff8f12b0fb586
6
+ metadata.gz: 64a8ce40bf7fc4986b6b0796c72fb9a8e9a13b2acb70c4aaa76cd68d5f68158bc9fbde7d5a0a5f3e586978b97f849f712b5addef336754b896e901f71c9feec2
7
+ data.tar.gz: 6f12a27b72098ff513ecc216ee8f2c6deb08e3c3a29cf4f1a7e9c6dfb7750a9b00ad13fe514f66fdda7b7a837b62e2526d1af04ca1af85deed1435e2d34b30a3
data/.version CHANGED
@@ -1 +1 @@
1
- 0.3.10
1
+ 0.3.12
data/AGENTS.md CHANGED
@@ -98,10 +98,20 @@ At Hammerfile (block-DSL) top-level scope only:
98
98
 
99
99
  At class or `Hammerfile` scope:
100
100
 
101
- * `task :name do ... end`
101
+ * `task :name do ... end` - redefining a task is last-write-wins. A
102
+ warning fires (and the entry is tagged `(redefined)` in help) **only**
103
+ when the task it clobbers was also defined inside the main app (cwd).
104
+ Overriding a task that came from outside - a framework default, plugin,
105
+ or gem (an absolute path outside cwd) - is treated as an intentional
106
+ override and stays silent. Locality is read off the location string:
107
+ `relativize_path` rewrites in-app absolutes to a `.`-relative form, so
108
+ anything still starting with `/` is external (see `app_local_location?`).
102
109
  * `namespace :name do ... end` - `:self` is reserved for the `hammer`
103
110
  binary's built-in namespace (see `lib/hammer/builtins.rb`). Defining
104
- it from user code raises.
111
+ it from user code raises. Reopening a namespace **merges** (Rake-style):
112
+ the same `namespace :db` can be split across files / `load`ed fragments
113
+ and the blocks accumulate onto one subclass - no warning. Only a
114
+ duplicate *task* name warns (handled by `task`, last write wins).
105
115
  * `dotenv false` - opt out of auto `.env` / `.env.local` loading.
106
116
  Only meaningful from the `hammer` binary (`Hammer.cli`); the load
107
117
  happens after Hammerfile evaluation, before dispatch. Shell-set vars
data/lib/lux-hammer.rb CHANGED
@@ -164,7 +164,11 @@ class Hammer
164
164
  end
165
165
  cmd.handler = handler
166
166
 
167
- if (prev = commands[cmd.name])
167
+ # Only warn when overriding a task that was also defined inside the
168
+ # main app. Overriding one that came from outside - a framework
169
+ # default, plugin, or gem - is an intentional override, so stay quiet
170
+ # and don't tag it `(redefined)` in help.
171
+ if (prev = commands[cmd.name]) && app_local_location?(prev.location)
168
172
  cmd.prev_location = prev.location
169
173
  warn_redefinition('task', cmd.name, prev.location, cmd.location)
170
174
  end
@@ -190,28 +194,29 @@ class Hammer
190
194
  # namespace :users do ... end
191
195
  # end
192
196
  #
197
+ # Reopening a namespace merges: the same `namespace :db do ... end` can
198
+ # be split across files (Rake-style) and the blocks accumulate onto one
199
+ # subclass. Only a duplicate *task* name inside warns - that's handled
200
+ # by `task`. The namespace subclass is created lazily on first mention.
193
201
  def namespace(name, &block)
194
- sub = Class.new(Hammer)
195
- # Track the top-level CLI class so cross-invocation
196
- # (`hammer 'ns:cmd'`) from inside a namespaced command dispatches
197
- # against the full tree, not just the current namespace.
198
- sub.instance_variable_set(:@root, root)
199
- # Parent link, so `before` hooks defined further up the namespace
200
- # tree can be collected and run outer -> inner before a command.
201
- sub.instance_variable_set(:@parent, self)
202
- # Share the parent's resolved program_name so help banners show
203
- # "myapp ns:cmd" with the same prefix everywhere - and so the value
204
- # captured pre-chdir (see `Hammer.cli`) survives into nested classes.
205
- sub.instance_variable_set(:@program_name, program_name)
206
- sub.instance_variable_set(:@location, source_location_of(block))
207
- Hammer.with_target(sub) { sub.class_eval(&block) } if block
208
-
209
- if (prev = @namespaces[name.to_s])
210
- sub.instance_variable_set(:@prev_location, prev.instance_variable_get(:@location))
211
- warn_redefinition('namespace', name.to_s, prev.instance_variable_get(:@location), sub.instance_variable_get(:@location))
212
- end
202
+ sub = (@namespaces[name.to_s] ||= begin
203
+ ns = Class.new(Hammer)
204
+ # Track the top-level CLI class so cross-invocation
205
+ # (`hammer 'ns:cmd'`) from inside a namespaced command dispatches
206
+ # against the full tree, not just the current namespace.
207
+ ns.instance_variable_set(:@root, root)
208
+ # Parent link, so `before` hooks defined further up the namespace
209
+ # tree can be collected and run outer -> inner before a command.
210
+ ns.instance_variable_set(:@parent, self)
211
+ # Share the parent's resolved program_name so help banners show
212
+ # "myapp ns:cmd" with the same prefix everywhere - and so the value
213
+ # captured pre-chdir (see `Hammer.cli`) survives into nested classes.
214
+ ns.instance_variable_set(:@program_name, program_name)
215
+ ns.instance_variable_set(:@location, source_location_of(block))
216
+ ns
217
+ end)
213
218
 
214
- @namespaces[name.to_s] = sub
219
+ Hammer.with_target(sub) { sub.class_eval(&block) } if block
215
220
  end
216
221
 
217
222
  # Register a hook to run before every command in this class (root or
@@ -252,7 +257,23 @@ class Hammer
252
257
  # built-in C-defined procs, eval'd blocks).
253
258
  def source_location_of(block)
254
259
  loc = block&.source_location
255
- loc ? "#{loc[0]}:#{loc[1]}" : '(unknown)'
260
+ loc ? "#{relativize_path(loc[0])}:#{loc[1]}" : '(unknown)'
261
+ end
262
+
263
+ # Trim the cwd prefix off an absolute path so redefinition warnings
264
+ # read as `./lib/tasks/foo.rb` instead of a long absolute path. Paths
265
+ # outside cwd (framework / gem files) are left absolute.
266
+ def relativize_path(path)
267
+ prefix = "#{Dir.pwd}/"
268
+ path.start_with?(prefix) ? ".#{path[Dir.pwd.length..]}" : path
269
+ end
270
+
271
+ # True when a captured location lives inside the main app. relativize_path
272
+ # rewrites in-app absolute paths to a `.`-relative form, so anything still
273
+ # starting with "/" is an absolute path outside cwd - a framework, plugin,
274
+ # or gem file. Relative locations are already cwd-anchored, hence local.
275
+ def app_local_location?(loc)
276
+ !loc.to_s.start_with?('/')
256
277
  end
257
278
 
258
279
  # Emit a yellow [hammer] warning on stderr when a task/namespace is
@@ -735,7 +756,7 @@ class Hammer
735
756
 
736
757
  def print_footer
737
758
  Shell.say ''
738
- Shell.say "powered by hammer - #{HOMEPAGE}", :gray
759
+ Shell.say "powered by hammer (v#{VERSION}) - #{HOMEPAGE}", :gray
739
760
  end
740
761
 
741
762
  # Hammerfile cheat-sheet shown under `hammer --help`. Same content
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lux-hammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-27 00:00:00.000000000 Z
11
+ date: 2026-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest