class Escalator::EscalatorConfig
Public Class Methods
default()
click to toggle source
# File lib/escalator/config.rb, line 39 def default @config ||= begin load File.join("config", "plc.yml") end end
load(path)
click to toggle source
# File lib/escalator/config.rb, line 45 def load path h = {} if File.exist?(path) h = YAML.load(File.read(path)) h = JSON.parse(h.to_json, symbolize_names: true) end new h || {} end
new(options={})
click to toggle source
# File lib/escalator/config.rb, line 56 def initialize options={} default = { input: "asm/main.asm", output: "build/main.hex", } emulator_default = { host: "localhost", port: 5555, protocol: "emu_protocol", } @config = default.merge options @config[:plc] ||= {} @config[:plc][:emulator] = @config[:plc][:emulator] ? emulator_default.merge(@config[:plc][:emulator]) : emulator_default @config[:default] ||= {} @targets = {} end
Public Instance Methods
[](key)
click to toggle source
# File lib/escalator/config.rb, line 76 def [] key @config[key] end
method_missing(name, *args)
click to toggle source
# File lib/escalator/config.rb, line 95 def method_missing(name, *args) name = name.to_s unless name.is_a? String case name.to_s when /(.*)=$/ @config[$1.to_sym] = args.first else @config[name.to_sym] end end
target(name=nil)
click to toggle source
# File lib/escalator/config.rb, line 80 def target name=nil name ||= (@config[:default][:target] || :emulator) name = name.to_sym if name.is_a? String target = @targets[name] unless target h = @config[:plc][name] unless h.nil? || h.empty? h = {name:name}.merge h target = EscalatorConfigTarget.new h @targets[name] = target end end target end