Class: Shadwire::Project

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Project

Returns a new instance of Project.



10
11
12
# File 'lib/shadwire/project.rb', line 10

def initialize(root)
  @root = root.to_s
end

Instance Attribute Details

#rootObject (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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


24
25
26
# File 'lib/shadwire/project.rb', line 24

def importmap?
  gem?("importmap-rails") || File.exist?(importmap_path)
end

#importmap_pathObject



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


58
59
60
# File 'lib/shadwire/project.rb', line 58

def legacy_helper?
  File.exist?(path("app/helpers/ui_helper.rb"))
end

#rails?Boolean

Returns:

  • (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.

Raises:



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

Returns:

  • (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

Returns:

  • (Boolean)


28
29
30
# File 'lib/shadwire/project.rb', line 28

def tailwindcss_rails?
  gem?("tailwindcss-rails")
end