Class: Super::Assets
- Inherits:
-
Object
- Object
- Super::Assets
- Defined in:
- lib/super/assets.rb
Overview
Utilities for determining whether to use Sprockets or Webpacker
Class Method Summary collapse
- .auto ⇒ Object
- .dist(gem_name, package_name) ⇒ Object
- .none ⇒ Object
- .sprockets ⇒ Object
- .sprockets_available? ⇒ Boolean
- .webpacker ⇒ Object
Instance Method Summary collapse
-
#initialize(asset_handler) ⇒ Assets
constructor
A new instance of Assets.
- #none? ⇒ Boolean
- #sprockets? ⇒ Boolean
- #webpacker? ⇒ Boolean
Constructor Details
#initialize(asset_handler) ⇒ Assets
Returns a new instance of Assets.
47 48 49 |
# File 'lib/super/assets.rb', line 47 def initialize(asset_handler) @asset_handler = asset_handler end |
Class Method Details
.auto ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/super/assets.rb', line 18 def self.auto @auto ||= if Gem::Dependency.new("sprockets", "~> 4.0").matching_specs.any? sprockets elsif Gem::Dependency.new("sprockets", "~> 3.0").matching_specs.any? sprockets elsif Gem::Dependency.new("sprockets", "~> 2.0").matching_specs.any? sprockets elsif Gem::Dependency.new("webpacker", "~> 4.0").matching_specs.any? webpacker elsif Gem::Dependency.new("webpacker", "~> 3.0").matching_specs.any? webpacker else none end end |
.dist(gem_name, package_name) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/super/assets.rb', line 8 def self.dist(gem_name, package_name) gem_name = gem_name.to_s @gem_paths ||= {} @gem_paths[gem_name] ||= Pathname.new(Gem.loaded_specs[gem_name].full_gem_path). gem_path = @gem_paths[gem_name] gem_path.join("frontend", package_name, "dist") end |
.none ⇒ Object
43 44 45 |
# File 'lib/super/assets.rb', line 43 def self.none new(:none) end |
.sprockets ⇒ Object
35 36 37 |
# File 'lib/super/assets.rb', line 35 def self.sprockets new(:sprockets) end |
.sprockets_available? ⇒ Boolean
4 5 6 |
# File 'lib/super/assets.rb', line 4 def self.sprockets_available? Gem::Dependency.new("sprockets").matching_specs.any? end |
.webpacker ⇒ Object
39 40 41 |
# File 'lib/super/assets.rb', line 39 def self.webpacker new(:webpacker) end |
Instance Method Details
#none? ⇒ Boolean
59 60 61 |
# File 'lib/super/assets.rb', line 59 def none? @asset_handler == :none end |
#sprockets? ⇒ Boolean
51 52 53 |
# File 'lib/super/assets.rb', line 51 def sprockets? @asset_handler == :sprockets end |
#webpacker? ⇒ Boolean
55 56 57 |
# File 'lib/super/assets.rb', line 55 def webpacker? @asset_handler == :webpacker end |