Sha256: 8f9fa0af3d14c563a650477f33fa7f1a47a554b5fb33fa653429fc9c713a936e
Contents?: true
Size: 1.86 KB
Versions: 10
Compression:
Stored size: 1.86 KB
Contents
# Rgentpl module Rgentpl class << self # Configure # # @param _block [Proc] the configuration options # @raise [NoMethodError] when new options are inside configuration block # @return [Rgentpl::Configuration] the configuration def configure(&_block) yield @config ||= Rgentpl::Configuration.new rescue NoMethodError => exc add_new_attribute_from_exception exc end # Configuration object # # @return [Rgentpl::Configuration] the configuration object def config @config ||= Rgentpl::Configuration.new end # Interface for adding new attribute in configuration block # # @param exc [NoMethodError] the exception # @return [void] def add_new_attribute_from_exception(exc) add_new_attribute(exc, exc.name.to_s.gsub(/=$/, '')) end # Implementation for adding new attribute in configuration block # # @param exc [NoMethodError] the exception # @param method [String] the writter method name # @return [void] def add_new_attribute(exc, method) @config.extend Virtus.model @config.attribute method.to_sym, String, default: exc.args.first, lazy: true @config.send(exc.name, exc.args.first) end private :add_new_attribute end # Configuration class Configuration include Virtus.model attribute :active, Boolean, default: true attribute :log_file, String attribute :options, Hash[Symbol => String], default: {} # Set custom default values # # @param args [Array] the attributes # @return [void] def initialize(*args) super # Bug - Update some default values @log_file = Rgentpl.env + '.log' end # Configuration # # @return [Rgentpl::Configuration] the configuration def config Rgentpl.config end end end
Version data entries
10 entries across 10 versions & 1 rubygems