Class: Shadwire::Project
- Inherits:
-
Object
- Object
- Shadwire::Project
- Defined in:
- lib/shadwire/project.rb
Overview
Detects a consuming Rails app and its front-end stack by inspecting the Gemfile / Gemfile.lock and a few conventional files. Pure filesystem reads — never loads the app or Bundler.
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#binstub? ⇒ Boolean
The canonical CLI entry point.
-
#gem?(name) ⇒ Boolean
True when the gem is declared in Gemfile.lock (authoritative when present) or the Gemfile.
- #importmap? ⇒ Boolean
- #importmap_path ⇒ Object
-
#include_all_helpers? ⇒ Boolean
Rails includes every app/helpers/**/*_helper.rb module into views unless an app opts out.
-
#initialize(root) ⇒ Project
constructor
A new instance of Project.
-
#legacy_helper? ⇒ Boolean
A monolithic app/helpers/ui_helper.rb left over from before helpers were split per item.
- #rails? ⇒ Boolean
-
#raise_unless_rails! ⇒ Object
Raises ProjectError unless this looks like a Rails app.
- #stimulus? ⇒ Boolean
- #tailwind_css_path(relative = "app/assets/tailwind/application.css") ⇒ Object
- #tailwindcss_rails? ⇒ Boolean
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
8 9 10 |
# File 'lib/shadwire/project.rb', line 8 def root @root end |
Instance Method Details
#binstub? ⇒ Boolean
The canonical CLI entry point. status reports it so the agent skill can
name one invocation instead of guessing from the Gemfile.
38 39 40 |
# File 'lib/shadwire/project.rb', line 38 def binstub? Binstub.exist?(@root) end |
#gem?(name) ⇒ Boolean
True when the gem is declared in Gemfile.lock (authoritative when present) or the Gemfile.
20 21 22 |
# File 'lib/shadwire/project.rb', line 20 def gem?(name) (File.exist?(lockfile_path) && lock_declares?(name)) || gemfile_declares?(name) end |
#importmap? ⇒ Boolean
24 25 26 |
# File 'lib/shadwire/project.rb', line 24 def importmap? gem?("importmap-rails") || File.exist?(importmap_path) end |
#importmap_path ⇒ Object
42 43 44 |
# File 'lib/shadwire/project.rb', line 42 def importmap_path path("config/importmap.rb") end |
#include_all_helpers? ⇒ Boolean
Rails includes every app/helpers/**/*_helper.rb module into views unless an
app opts out. When it does, the Ui::*Helper modules need per-controller
helper calls, so status surfaces it.
49 50 51 52 53 54 |
# File 'lib/shadwire/project.rb', line 49 def include_all_helpers? config = path("config/application.rb") return true unless File.exist?(config) !File.read(config).match?(/include_all_helpers\s*=\s*false/) end |
#legacy_helper? ⇒ Boolean
A monolithic app/helpers/ui_helper.rb left over from before helpers were split per item. No longer published; safe for the app to delete.
58 59 60 |
# File 'lib/shadwire/project.rb', line 58 def legacy_helper? File.exist?(path("app/helpers/ui_helper.rb")) end |
#rails? ⇒ Boolean
14 15 16 |
# File 'lib/shadwire/project.rb', line 14 def rails? File.exist?(path("config/application.rb")) || gem?("rails") end |
#raise_unless_rails! ⇒ Object
Raises ProjectError unless this looks like a Rails app.
67 68 69 70 71 72 |
# File 'lib/shadwire/project.rb', line 67 def raise_unless_rails! return if rails? raise ProjectError, "Not a Rails app: no config/application.rb or `gem \"rails\"` found in #{@root}" end |
#stimulus? ⇒ Boolean
32 33 34 |
# File 'lib/shadwire/project.rb', line 32 def stimulus? gem?("stimulus-rails") || File.exist?(path("app/javascript/controllers/index.js")) end |
#tailwind_css_path(relative = "app/assets/tailwind/application.css") ⇒ Object
62 63 64 |
# File 'lib/shadwire/project.rb', line 62 def tailwind_css_path(relative = "app/assets/tailwind/application.css") path(relative) end |
#tailwindcss_rails? ⇒ Boolean
28 29 30 |
# File 'lib/shadwire/project.rb', line 28 def tailwindcss_rails? gem?("tailwindcss-rails") end |