Sha256: 940c0902f4b23f0260f4ffb420352d7d52ef0051f4d3eac9209b3bf547b38348

Contents?: true

Size: 1.32 KB

Versions: 13

Compression:

Stored size: 1.32 KB

Contents

module Coercible
  class Coercer

    module Configurable

      # Add configuration-specific option keys to the descendant
      #
      # @return [self]
      #
      # @api private
      def self.extended(coercer)
        coercer.accept_options :config_keys
        super
      end

      # Build configuration object for the coercer class
      #
      # @example
      #
      #   coercer_class = Class.new(Coercer::Object) do
      #     extend Configurable
      #
      #     config_keys [ :foo, :bar ]
      #   end
      #
      #   coercer_class.config do |config|
      #     config.foo = '1'
      #     config.bar = '2'
      #   end
      #
      # @yieldparam [Configuration]
      #
      # @return [Configuration]
      #
      # @api public
      def config(&block)
        configuration = configuration_class.build(config_keys)
        yield configuration
        configuration
      end

      # Return configuration name in the global config
      #
      # @return [Symbol]
      #
      # @api private
      def config_name
        name.downcase.split('::').last.to_sym
      end

      # Return configuration class
      #
      # @return [Class:Configuration]
      #
      # @api private
      def configuration_class
        Configuration
      end

    end # module Configurable

  end # class Coercer
end # module Coercible

Version data entries

13 entries across 11 versions & 5 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/coercible-1.0.0/lib/coercible/coercer/configurable.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/coercible-1.0.0/lib/coercible/coercer/configurable.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/coercible-1.0.0/lib/coercible/coercer/configurable.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/coercible-1.0.0/lib/coercible/coercer/configurable.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/coercible-1.0.0/lib/coercible/coercer/configurable.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/configurable.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/configurable.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/configurable.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/coercible-1.0.0/lib/coercible/coercer/configurable.rb
coercible-1.0.0 lib/coercible/coercer/configurable.rb
motion_coercible-0.2.0.2 lib/project/coercer/configurable.rb
motion_coercible-0.2.0.1 lib/project/coercer/configurable.rb
motion_coercible-0.2.0 lib/project/coercer/configurable.rb