class Viter::Configuration

Attributes

config_path[R]
env[R]
root_path[R]

Public Class Methods

new(root_path:, config_path:, env:) click to toggle source
# File lib/viter/configuration.rb, line 9
def initialize(root_path:, config_path:, env:)
  @root_path = root_path
  @config_path = config_path
  @env = env
end

Public Instance Methods

additional_paths() click to toggle source
# File lib/viter/configuration.rb, line 31
def additional_paths
  fetch(:additional_paths)
end
cache_manifest?() click to toggle source
# File lib/viter/configuration.rb, line 47
def cache_manifest?
  fetch(:cache_manifest)
end
cache_path() click to toggle source
# File lib/viter/configuration.rb, line 51
def cache_path
  root_path.join(fetch(:cache_path))
end
compile?() click to toggle source
# File lib/viter/configuration.rb, line 23
def compile?
  fetch(:compile)
end
data() click to toggle source
# File lib/viter/configuration.rb, line 63
def data
  @data ||= load
end
defaults() click to toggle source
# File lib/viter/configuration.rb, line 85
def defaults
  @defaults ||= begin
    path = File.expand_path('../../config/viter_default.yml', __dir__)
    config = begin
      YAML.load_file(path, aliases: true)
    rescue ArgumentError
      YAML.load_file(path)
    end
    HashWithIndifferentAccess.new(config[env])
  end
end
fetch(key) click to toggle source
# File lib/viter/configuration.rb, line 59
def fetch(key)
  data.fetch(key, defaults[key])
end
host() click to toggle source
# File lib/viter/configuration.rb, line 19
def host
  "#{server[:host]}:#{server[:port]}"
end
load() click to toggle source
# File lib/viter/configuration.rb, line 67
def load
  config = begin
    YAML.load_file(config_path.to_s, aliases: true)
  rescue ArgumentError
    YAML.load_file(config_path.to_s)
  end
  config[env].deep_symbolize_keys
rescue Errno::ENOENT => e
  raise "Viter configuration file not found #{config_path}. " \
        "Please run rails viter:install " \
        "Error: #{e.message}"

rescue Psych::SyntaxError => e
  raise "YAML syntax error occurred while parsing #{config_path}. " \
        "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
        "Error: #{e.message}"
end
public_manifest_path() click to toggle source
# File lib/viter/configuration.rb, line 43
def public_manifest_path
  public_path.join('manifest.json')
end
public_path() click to toggle source
# File lib/viter/configuration.rb, line 39
def public_path
  root_path.join(fetch(:public_root_path))
end
server() click to toggle source
# File lib/viter/configuration.rb, line 15
def server
  fetch(:server)
end
source_entry_path() click to toggle source
# File lib/viter/configuration.rb, line 35
def source_entry_path
  source_path.join(fetch(:source_entry_path))
end
source_path() click to toggle source
# File lib/viter/configuration.rb, line 27
def source_path
  root_path.join(fetch(:root_path))
end
webpack_compile_output?() click to toggle source
# File lib/viter/configuration.rb, line 55
def webpack_compile_output?
  fetch(:webpack_compile_output)
end