lib/sinclair/configurable.rb in sinclair-1.3.4 vs lib/sinclair/configurable.rb in sinclair-1.4.0

- old
+ new

@@ -15,10 +15,18 @@ # @see ConfigBuilder # # @example (see #configurable_with) # @example (see #configurable_by) module Configurable + # @api private + # Deprecation warning message + # @see https://github.com/darthjee/sinclair/blob/master/WARNINGS.md#usage-of-custom-config-classes + CONFIG_CLASS_WARNING = 'Config classes attributes should ' \ + 'be defined inside the class or through the usage of ' \ + "configurable_with.\n" \ + "In future releases this will be enforced.\n" \ + 'see more on https://github.com/darthjee/sinclair/blob/master/WARNINGS.md#usage-of-custom-config-classes' # (see ConfigFactory#config) # @see ConfigFactory#config def config config_factory.config end @@ -114,11 +122,13 @@ # {#configurable_with} # # @return [ConfigFactory] # # @example Configured by custom config class - # class MyServerConfig + # class MyServerConfig < Sinclair::Config + # config_attributes :host, :port + # # def url # if @port # "http://#{@host}:#{@port}" # else # "http://#{@host}" @@ -127,11 +137,11 @@ # end # # class Client # extend Sinclair::Configurable # - # configurable_by MyServerConfig, with: %i[host port] + # configurable_by MyServerConfig # end # # Client.configure do # host 'interstella.com' # end @@ -142,9 +152,11 @@ # config.port 8080 # end # # Client.config.url # returns 'http://interstella.com:8080' def configurable_by(config_class, with: []) + warn CONFIG_CLASS_WARNING if with.present? + @config_factory = ConfigFactory.new( config_class: config_class, config_attributes: with.map(&:to_sym) ) end