Class: Browsable::AssetPipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/browsable/asset_pipeline.rb

Overview

Identifies which Rails asset pipeline (Propshaft, Sprockets, both, or neither) is in use for a project. Reported in the audit header so the user sees at a glance which pipeline browsable inferred — and surfaced in the JSON output so editor integrations and CI can branch on it.

Detection prefers a live ‘defined?` check (set when running inside the host Rails process, e.g. via the railtie or a rake task). Standalone CLI runs never load the host app, so the fallback inspects the project’s Gemfile.lock — the canonical record of which asset-pipeline gem the app actually uses.

Constant Summary collapse

PROPSHAFT =
"propshaft"
SPROCKETS =
"sprockets"
BOTH =
"sprockets+propshaft"
NONE =
"none"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:) ⇒ AssetPipeline

Returns a new instance of AssetPipeline.



27
28
29
# File 'lib/browsable/asset_pipeline.rb', line 27

def initialize(root:)
  @root = File.expand_path(root)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



25
26
27
# File 'lib/browsable/asset_pipeline.rb', line 25

def root
  @root
end

Class Method Details

.detect(root:) ⇒ Object

Build a pipeline descriptor for the project at ‘root`.



21
22
23
# File 'lib/browsable/asset_pipeline.rb', line 21

def self.detect(root:)
  new(root: root)
end

Instance Method Details

#nameObject

One of PROPSHAFT, SPROCKETS, BOTH, NONE.



32
33
34
# File 'lib/browsable/asset_pipeline.rb', line 32

def name
  @name ||= identify
end

#none?Boolean

Returns:

  • (Boolean)


38
# File 'lib/browsable/asset_pipeline.rb', line 38

def none?      = name == NONE

#prefer_sprockets_layout?Boolean

When both pipelines are loaded (typical during a Propshaft migration), prefer Sprockets-style discovery — its source tree is the broader superset, so its globs match everything Propshaft would have found too.

Returns:

  • (Boolean)


43
# File 'lib/browsable/asset_pipeline.rb', line 43

def prefer_sprockets_layout? = sprockets?

#propshaft?Boolean

Returns:

  • (Boolean)


36
# File 'lib/browsable/asset_pipeline.rb', line 36

def propshaft? = name == PROPSHAFT || name == BOTH

#sprockets?Boolean

Returns:

  • (Boolean)


37
# File 'lib/browsable/asset_pipeline.rb', line 37

def sprockets? = name == SPROCKETS || name == BOTH