Class: WebpackerLite::Configuration

Inherits:
FileLoader show all
Defined in:
lib/webpacker_lite/configuration.rb

Constant Summary collapse

RAILS_WEB_PUBLIC =
"public"

Instance Attribute Summary

Attributes inherited from FileLoader

#data, #mtime

Class Method Summary collapse

Methods inherited from FileLoader

load_instance

Class Method Details

.base_pathObject



18
19
20
# File 'lib/webpacker_lite/configuration.rb', line 18

def base_path
  "/#{configuration.fetch(:webpack_public_output_dir, "webpack")}"
end

.base_urlObject

Uses the hot_reloading_host if appropriate



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/webpacker_lite/configuration.rb', line 23

def base_url
  if WebpackerLite::Env.hot_loading?
    host = configuration[:hot_reloading_host]
    if host.blank?
      raise "WebpackerLite's /config/webpacker_lite.yml needs a configuration value for the "\
        "`hot_reloading_host` for environment #{Rails.env}."
    end
    if host.starts_with?("http")
      host
    else
      "http://#{host}"
    end
  else
    base_path
  end
end

.configurationObject



40
41
42
43
44
# File 'lib/webpacker_lite/configuration.rb', line 40

def configuration
  load_instance
  raise WebpackerLite::FileLoader::FileLoaderError.new("WebpackerLite::Configuration.load_instance must be called first") unless instance
  instance.data
end

.file_pathObject



46
47
48
# File 'lib/webpacker_lite/configuration.rb', line 46

def file_path
  Rails.root.join("config", "webpacker_lite.yml")
end

.manifest_pathObject



9
10
11
12
# File 'lib/webpacker_lite/configuration.rb', line 9

def manifest_path
  Rails.root.join(webpack_public_output_dir,
                  configuration.fetch(:manifest, "manifest.json"))
end

.webpack_public_output_dirObject



14
15
16
# File 'lib/webpacker_lite/configuration.rb', line 14

def webpack_public_output_dir
  Rails.root.join(RAILS_WEB_PUBLIC, configuration.fetch(:webpack_public_output_dir, "webpack"))
end