Class: Mixlib::Config::Configurable

### Home Classes Methods

### In Files

- lib/mixlib/config/configurable.rb

### Parent

Object

### Methods

- ::new
- #default
- #defaults_to
- #get
- #set
- #writes_value

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Mixlib
- Mixlib::Config
- Mixlib::Config::Configurable
- Mixlib::Config::ReopenedConfigContextWithConfigurableError
- Mixlib::Config::ReopenedConfigurableWithConfigContextError
- Mixlib::Config::UnknownConfigOptionError

No matching classes.

# Mixlib::Config::Configurable

### Attributes

has_default[R]

### Public Class Methods

new(symbol) click to toggle source

    # File lib/mixlib/config/configurable.rb, line 22
    def initialize(symbol)
      @symbol = symbol
      @default_block = nil
      @has_default = false
      @default_value = nil
      @writes_value = nil
    end

### Public Instance Methods

default() click to toggle source

    # File lib/mixlib/config/configurable.rb, line 64
    def default
      if @default_block
        @default_block.call
      else
        @default_value
      end
    end

defaults_to(default_value = nil, &block) click to toggle source

    # File lib/mixlib/config/configurable.rb, line 32
    def defaults_to(default_value = nil, &block)
      @has_default = true
      @default_block = block
      @default_value = default_value
      self
    end

get(config) click to toggle source

    # File lib/mixlib/config/configurable.rb, line 44
    def get(config)
      if config.has_key?(@symbol)
        config[@symbol]
      elsif @default_block
        @default_block.call
      else
        begin
          # Some things cannot be dup'd, and you won't know this till after the fact
          # because all values implement dup
          config[@symbol] = @default_value.dup
        rescue TypeError
          @default_value
        end
      end
    end

set(config, value) click to toggle source

    # File lib/mixlib/config/configurable.rb, line 60
    def set(config, value)
      config[@symbol] = @writes_value ? @writes_value.call(value) : value
    end

writes_value(&block) click to toggle source

    # File lib/mixlib/config/configurable.rb, line 39
    def writes_value(&block)
      @writes_value = block
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.