Class: Config

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

Overview

Configuration class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf = {}) ⇒ Config

Returns a new instance of Config.



8
9
10
# File 'lib/jruby_art/config.rb', line 8

def initialize(conf = {})
  @config = Default.config.merge(conf)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/jruby_art/config.rb', line 7

def config
  @config
end

Instance Method Details

#checkObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jruby_art/config.rb', line 32

def check
  load_config
  puts "JRubyArt version #{JRubyArt::VERSION}"
  puts 'Approximates to Processing-4.0'
  puts "processing ide = #{config.fetch('processing_ide', false)}"
  puts "library_path = #{config.fetch('library_path', File.join(HOME, '.jruby_art'))}"
  puts "template = #{config.fetch('template', 'bare')}"
  puts "java_args = #{config.fetch('java_args', '')}"
  puts "MAX_WATCH = #{config.fetch('MAX_WATCH', 32)}"
  puts "JRUBY = #{config.fetch('JRUBY', true)}"
end

#load_configObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jruby_art/config.rb', line 18

def load_config
  config_path = File.join(File.join(HOME, '.jruby_art', 'config.yml'))
  if File.exist? config_path
    loaded = YAML.safe_load(File.read(config_path))
    @config = Default.config.merge(loaded)
    return self unless loaded.key? 'PROCESSING_ROOT'

    warn '*********** Move Old Config File ***************'
  end
  @config = Default.config
  warn '*********** Default Config Loaded ***************'
  self
end

#write_to_fileObject



12
13
14
15
16
# File 'lib/jruby_art/config.rb', line 12

def write_to_file
  directory = File.join(HOME, '.jruby_art')
  Dir.mkdir(directory) unless Dir.exist? directory
  File.write(File.join(HOME, '.jruby_art', 'config.yml'), config.to_yaml)
end