Sha256: 40c276f6486e19e9981c161f38f07434dc00154703bc23445e95eeb0b06cecc9
Contents?: true
Size: 949 Bytes
Versions: 7
Compression:
Stored size: 949 Bytes
Contents
# frozen_string_literal: true require 'yaml' module Toggl module Worktime # Config for Toggl::Worktime class Config attr_accessor :foo ATTRS = %i[ working_interval_min day_begin_hour timezone ignore_conditions ].freeze ATTR_DEFAULTS = { working_interval_min: 10, day_begin_hour: 6, timezone: 'Asia/Tokyo', ignore_conditions: [] }.freeze ATTRS.each do |attr| attr_accessor attr end def initialize(args) c = self.class.load_config(args[:path]) attr_set(c) end class << self def load_config(path) YAML.safe_load(File.open(path).read).transform_keys(&:to_sym) end end private def attr_set(hash) ATTRS.each do |k| send((k.to_s + '=').to_sym, hash.key?(k) ? hash[k] : ATTR_DEFAULTS[k]) end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems