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
-
#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
#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
36 37 38 |
# File 'lib/shadwire/project.rb', line 36 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.
43 44 45 46 47 48 |
# File 'lib/shadwire/project.rb', line 43 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.
52 53 54 |
# File 'lib/shadwire/project.rb', line 52 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.
61 62 63 64 65 66 |
# File 'lib/shadwire/project.rb', line 61 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
56 57 58 |
# File 'lib/shadwire/project.rb', line 56 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 |