Class: Shakapacker::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/shakapacker/configuration.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path:, config_path:, env:) ⇒ Configuration

Returns a new instance of Configuration.



12
13
14
15
16
17
18
19
# File 'lib/shakapacker/configuration.rb', line 12

def initialize(root_path:, config_path:, env:)
  @root_path = root_path
  @env = env

  # For backward compatibility
  Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
  @config_path = Pathname.new(ENV["SHAKAPACKER_CONFIG"] || config_path)
end

Class Attribute Details

.installingObject

Returns the value of attribute installing.



7
8
9
# File 'lib/shakapacker/configuration.rb', line 7

def installing
  @installing
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



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

def config_path
  @config_path
end

#envObject (readonly)

Returns the value of attribute env.



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

def env
  @env
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



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

def root_path
  @root_path
end

Instance Method Details

#additional_pathsObject



61
62
63
# File 'lib/shakapacker/configuration.rb', line 61

def additional_paths
  fetch(:additional_paths)
end

#asset_hostObject



119
120
121
# File 'lib/shakapacker/configuration.rb', line 119

def asset_host
  ENV.fetch("SHAKAPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host)
end

#cache_manifest?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/shakapacker/configuration.rb', line 89

def cache_manifest?
  fetch(:cache_manifest)
end

#cache_pathObject



93
94
95
# File 'lib/shakapacker/configuration.rb', line 93

def cache_path
  root_path.join(fetch(:cache_path))
end

#compile?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/shakapacker/configuration.rb', line 25

def compile?
  fetch(:compile)
end

#compiler_strategyObject



101
102
103
# File 'lib/shakapacker/configuration.rb', line 101

def compiler_strategy
  fetch(:compiler_strategy)
end

#dev_serverObject



21
22
23
# File 'lib/shakapacker/configuration.rb', line 21

def dev_server
  fetch(:dev_server)
end

#ensure_consistent_versioning?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/shakapacker/configuration.rb', line 33

def ensure_consistent_versioning?
  fetch(:ensure_consistent_versioning)
end

#fetch(key) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/shakapacker/configuration.rb', line 105

def fetch(key)
  return data.fetch(key, defaults[key]) unless key == :webpacker_precompile

  # for backward compatibility
  Shakapacker.puts_deprecation_message(
    Shakapacker.short_deprecation_message(
      "webpacker_precompile",
      "shakapacker_precompile"
    )
  )

  data.fetch(key, defaults[:shakapacker_precompile])
end

#manifest_pathObject



69
70
71
72
73
74
75
# File 'lib/shakapacker/configuration.rb', line 69

def manifest_path
  if data.has_key?(:manifest_path)
    root_path.join(fetch(:manifest_path))
  else
    public_output_path.join("manifest.json")
  end
end

#nested_entries?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/shakapacker/configuration.rb', line 29

def nested_entries?
  fetch(:nested_entries)
end

#public_manifest_pathObject



77
78
79
# File 'lib/shakapacker/configuration.rb', line 77

def public_manifest_path
  manifest_path
end

#public_output_pathObject



85
86
87
# File 'lib/shakapacker/configuration.rb', line 85

def public_output_path
  public_path.join(fetch(:public_output_path))
end

#public_pathObject



81
82
83
# File 'lib/shakapacker/configuration.rb', line 81

def public_path
  root_path.join(fetch(:public_root_path))
end

#relative_url_rootObject



123
124
125
# File 'lib/shakapacker/configuration.rb', line 123

def relative_url_root
  ENV.fetch("SHAKAPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root)
end

#shakapacker_precompile?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
# File 'lib/shakapacker/configuration.rb', line 37

def shakapacker_precompile?
  # ENV of false takes precedence
  return false if %w(no false n f).include?(ENV["SHAKAPACKER_PRECOMPILE"])
  return true if %w(yes true y t).include?(ENV["SHAKAPACKER_PRECOMPILE"])

  return false unless config_path.exist?
  fetch(:shakapacker_precompile)
end

#source_entry_pathObject



65
66
67
# File 'lib/shakapacker/configuration.rb', line 65

def source_entry_path
  source_path.join(relative_path(fetch(:source_entry_path)))
end

#source_pathObject



57
58
59
# File 'lib/shakapacker/configuration.rb', line 57

def source_path
  root_path.join(fetch(:source_path))
end

#webpack_compile_output?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/shakapacker/configuration.rb', line 97

def webpack_compile_output?
  fetch(:webpack_compile_output)
end

#webpacker_precompile?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
# File 'lib/shakapacker/configuration.rb', line 46

def webpacker_precompile?
  Shakapacker.puts_deprecation_message(
    Shakapacker.short_deprecation_message(
      "webpacker_precompile?",
      "shakapacker_precompile?"
    )
  )

  shakapacker_precompile?
end