Class: Ramekin::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ramekin/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Config

Returns a new instance of Config.



51
52
53
# File 'lib/ramekin/config.rb', line 51

def initialize(file)
  @raw = YAML.load_file(file) || {}
end

Instance Method Details

#amk_dirObject



79
80
81
# File 'lib/ramekin/config.rb', line 79

def amk_dir
  option('RAMEKIN_AMK_DIR', 'amk_dir', 'addmusick')
end

#asar_dirObject



83
84
85
# File 'lib/ramekin/config.rb', line 83

def asar_dir
  option('RAMEKIN_ASAR_DIR', 'asar_dir', 'asar')
end

#asar_libObject



91
92
93
94
95
96
# File 'lib/ramekin/config.rb', line 91

def asar_lib
  try_asar_lib or begin
    $stderr.puts "can't find asar lib. did you compile it?"
    exit 1
  end
end

#expand(path) ⇒ Object



117
118
119
# File 'lib/ramekin/config.rb', line 117

def expand(path)
  File.expand_path(path, HOME)
end

#lib_extObject



55
56
57
# File 'lib/ramekin/config.rb', line 55

def lib_ext
  RbConfig::CONFIG['SOEXT']
end

#linux?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/ramekin/config.rb', line 67

def linux?
  lib_ext == 'so'
end

#macos?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/ramekin/config.rb', line 63

def macos?
  lib_ext == 'dylib'
end

#option(upname, downname, default) ⇒ Object



75
76
77
# File 'lib/ramekin/config.rb', line 75

def option(upname, downname, default)
  expand(raw_option(upname, downname, default))
end

#packages_dirObject



113
114
115
# File 'lib/ramekin/config.rb', line 113

def packages_dir
  expand(ENV['RAMEKIN_PACKAGES_DIR'] || @raw['packages_dir'] || 'packages')
end

#raw_option(upname, downname, default) ⇒ Object



71
72
73
# File 'lib/ramekin/config.rb', line 71

def raw_option(upname, downname, default)
  ENV[upname] || @raw[downname] || Object.const_get(upname)
end

#spc_playerObject



87
88
89
# File 'lib/ramekin/config.rb', line 87

def spc_player
  raw_option('RAMEKIN_SPC_PLAYER', 'spc_player', '__auto__')
end

#try_asar_libObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ramekin/config.rb', line 98

def try_asar_lib
  return nil unless Dir.exist?(asar_dir)

  path = Dir.chdir(asar_dir) do
    Dir.glob('asar/lib/*').find do |f|
      next unless File.file?(f)
      next if File.symlink?(f)

      f =~ /[.]#{lib_ext}([.]\d+)*/
    end
  end

  path && File.expand_path(path, asar_dir)
end

#windows?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/ramekin/config.rb', line 59

def windows?
  lib_ext == 'dll'
end