Class: Shakapacker::Instance
- Inherits:
-
Object
- Object
- Shakapacker::Instance
- Defined in:
- lib/shakapacker/instance.rb,
sig/shakapacker/instance.rbs
Overview
Represents a single instance of Shakapacker configuration and state
An instance encapsulates all the configuration, compilation, and manifest lookup functionality for a specific Rails application.
Instance Attribute Summary collapse
-
#config_path ⇒ Pathname
readonly
The path to the Shakapacker configuration file.
-
#root_path ⇒ Pathname
readonly
The root path of the application.
Class Method Summary collapse
-
.logger ⇒ ActiveSupport::TaggedLogging
The shared logger used by all Shakapacker instances.
-
.logger= ⇒ ActiveSupport::TaggedLogging
Sets the shared logger used by all Shakapacker instances.
Instance Method Summary collapse
-
#commands ⇒ Commands
Returns the commands instance for build operations.
-
#compiler ⇒ Compiler
Returns the compiler for this instance.
-
#config ⇒ Configuration
Returns the configuration object for this instance.
-
#dev_server ⇒ DevServer
Returns the development server instance.
-
#env ⇒ ActiveSupport::StringInquirer
Returns the current Rails environment as a StringInquirer.
-
#initialize(root_path: nil, config_path: nil) ⇒ Instance
constructor
Creates a new Shakapacker instance.
-
#inlining_css? ⇒ Boolean
Returns whether CSS should be inlined by the dev server.
-
#logger ⇒ ActiveSupport::TaggedLogging
The shared logger used by all Shakapacker instances.
-
#manifest ⇒ Manifest
Returns the manifest for looking up compiled assets.
-
#strategy ⇒ MtimeStrategy, DigestStrategy
Returns the compiler strategy for determining staleness.
Constructor Details
#initialize(root_path: nil, config_path: nil) ⇒ Instance
Creates a new Shakapacker instance
41 42 43 44 45 46 47 48 49 |
# File 'lib/shakapacker/instance.rb', line 41 def initialize(root_path: nil, config_path: nil) # Use Rails.root if Rails is defined and no root_path is provided @root_path = root_path || (defined?(Rails) && Rails&.root) || Pathname.new(Dir.pwd) # Use the determined root_path to construct the default config path default_config_path = @root_path.join("config/shakapacker.yml") @config_path = Pathname.new(ENV["SHAKAPACKER_CONFIG"] || config_path || default_config_path) end |
Instance Attribute Details
#config_path ⇒ Pathname (readonly)
The path to the Shakapacker configuration file
31 32 33 |
# File 'lib/shakapacker/instance.rb', line 31 def config_path @config_path end |
#root_path ⇒ Pathname (readonly)
The root path of the application
27 28 29 |
# File 'lib/shakapacker/instance.rb', line 27 def root_path @root_path end |
Class Method Details
.logger ⇒ ActiveSupport::TaggedLogging
The shared logger used by all Shakapacker instances
7 |
# File 'sig/shakapacker/instance.rbs', line 7
def self.logger: () -> ActiveSupport::TaggedLogging
|
.logger= ⇒ ActiveSupport::TaggedLogging
Sets the shared logger used by all Shakapacker instances
10 |
# File 'sig/shakapacker/instance.rbs', line 10
def self.logger=: (ActiveSupport::TaggedLogging logger) -> ActiveSupport::TaggedLogging
|
Instance Method Details
#commands ⇒ Commands
Returns the commands instance for build operations
122 123 124 |
# File 'lib/shakapacker/instance.rb', line 122 def commands @commands ||= Shakapacker::Commands.new self end |
#compiler ⇒ Compiler
Returns the compiler for this instance
92 93 94 |
# File 'lib/shakapacker/instance.rb', line 92 def compiler @compiler ||= Shakapacker::Compiler.new self end |
#config ⇒ Configuration
Returns the configuration object for this instance
68 69 70 71 72 73 74 |
# File 'lib/shakapacker/instance.rb', line 68 def config @config ||= Shakapacker::Configuration.new( root_path: root_path, config_path: config_path, env: env ) end |
#dev_server ⇒ DevServer
Returns the development server instance
102 103 104 |
# File 'lib/shakapacker/instance.rb', line 102 def dev_server @dev_server ||= Shakapacker::DevServer.new config end |
#env ⇒ ActiveSupport::StringInquirer
Returns the current Rails environment as a StringInquirer
58 59 60 |
# File 'lib/shakapacker/instance.rb', line 58 def env @env ||= Shakapacker::Env.inquire self end |
#inlining_css? ⇒ Boolean
Returns whether CSS should be inlined by the dev server
134 135 136 |
# File 'lib/shakapacker/instance.rb', line 134 def inlining_css? dev_server.inline_css? && dev_server.hmr? && dev_server.running? end |
#logger ⇒ ActiveSupport::TaggedLogging
The shared logger used by all Shakapacker instances
23 |
# File 'lib/shakapacker/instance.rb', line 23 cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) } |
#manifest ⇒ Manifest
Returns the manifest for looking up compiled assets
112 113 114 |
# File 'lib/shakapacker/instance.rb', line 112 def manifest @manifest ||= Shakapacker::Manifest.new self end |
#strategy ⇒ MtimeStrategy, DigestStrategy
Returns the compiler strategy for determining staleness
83 84 85 |
# File 'lib/shakapacker/instance.rb', line 83 def strategy @strategy ||= Shakapacker::CompilerStrategy.from_config(self) end |