require "yaml_properties/version" require "active_support/core_ext/hash" require "yaml" require "erb" module YamlProperties def properties reset! if dev_environment @properties ||= load_properties.with_indifferent_access end attr_accessor :dev_environment def reset! reset_properties end def reset_properties @properties = nil end def method_missing(key, *args, &block) return properties[key] if key_present? key super key, *args, &block end def fetch(key, default = nil) key_present?(key) ? properties[key] : default end def override_attribute attribute, value unless key_present? attribute raise ArgumentError, "Trying to override non-existent property `#{attribute}' with `#{value}'" end properties[attribute] = value end private def key_present? key properties.keys.include? key.to_s end def yaml_file File.join %w(config properties.yml) end def load_properties yaml = YAML.load ERB.new(File.read(yaml_file)).result yaml end extend self end